Created
January 12, 2018 13:37
-
-
Save alepez/127724e22cbd0afcfd11356c6fe3e627 to your computer and use it in GitHub Desktop.
adblock: Generates dnsmasq rules for NetworkManager
This file contains hidden or 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 | |
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