Skip to content

Instantly share code, notes, and snippets.

@alepez
Created January 12, 2018 13:37
Show Gist options
  • Save alepez/127724e22cbd0afcfd11356c6fe3e627 to your computer and use it in GitHub Desktop.
Save alepez/127724e22cbd0afcfd11356c6fe3e627 to your computer and use it in GitHub Desktop.
adblock: Generates dnsmasq rules for NetworkManager
#!/bin/sh
FAKE_SERVER_ADDRESS='127.8.8.8'
URL='http://pgl.yoyo.org/adservers/serverlist.php?hostformat=dnsmasq&showintro=0&mimetype=plaintext'
FILENAME='/etc/NetworkManager/dnsmasq.d/adblock'
## do not update if fresh (24h)
if test -e "${FILENAME}"; then
echo 'file exists'
if ! test "$( find "${FILENAME}" -mmin +1440 )"; then
echo 'file is fresh';
exit 0
fi
fi
## update
echo 'file is outdated'
curl "${URL}" 2>/dev/null > /tmp/adblock || exit 0
cat /tmp/adblock | sed "s/127\.0\.0\.1/${FAKE_SERVER_ADDRESS}/" > "${FILENAME}"
rm /tmp/adblock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment