-
-
Save LespiletteMaxime/119431344a3bf2a9ab84768a479ae53c to your computer and use it in GitHub Desktop.
Update script for my dnsmasq to remove add
This file contains 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/bash | |
# Address to send ads to (the RPi) | |
piholeIP="127.0.0.1" | |
# Config file to hold URL rules | |
eventHorizion="/etc/dnsmasq.d/adList.conf" | |
echo "Getting yoyo ad list..." | |
curl -s -d mimetype=plaintext -d hostformat=unixhosts http://pgl.yoyo.org/adservers/serverlist.php? | sort > /tmp/matter.txt | |
echo "Getting winhelp2002 ad list..." | |
curl -s http://winhelp2002.mvps.org/hosts.txt | grep -v "#" | grep -v "127.0.0.1" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | sort >> /tmp/matter.txt | |
echo "Getting adaway ad list..." | |
curl -s https://adaway.org/hosts.txt | grep -v "#" | grep -v "::1" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt | |
echo "Getting hosts-file ad list..." | |
curl -s http://hosts-file.net/.%5Cad_servers.txt | grep -v "#" | grep -v "::1" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt | |
echo "Getting malwaredomainlist ad list..." | |
curl -s http://www.malwaredomainlist.com/hostslist/hosts.txt | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $3}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt | |
echo "Getting adblock.gjtech ad list..." | |
curl -s http://adblock.gjtech.net/?format=unix-hosts | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt | |
echo "Getting someone who cares ad list..." | |
curl -s http://someonewhocares.org/hosts/hosts | grep -v "#" | sed '/^$/d' | sed 's/\ /\\ /g' | grep -v '^\\' | grep -v '\\$' | awk '{print $2}' | grep -v '^\\' | grep -v '\\$' | sort >> /tmp/matter.txt | |
echo "Getting Mother of All Ad Blocks list..." | |
curl -A 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' -e http://forum.xda-developers.com/ http://adblock.mahakala.is/ | grep -v "#" | awk '{print $2}' | sort >> /tmp/matter.txt | |
# Sort the aggregated results and remove any duplicates | |
echo "Removing duplicates and formatting to address=/<ad domain>/"$piholeIP | |
cat /tmp/matter.txt | sed $'s/\r$//' | sort | uniq | sed '/^$/d' | awk -v "IP=$piholeIP" '{sub(/\r$/,""); print "address=/"$0"/"IP}' > /tmp/andLight.txt | |
# Count how many domains were added so it can be displayed to the user | |
numberOfAdsBlocked=$(cat /tmp/andLight.txt | wc -l | sed 's/^[ \t]*//') | |
echo "$numberOfAdsBlocked ad domains added to the blacklist" | |
# Remove addresses I want | |
echo "Remove wanted domains name" | |
to_keep=(hosts-file.net ubi.com ubi-security.eu origin.com ea.com teeworlds.com battlefield.com www.piriform.com) | |
search="" | |
for name in ${to_keep[@]}; do | |
search=${search}"address=/"$name"/127.0.0.1\|" | |
done | |
search=$(echo $search | rev | cut -c 3- | rev) | |
grep -v $search /tmp/andLight.txt > /tmp/andLight.txt.tp; mv /tmp/andLight.txt.tp /tmp/andLight.txt | |
# Turn the file into a dnsmasq config file | |
mv /tmp/andLight.txt $eventHorizion | |
# Restart DNS | |
echo "Restart dnsmasq service" | |
service dnsmasq restart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment