From a8874fb60606a47737680b46b8c39f14b9ac8aa4 Mon Sep 17 00:00:00 2001 From: jacobsalmela Date: Tue, 10 Mar 2015 12:27:57 -0500 Subject: [PATCH] Fixes #6 whitelist not found when using sudo This fixes #6 by changing the location of the whitelist.txt file. Instead of storing it in the current users home folder, it should be created in /etc/pihole. The script will also create the directory if it does not exist, but will not add a whitelist.txt by default. You would still need to go back and manually add one. But this directory will be used to store other support files as the script improves. I also added sudo commands to the commands requiring elevation. Finally, changed the comment to reflect a more accurate number of domains getting blocked. --- gravity-adv.sh | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gravity-adv.sh b/gravity-adv.sh index 593d81a..5de6c4d 100755 --- a/gravity-adv.sh +++ b/gravity-adv.sh @@ -1,5 +1,5 @@ #!/bin/bash -# The Pi-hole now blocks over 140,000 ad domains +# The Pi-hole now blocks over 120,000 ad domains # Address to send ads to (the RPi) piholeIP="127.0.0.1" # Optionally, uncomment to automatically detect the address. Thanks Gregg @@ -7,7 +7,15 @@ piholeIP="127.0.0.1" # Config file to hold URL rules eventHorizion="/etc/dnsmasq.d/adList.conf" -whitelist=$HOME/whitelist.txt +whitelist=/etc/pihole/whitelist.txt + +# Create the pihole resource directory if it doesn't exist. Future files will be stored here +if [[ -d /etc/pihole/ ]];then + : +else + echo "Forming pihole directory..." + sudo mkdir /etc/pihole +fi echo "Getting yoyo ad list..." # Approximately 2452 domains at the time of writing curl -s -d mimetype=plaintext -d hostformat=unixhosts http://pgl.yoyo.org/adservers/serverlist.php? | sort > /tmp/matter.txt @@ -43,7 +51,7 @@ numberOfAdsBlocked=$(cat /tmp/andLight.txt | wc -l | sed 's/^[ \t]*//') echo "$numberOfAdsBlocked ad domains blocked." # Turn the file into a dnsmasq config file -mv /tmp/andLight.txt $eventHorizion +sudo mv /tmp/andLight.txt $eventHorizion # Restart DNS -service dnsmasq restart \ No newline at end of file +sudo service dnsmasq restart \ No newline at end of file