Last active
May 12, 2018 00:46
-
-
Save bedge/81e7572a5c3daefd2e9dcaccd34f28c2 to your computer and use it in GitHub Desktop.
Scripted update from someonewhocares.org preserving local changes.
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/bash -ex | |
# Keep /etc/hosts up to date with ad blocker site: | |
# http://someonewhocares.org/hosts/hosts | |
# Depends on my endecode.py gist or equiv for cleaning up html text. | |
# Excluding personal allow list | |
# eg: googleadservices, so google image searches are clickable. | |
allow=${hosts}.allow | |
# Optional files | |
# /etc/hosts.local for local additions | |
# /etc/hosts.allow for ones to prune from source | |
hosts="/etc/hosts" | |
backup="/tmp/$(basename ${hosts}).$(date +%x | tr '/' '_')" | |
allow=${hosts}.allow | |
local=${hosts}.local | |
tmp=$(mktemp) | |
sudo cp $hosts $backup | |
if [ -e ${local} ] ; then | |
cp $local $tmp | |
fi | |
curl -s http://someonewhocares.org/hosts/hosts | endecode.py -a html_decode >> $tmp | |
if [ -e ${allow} ] ; then | |
mv $tmp $tmp.1 | |
grep -v -f $allow $tmp.1 > $tmp | |
rm -rf $tmp.1 | |
fi | |
sudo mv $tmp /etc/hosts | |
[ "$DEBUG" ] && diff $backup /etc/hosts | |
rm -f $tmp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment