Skip to content

Instantly share code, notes, and snippets.

@goofball222
Created November 29, 2018 23:23
Show Gist options
  • Save goofball222/8365e4ed127d0aaffc532789ba101ece to your computer and use it in GitHub Desktop.
Save goofball222/8365e4ed127d0aaffc532789ba101ece to your computer and use it in GitHub Desktop.
Script to download and format the Pi-Hole default adblock list for Unbound
#!/bin/bash
/usr/bin/curl -sSL https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -o hosts1
/usr/bin/curl -sSL https://mirror1.malwaredomains.com/files/justdomains -o domains1
/usr/bin/curl -sSL http://sysctl.org/cameleon/hosts -o hosts2
/usr/bin/curl -sSL https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist -o domains2
/usr/bin/curl -sSL https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt -o domains3
/usr/bin/curl -sSL https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt -o domains4
/usr/bin/curl -sSL https://hosts-file.net/ad_servers.txt -o hosts3
cat hosts1 | awk '{ sub("\r$", ""); print }' | grep '^0\.0\.0\.0' | awk '{print $2}' | grep -v '^0\.0\.0\.0' > hosts1.clean
cat hosts2 | awk '{ sub("\r$", ""); print }' | grep '^127\.0\.0\.1' | awk '{print $2}' | grep -v 'localhost' > hosts2.clean
cat hosts3 | awk '{ sub("\r$", ""); print }' | grep '^127\.0\.0\.1' | awk '{print $2}' | grep -v 'localhost' > hosts3.clean
sed '/#/d; /*/d; /^$/d; /^\./d' domains1 > domains1.clean
sed '/#/d; /*/d; /^$/d; /^\./d' domains2 > domains2.clean
sed '/#/d; /*/d; /^$/d; /^\./d' domains3 > domains3.clean
sed '/#/d; /*/d; /^$/d; /^\./d' domains4 > domains4.clean
cat hosts1.clean hosts2.clean hosts3.clean domains1.clean domains2.clean domains3.clean domains4.clean \
| tr A-Z a-z \
| sort -u > merged
comm -23 merged ../unbound/whitelist.conf > clean
awk '{print "local-zone: \""$1"\" redirect\nlocal-data: \""$1" A 0.0.0.0\""}' clean > ../unbound/blocklist.conf
rm clean hosts* domains* merged
docker restart unbound
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment