Instantly share code, notes, and snippets.

Embed
What would you like to do?
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