Skip to content

Instantly share code, notes, and snippets.

@bedge
Last active May 12, 2018 00:46
Show Gist options
  • Save bedge/81e7572a5c3daefd2e9dcaccd34f28c2 to your computer and use it in GitHub Desktop.
Save bedge/81e7572a5c3daefd2e9dcaccd34f28c2 to your computer and use it in GitHub Desktop.
Scripted update from someonewhocares.org preserving local changes.
#!/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