Last active
July 3, 2024 14:57
-
-
Save BlakeRain/75bc52434528dcabb6ca87908d70468e to your computer and use it in GitHub Desktop.
Script to generate adblocking configuration for Unbound
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 | |
# See https://blakerain.com/blog/adding-dns-adblock-to-unbound/ | |
UNBOUND="/var/unbound/etc" | |
VARIANT=${VARIANT:-fakenews-gambling-social} | |
URL="https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/$VARIANT/hosts" | |
wget -qO- "$URL" | grep '^0\.0\.0\.0' | sort | \ | |
awk '{print "local-zone: \""$2"\" refuse"}' > "$UNBOUND/adblock.conf" | |
if [ -f "$HOME/adblock.exceptions" ]; then | |
(cat "$HOME/adblock.exceptions" | \ | |
awk '{gsub(/\./,"\\."); print "g/\"" $0 "\"/d"}'; echo w) | ed - "$UNBOUND/adblock.conf" | |
cat "$HOME/adblock.exceptions" | \ | |
awk '{print "local-zone: \""$0".\" transparent"}' > "$UNBOUND/adblock.exceptions.conf" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment