Last active
December 29, 2016 08:22
-
-
Save glabra/cea0b8129751b132b941df5507ff961d to your computer and use it in GitHub Desktop.
adaway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -ue | |
umask 0027 | |
#export PATH='/bin:/usr/bin' | |
export LANG='C' | |
IFS=' | |
' | |
SOURCES='https://adaway.org/hosts.txt | |
https://hosts-file.net/ad_servers.txt | |
https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext | |
https://sites.google.com/site/logroid/files/hosts.txt?attredirects=0 | |
https://sites.google.com/site/cosmonoteshosts/hosts_for_Adaway.txt' | |
tmp_f1=$(mktemp) | |
tmp_f2=$(mktemp) | |
tmp_f3=$(mktemp) | |
cleanup () { | |
rm -f "${tmp_f1}" "${tmp_f2}" "${tmp_f3}" | |
exit | |
} | |
trap "cleanup" EXIT INT TERM | |
# my filter | |
cat <<- _EOF_ > "${tmp_f1}" | |
127.0.0.1 localhost | |
::1 localhost | |
fe80::1 localhost | |
white rss.rssad.jp | |
_EOF_ | |
curl -Lo - -- $(printf "${SOURCES}" | tr '\n' ' ') | cat - "${tmp_f1}" | \ | |
sed '/^#/d' | sed 's/ *#.*$//' | tr '\t' ' ' | tr -s ' ' | \ | |
tr -d '\r' | sed '/^\s*$/d' | sort -k 2b,2 | uniq > "${tmp_f2}" | |
egrep -v '^white ' "${tmp_f2}" > "${tmp_f1}" | |
egrep '^white ' "${tmp_f2}" > "${tmp_f3}" | |
join -j2 -v1 -o'1.1 1.2' "${tmp_f1}" "${tmp_f3}" > "${tmp_f2}" | |
if [ "${1:-}" = 'deploy' ]; then | |
adb root | |
adb remount | |
adb push "${tmp_f2}" /etc/hosts | |
adb reboot | |
else | |
cat "${tmp_f2}" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment