From 0b5f005a5d799d0a0a1200061ea668434fa77eaf Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 19 Mar 2016 20:32:11 -0500 Subject: [PATCH 01/38] Added piholeDebug.sh script for advanced debugging Script piholeDebug.sh added to /usr/local/bin to generate a detailed log file for debugging/troubleshooting. --- advanced/Scripts/piholeDebug.sh | 157 +++++++++++++++++++++++++++++ automated install/basic-install.sh | 3 +- 2 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 advanced/Scripts/piholeDebug.sh diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh new file mode 100644 index 00000000..ead75cd9 --- /dev/null +++ b/advanced/Scripts/piholeDebug.sh @@ -0,0 +1,157 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2015, 2016 by Jacob Salmela +# Network-wide ad blocking via your Raspberry Pi +# http://pi-hole.net +# Flushes /var/log/pihole.log +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +# Nate Brandeburg +# nate@ubiquisoft.com +# 3/19/2016 + +######## GLOBAL VARS ######## +DEBUG_LOG="/var/log/pihole_debug.log" + +######## FIRST CHECK ######## +# Must be root to debug +if [[ $EUID -eq 0 ]];then + echo "::: You are root... Beginning debug!" +else + echo "::: sudo will be used for debugging." + # Check if sudo is actually installed + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi +fi + +# Ensure the file exists, create if not, clear if exists. +if [ ! -f "$DEBUG_LOG" ] +then + $SUDO touch $DEBUG_LOG + $SUDO chmod 644 $DEBUG_LOG + $SUDO chown "$USER":root $DEBUG_LOG +else + truncate -s 0 $DEBUG_LOG +fi + +### Check Pi internet connections ### +# Log the IP addresses of this Pi +IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e') +echo "Writing local IPs to debug log" +echo "IP Addresses of this Pi:" >> $DEBUG_LOG +echo "$IPADDR" >> $DEBUG_LOG +echo >> $DEBUG_LOG + +# Check if we can connect to the local gateway +GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error) +echo "Gateway check:" >> $DEBUG_LOG +echo "$GATEWAY_CHECK" >> $DEBUG_LOG +echo >> $DEBUG_LOG + +echo "Writing dnsmasq.conf to debug log..." +echo "############### Dnsmasq ###############" >> $DEBUG_LOG +DNSMASQFILE="/etc/dnsmasq.conf" +if [ -e "$DNSMASQFILE" ] +then + cat $DNSMASQFILE >> $DEBUG_LOG + echo >> $DEBUG_LOG +else + echo "No dnsmasq.conf file found!" >> $DEBUG_LOG + echo "No dnsmasq.conf file found!" +fi + +echo "Writing hosts file to debug log..." +echo "############### Hosts ###############" >> $DEBUG_LOG +HOSTSFILE="/etc/hosts" +if [ -e "$HOSTSFILE" ] +then + cat "$HOSTSFILE" >> $DEBUG_LOG + echo >> $DEBUG_LOG +else + echo "No hosts file found!" >> $DEBUG_LOG + echo "No hosts file found!" +fi + +### PiHole application specific logging ### +# Write Pi-Hole logs to debug log +echo "Writing whitelist to debug log..." +echo "############### Whitelist ###############" >> $DEBUG_LOG +WHITELISTFILE="/etc/pihole/whitelist.txt" +if [ -e "$WHITELISTFILE" ] +then + cat "$WHITELISTFILE" >> $DEBUG_LOG + echo >> $DEBUG_LOG +else + echo "No whitelist.txt file found!" >> $DEBUG_LOG + echo "No whitelist.txt file found!" +fi + +echo "Writing blacklist to debug log..." +echo "############### Blacklist ###############" >> $DEBUG_LOG +BLACKLISTFILE="/etc/pihole/blacklist.txt" +if [ -e "$BLACKLISTFILE" ] +then + cat "$BLACKLISTFILE" >> $DEBUG_LOG + echo >> $DEBUG_LOG +else + echo "No blacklist.txt file found!" >> $DEBUG_LOG + echo "No blacklist.txt file found!" +fi + +echo "Writing adlists.list to debug log..." +echo "############### adlists.list ###############" >> $DEBUG_LOG +ADLISTSFILE="/etc/pihole/adlists.list" +if [ -e "$ADLISTSFILE" ] +then + cat "$ADLISTSFILE" >> $DEBUG_LOG + echo >> $DEBUG_LOG +else + echo "No adlists.list file found!" >> $DEBUG_LOG + echo "No adlists.list file found!" +fi + + +# Continuously append the pihole.log file to the pihole_debug.log file +function dumpPiHoleLog { + trap '{ echo -e "\nFinishing debug write from interrupt... Quitting!" ; exit 1; }' INT + echo -e "Writing current pihole traffic to debug log...\nTry loading any/all sites that you are having trouble with now... (Press ctrl+C to finish)" + echo "############### pihole.log ###############" >> $DEBUG_LOG + PIHOLELOG="/var/log/pihole.log" + if [ -e "$PIHOLELOG" ] + then + while true; do + tail -f "$PIHOLELOG" >> $DEBUG_LOG + echo >> $DEBUG_LOG + done + else + echo "No pihole.log file found!" >> $DEBUG_LOG + echo "No pihole.log file found!" + fi +} + +function finalWrites { + # Write the gravity.list after the user is finished capturing the pihole.log output + echo "Writing gravity.list to debug log..." + echo "############### gravity.list ###############" >> $DEBUG_LOG + GRAVITYFILE="/etc/pihole/gravity.list" + if [ -e "$GRAVITYFILE" ] + then + cat /etc/pihole/gravity.list >> $DEBUG_LOG + echo >> $DEBUG_LOG + else + echo "No gravity.list file found!" >> $DEBUG_LOG + echo "No gravity.list file found" + fi +} +trap finalWrites EXIT + +### Method calls for additinal logging ### +dumpPiHoleLog diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b3e6202f..8068a485 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -477,7 +477,8 @@ installScripts() { $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /usr/local/bin/blacklist.sh $SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /usr/local/bin/piholeLogFlush.sh $SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /usr/local/bin/updateDashboard.sh - $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh + $SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /usr/local/bin/piholeDebug.sh + $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,piholeDebug}.sh $SUDO echo " done." } From b0dd2310186647afa7e27c0f91aceea49c187b27 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 19 Mar 2016 21:34:02 -0500 Subject: [PATCH 02/38] Modified description in header Removed copied header description from piholeLogFlush.sh and replaced with relevant description. --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ead75cd9..59ad130e 100644 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -3,7 +3,7 @@ # (c) 2015, 2016 by Jacob Salmela # Network-wide ad blocking via your Raspberry Pi # http://pi-hole.net -# Flushes /var/log/pihole.log +# Generates pihole_debug.log in /var/log/ to be used for troubleshooting. # # Pi-hole is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by From 04638c90652d56240ab3ac378b5e43b152451417 Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 20 Mar 2016 18:21:35 -0500 Subject: [PATCH 03/38] Added 01-pihole.conf from /etc/dnsmasq.d/ to log Write 01-pihole.conf to debug log --- advanced/Scripts/piholeDebug.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 59ad130e..b47d9755 100644 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -138,13 +138,25 @@ function dumpPiHoleLog { } function finalWrites { + # Write the 01-pihole.conf from /etc/dnsmasq.d/ to the debug log + echo "Writing 01-pihole.conf to debug log..." + echo "############### 01-pihole.conf ###############" >> $DEBUG_LOG + PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf" + if [ -e "$PIHOLECONFFILE" ] + then + cat "$PIHOLECONFFILE" >> $DEBUG_LOG + echo >> $DEBUG_LOG + else + echo "No 01-pihole.conf file found!" >> $DEBUG_LOG + echo "No 01-pihole.conf file found" + fi # Write the gravity.list after the user is finished capturing the pihole.log output echo "Writing gravity.list to debug log..." echo "############### gravity.list ###############" >> $DEBUG_LOG GRAVITYFILE="/etc/pihole/gravity.list" if [ -e "$GRAVITYFILE" ] then - cat /etc/pihole/gravity.list >> $DEBUG_LOG + cat "$GRAVITYFILE" >> $DEBUG_LOG echo >> $DEBUG_LOG else echo "No gravity.list file found!" >> $DEBUG_LOG From 00f46dc149ccbec41b690c3af7e59a40a9d6b290 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 23 Mar 2016 14:56:27 -0500 Subject: [PATCH 04/38] Added Pi 3B to README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a181d6f..01928cdd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Automated Install -##### Designed For Raspberry Pi A+, B, B+, 2, and Zero (with an Ethernet/Wi-Fi adapter) +##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) 1. Install Raspbian 2. Run the command below From 86eafe7a332f8af6ca6ce5fb4ff32318063715e0 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 24 Mar 2016 16:21:29 -0500 Subject: [PATCH 05/38] Added comparison of gravity.list with Whitelist.txt and Blacklist.txt. Added additional echos to help read the debug file. TODO: testNslookup function --- advanced/Scripts/piholeDebug.sh | 162 +++++++++++++++++++++++--------- 1 file changed, 119 insertions(+), 43 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index b47d9755..8bb741ea 100644 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -12,22 +12,32 @@ # Nate Brandeburg # nate@ubiquisoft.com -# 3/19/2016 +# 3/24/2016 ######## GLOBAL VARS ######## DEBUG_LOG="/var/log/pihole_debug.log" +DNSMASQFILE="/etc/dnsmasq.conf" +PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf" +LIGHTTPDFILE="/etc/lighttpd/lighttpd.conf" +GRAVITYFILE="/etc/pihole/gravity.list" +HOSTSFILE="/etc/hosts" +WHITELISTFILE="/etc/pihole/whitelist.txt" +BLACKLISTFILE="/etc/pihole/blacklist.txt" +ADLISTSFILE="/etc/pihole/adlists.list" +PIHOLELOG="/var/log/pihole.log" + ######## FIRST CHECK ######## # Must be root to debug if [[ $EUID -eq 0 ]];then - echo "::: You are root... Beginning debug!" + echo "You are root... Beginning debug!" else - echo "::: sudo will be used for debugging." + echo "sudo will be used for debugging." # Check if sudo is actually installed if [[ $(dpkg-query -s sudo) ]];then export SUDO="sudo" else - echo "::: Please install sudo or run this as root." + echo "Please install sudo or run this as root." exit 1 fi fi @@ -42,6 +52,32 @@ else truncate -s 0 $DEBUG_LOG fi +### Private functions exist here ### +function compareWhitelist { + echo "#######################################" >> $DEBUG_LOG + echo "######## Whitelist Comparison #########" >> $DEBUG_LOG + echo "#######################################" >> $DEBUG_LOG + while read -r line; do + grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + done < "$WHITELISTFILE" + echo >> $DEBUG_LOG +} + +function compareBlacklist { + echo "#######################################" >> $DEBUG_LOG + echo "######## Blacklist Comparison #########" >> $DEBUG_LOG + echo "#######################################" >> $DEBUG_LOG + while read -r line; do + grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + done < "$BLACKLISTFILE" + echo >> $DEBUG_LOG +} + +function testNslookup { + # TODO: This will pull a non-matched entry from gravity.list to compare with the nslookup against Google's NS. + echo >> $DEBUG_LOG +} + ### Check Pi internet connections ### # Log the IP addresses of this Pi IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e') @@ -57,20 +93,78 @@ echo "$GATEWAY_CHECK" >> $DEBUG_LOG echo >> $DEBUG_LOG echo "Writing dnsmasq.conf to debug log..." +echo "#######################################" >> $DEBUG_LOG echo "############### Dnsmasq ###############" >> $DEBUG_LOG -DNSMASQFILE="/etc/dnsmasq.conf" +echo "#######################################" >> $DEBUG_LOG if [ -e "$DNSMASQFILE" ] then - cat $DNSMASQFILE >> $DEBUG_LOG + #cat $DNSMASQFILE >> $DEBUG_LOG + while read -r line; do + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> $DEBUG_LOG + done < "$DNSMASQFILE" echo >> $DEBUG_LOG else echo "No dnsmasq.conf file found!" >> $DEBUG_LOG echo "No dnsmasq.conf file found!" fi +echo "Writing 01-pihole.conf to debug log..." +echo "#######################################" >> $DEBUG_LOG +echo "########### 01-pihole.conf ############" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG +if [ -e "$PIHOLECONFFILE" ] +then + #cat "$PIHOLECONFFILE" >> $DEBUG_LOG + while read -r line; do + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> $DEBUG_LOG + done < "$PIHOLECONFFILE" + echo >> $DEBUG_LOG +else + echo "No 01-pihole.conf file found!" >> $DEBUG_LOG + echo "No 01-pihole.conf file found" +fi + +echo "Writing lighttpd.conf to debug log..." +echo "#######################################" >> $DEBUG_LOG +echo "############ lighttpd.conf ############" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG +if [ -e "$LIGHTTPDFILE" ] +then + #cat "$PIHOLECONFFILE" >> $DEBUG_LOG + while read -r line; do + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> $DEBUG_LOG + done < "$LIGHTTPDFILE" + echo >> $DEBUG_LOG +else + echo "No lighttpd.conf file found!" >> $DEBUG_LOG + echo "No lighttpd.conf file found" +fi + +echo "Writing size of gravity.list to debug log..." +echo "#######################################" >> $DEBUG_LOG +echo "############ gravity.list #############" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG +if [ -e "$GRAVITYFILE" ] +then + wc -l "$GRAVITYFILE" >> $DEBUG_LOG + echo >> $DEBUG_LOG +else + echo "No gravity.list file found!" >> $DEBUG_LOG + echo "No gravity.list file found" +fi + +# Write the hostname output to compare against entries in /etc/hosts, which is logged next +echo "Hostname of this pihole is: " >> $DEBUG_LOG +hostname >> $DEBUG_LOG +echo >> $DEBUG_LOG + echo "Writing hosts file to debug log..." -echo "############### Hosts ###############" >> $DEBUG_LOG -HOSTSFILE="/etc/hosts" +echo "#######################################" >> $DEBUG_LOG +echo "################ Hosts ################" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG if [ -e "$HOSTSFILE" ] then cat "$HOSTSFILE" >> $DEBUG_LOG @@ -83,8 +177,9 @@ fi ### PiHole application specific logging ### # Write Pi-Hole logs to debug log echo "Writing whitelist to debug log..." -echo "############### Whitelist ###############" >> $DEBUG_LOG -WHITELISTFILE="/etc/pihole/whitelist.txt" +echo "#######################################" >> $DEBUG_LOG +echo "############## Whitelist ##############" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG if [ -e "$WHITELISTFILE" ] then cat "$WHITELISTFILE" >> $DEBUG_LOG @@ -95,8 +190,9 @@ else fi echo "Writing blacklist to debug log..." -echo "############### Blacklist ###############" >> $DEBUG_LOG -BLACKLISTFILE="/etc/pihole/blacklist.txt" +echo "#######################################" >> $DEBUG_LOG +echo "############## Blacklist ##############" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG if [ -e "$BLACKLISTFILE" ] then cat "$BLACKLISTFILE" >> $DEBUG_LOG @@ -107,8 +203,9 @@ else fi echo "Writing adlists.list to debug log..." -echo "############### adlists.list ###############" >> $DEBUG_LOG -ADLISTSFILE="/etc/pihole/adlists.list" +echo "#######################################" >> $DEBUG_LOG +echo "############ adlists.list #############" >> $DEBUG_LOG +echo "#######################################" >> $DEBUG_LOG if [ -e "$ADLISTSFILE" ] then cat "$ADLISTSFILE" >> $DEBUG_LOG @@ -123,8 +220,9 @@ fi function dumpPiHoleLog { trap '{ echo -e "\nFinishing debug write from interrupt... Quitting!" ; exit 1; }' INT echo -e "Writing current pihole traffic to debug log...\nTry loading any/all sites that you are having trouble with now... (Press ctrl+C to finish)" - echo "############### pihole.log ###############" >> $DEBUG_LOG - PIHOLELOG="/var/log/pihole.log" + echo "#######################################" >> $DEBUG_LOG + echo "############# pihole.log ##############" >> $DEBUG_LOG + echo "#######################################" >> $DEBUG_LOG if [ -e "$PIHOLELOG" ] then while true; do @@ -137,33 +235,11 @@ function dumpPiHoleLog { fi } -function finalWrites { - # Write the 01-pihole.conf from /etc/dnsmasq.d/ to the debug log - echo "Writing 01-pihole.conf to debug log..." - echo "############### 01-pihole.conf ###############" >> $DEBUG_LOG - PIHOLECONFFILE="/etc/dnsmasq.d/01-pihole.conf" - if [ -e "$PIHOLECONFFILE" ] - then - cat "$PIHOLECONFFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG - else - echo "No 01-pihole.conf file found!" >> $DEBUG_LOG - echo "No 01-pihole.conf file found" - fi - # Write the gravity.list after the user is finished capturing the pihole.log output - echo "Writing gravity.list to debug log..." - echo "############### gravity.list ###############" >> $DEBUG_LOG - GRAVITYFILE="/etc/pihole/gravity.list" - if [ -e "$GRAVITYFILE" ] - then - cat "$GRAVITYFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG - else - echo "No gravity.list file found!" >> $DEBUG_LOG - echo "No gravity.list file found" - fi +# Anything to be done after capturing of pihole.log terminates +function finalWork { + echo "Finshed debugging!" } -trap finalWrites EXIT +trap finalWork EXIT -### Method calls for additinal logging ### +### Method calls for additional logging ### dumpPiHoleLog From b746250e71e247fc371b9c244d092dd54d28291a Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 24 Mar 2016 18:29:13 -0500 Subject: [PATCH 06/38] Made all advanced/Scripts/ executable for consistency. --- advanced/Scripts/blacklist.sh | 0 advanced/Scripts/piholeDebug.sh | 0 advanced/Scripts/setupLCD.sh | 0 advanced/Scripts/updateDashboard.sh | 0 4 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 advanced/Scripts/blacklist.sh mode change 100644 => 100755 advanced/Scripts/piholeDebug.sh mode change 100644 => 100755 advanced/Scripts/setupLCD.sh mode change 100644 => 100755 advanced/Scripts/updateDashboard.sh diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh old mode 100644 new mode 100755 diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh old mode 100644 new mode 100755 diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh old mode 100644 new mode 100755 diff --git a/advanced/Scripts/updateDashboard.sh b/advanced/Scripts/updateDashboard.sh old mode 100644 new mode 100755 From 8f8dc66c7052999920d2f83c4f5f1df6d1622646 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 24 Mar 2016 18:50:53 -0500 Subject: [PATCH 07/38] Ignore whitespace when writing config files --- advanced/Scripts/piholeDebug.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8bb741ea..e84e9319 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -100,8 +100,10 @@ if [ -e "$DNSMASQFILE" ] then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + if [ ! -z "$line" ]; then + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> $DEBUG_LOG + fi done < "$DNSMASQFILE" echo >> $DEBUG_LOG else @@ -117,8 +119,10 @@ if [ -e "$PIHOLECONFFILE" ] then #cat "$PIHOLECONFFILE" >> $DEBUG_LOG while read -r line; do - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + if [ ! -z "$line" ]; then + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> $DEBUG_LOG + fi done < "$PIHOLECONFFILE" echo >> $DEBUG_LOG else @@ -134,8 +138,10 @@ if [ -e "$LIGHTTPDFILE" ] then #cat "$PIHOLECONFFILE" >> $DEBUG_LOG while read -r line; do - [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + if [ ! -z "$line" ]; then + [[ "$line" =~ ^#.*$ ]] && continue + echo "$line" >> $DEBUG_LOG + fi done < "$LIGHTTPDFILE" echo >> $DEBUG_LOG else From b4463bf42c2bf10f8d9a885f7f178509784015b1 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 25 Mar 2016 16:42:17 -0500 Subject: [PATCH 08/38] Added test for nslookup Checks the TESTURL for nslookup is not whitelisted --- advanced/Scripts/piholeDebug.sh | 46 ++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e84e9319..ac7a4262 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -25,16 +25,17 @@ WHITELISTFILE="/etc/pihole/whitelist.txt" BLACKLISTFILE="/etc/pihole/blacklist.txt" ADLISTSFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" +WHITELISTMATCHES="/tmp/whitelistmatches.list" ######## FIRST CHECK ######## # Must be root to debug -if [[ $EUID -eq 0 ]];then +if [[ $EUID -eq 0 ]]; then echo "You are root... Beginning debug!" else echo "sudo will be used for debugging." # Check if sudo is actually installed - if [[ $(dpkg-query -s sudo) ]];then + if [[ $(dpkg-query -s sudo) ]]; then export SUDO="sudo" else echo "Please install sudo or run this as root." @@ -43,8 +44,7 @@ else fi # Ensure the file exists, create if not, clear if exists. -if [ ! -f "$DEBUG_LOG" ] -then +if [ ! -f "$DEBUG_LOG" ]; then $SUDO touch $DEBUG_LOG $SUDO chmod 644 $DEBUG_LOG $SUDO chown "$USER":root $DEBUG_LOG @@ -54,11 +54,21 @@ fi ### Private functions exist here ### function compareWhitelist { + if [ ! -f "$WHITELISTMATCHES" ]; then + $SUDO touch $WHITELISTMATCHES + $SUDO chmod 644 $WHITELISTMATCHES + $SUDO chown "$USER":root $WHITELISTMATCHES + else + truncate -s 0 $WHITELISTMATCHES + fi + echo "#######################################" >> $DEBUG_LOG echo "######## Whitelist Comparison #########" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG while read -r line; do - grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + TMP=$(grep -w ".* $line$" "$GRAVITYFILE") + echo "$TMP" >> $DEBUG_LOG + echo "$TMP" >> $WHITELISTMATCHES done < "$WHITELISTFILE" echo >> $DEBUG_LOG } @@ -74,7 +84,28 @@ function compareBlacklist { } function testNslookup { - # TODO: This will pull a non-matched entry from gravity.list to compare with the nslookup against Google's NS. + TESTURL="" + echo "#######################################" >> $DEBUG_LOG + echo "############ NSLookup Test ############" >> $DEBUG_LOG + echo "#######################################" >> $DEBUG_LOG + # Find a blocked url that has not been whitelisted. + while read -r line; do + CUTURL=$("$line" | cut -d " " -f2-) + if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then + while read -r line2; do + CUTURL2=$("$line2" | cut -d " " -f2-) + if [ "$CUTURL" != "$CUTURL2" ]; then + TESTURL="$CUTURL" + fi + done < "WHITELISTMATCHES" + fi + done < "GRAVITYFILE" + + echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG + echo nslookup "$TESTURL" >> $DEBUG_LOG + echo >> $DEBUG_LOG + echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG + echo nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG echo >> $DEBUG_LOG } @@ -92,6 +123,9 @@ echo "Gateway check:" >> $DEBUG_LOG echo "$GATEWAY_CHECK" >> $DEBUG_LOG echo >> $DEBUG_LOG +# Test the nslookup here +testNslookup + echo "Writing dnsmasq.conf to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############### Dnsmasq ###############" >> $DEBUG_LOG From a9c24b456d34bf83c1a85287a221be70120b79c8 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 25 Mar 2016 19:04:03 -0500 Subject: [PATCH 09/38] Bug fixes and logging improvements Finalized for production deployment. Next release targeting a tarball of config files plus additional logging. --- advanced/Scripts/piholeDebug.sh | 45 +++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ac7a4262..ab417aa6 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -67,8 +67,10 @@ function compareWhitelist { echo "#######################################" >> $DEBUG_LOG while read -r line; do TMP=$(grep -w ".* $line$" "$GRAVITYFILE") - echo "$TMP" >> $DEBUG_LOG - echo "$TMP" >> $WHITELISTMATCHES + if [ ! -z "$TMP" ]; then + echo "$TMP" >> $DEBUG_LOG + echo "$TMP" >> $WHITELISTMATCHES + fi done < "$WHITELISTFILE" echo >> $DEBUG_LOG } @@ -78,34 +80,39 @@ function compareBlacklist { echo "######## Blacklist Comparison #########" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG while read -r line; do - grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + if [ ! -z "$line" ]; then + grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + fi done < "$BLACKLISTFILE" echo >> $DEBUG_LOG } function testNslookup { - TESTURL="" + TESTURL="doubleclick.com" echo "#######################################" >> $DEBUG_LOG echo "############ NSLookup Test ############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG # Find a blocked url that has not been whitelisted. - while read -r line; do - CUTURL=$("$line" | cut -d " " -f2-) - if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then - while read -r line2; do - CUTURL2=$("$line2" | cut -d " " -f2-) - if [ "$CUTURL" != "$CUTURL2" ]; then - TESTURL="$CUTURL" - fi - done < "WHITELISTMATCHES" - fi - done < "GRAVITYFILE" + if [ -s "$WHITELISTMATCHES" ]; then + while read -r line; do + CUTURL=${line#*" "} + if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then + while read -r line2; do + CUTURL2=${line2#*" "} + if [ "$CUTURL" != "$CUTURL2" ]; then + TESTURL="$CUTURL" + break 2 + fi + done < "$WHITELISTMATCHES" + fi + done < "$GRAVITYFILE" + fi echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG - echo nslookup "$TESTURL" >> $DEBUG_LOG + nslookup "$TESTURL" >> $DEBUG_LOG echo >> $DEBUG_LOG echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG - echo nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG + nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG echo >> $DEBUG_LOG } @@ -124,6 +131,8 @@ echo "$GATEWAY_CHECK" >> $DEBUG_LOG echo >> $DEBUG_LOG # Test the nslookup here +compareWhitelist +compareBlacklist testNslookup echo "Writing dnsmasq.conf to debug log..." @@ -199,7 +208,6 @@ fi # Write the hostname output to compare against entries in /etc/hosts, which is logged next echo "Hostname of this pihole is: " >> $DEBUG_LOG hostname >> $DEBUG_LOG -echo >> $DEBUG_LOG echo "Writing hosts file to debug log..." echo "#######################################" >> $DEBUG_LOG @@ -215,7 +223,6 @@ else fi ### PiHole application specific logging ### -# Write Pi-Hole logs to debug log echo "Writing whitelist to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############## Whitelist ##############" >> $DEBUG_LOG From 0b9e78df2cf646b372be57d7c8436f42dcc6f4fb Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 26 Mar 2016 14:16:22 -0500 Subject: [PATCH 10/38] Cleaned code and added prompt for purge on uninstall --- advanced/Scripts/blacklist.sh | 30 ++++++------ advanced/Scripts/chronometer.sh | 4 +- advanced/Scripts/whitelist.sh | 27 +++++------ automated install/basic-install.sh | 76 +++++++++++++++--------------- automated install/uninstall.sh | 17 ++++--- gravity.sh | 46 +++++++++--------- 6 files changed, 100 insertions(+), 100 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 70b8131a..cf5e09a7 100644 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -33,13 +33,11 @@ versbose=true domList=() domToRemoveList=() - -piholeIPfile=/tmp/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') -piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') +piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') piholeIP=${piholeIPCIDR%/*} modifyHost=false @@ -53,10 +51,10 @@ fi function HandleOther(){ #check validity of domain - validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then - echo $1 is not a valid argument or domain name + echo "$1" is not a valid argument or domain name else domList=("${domList[@]}" $validDomain) fi @@ -69,10 +67,10 @@ function PopBlacklistFile(){ fi for dom in "${domList[@]}" do - if $addmode; then - AddDomain $dom + if "$addmode"; then + AddDomain "$dom" else - RemoveDomain $dom + RemoveDomain "$dom" fi done } @@ -86,7 +84,7 @@ function AddDomain(){ if $versbose; then echo -n "::: Adding $1 to blacklist file..." fi - echo $1 >> $blacklist + echo "$1" >> $blacklist modifyHost=true echo " done!" else @@ -119,14 +117,14 @@ function ModifyHostFile(){ if $addmode; then #add domains to the hosts file if [[ -r $blacklist ]];then - numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) + numberOf=$($blacklist | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." if [[ -n $piholeIPv6 ]];then - cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList + $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList else - cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList + $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList fi fi @@ -138,10 +136,10 @@ function ModifyHostFile(){ #we need to remove the domains from the blacklist file and the host file echo "::: $dom" echo -n "::: removing from HOSTS file..." - echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList + echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList echo " done!" echo -n "::: removing from blackist.txt..." - echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist + echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist echo " done!" done fi @@ -157,7 +155,7 @@ function Reload() { if [[ $dnsmasqPid ]]; then # service already running - reload config - sudo kill -HUP $dnsmasqPid + sudo kill -HUP "$dnsmasqPid" else # service not running, start it up sudo service dnsmasq start @@ -174,7 +172,7 @@ do "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; "-q" | "--quiet" ) versbose=false;; - * ) HandleOther $var;; + * ) HandleOther "$var";; esac done diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index ebed8684..3e5559e0 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -35,7 +35,7 @@ function CalcBlockedDomains(){ function CalcQueriesToday(){ if [ -e "$piLog" ];then - queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l) + queriesToday=$("$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l) else queriesToday="Err." fi @@ -43,7 +43,7 @@ function CalcQueriesToday(){ function CalcblockedToday(){ if [ -e "$piLog" ] && [ -e "$gravity" ];then - blockedToday=$(cat $piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) + blockedToday=$($piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) else blockedToday="Err." fi diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 853c3b79..0bea10aa 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -33,12 +33,11 @@ versbose=true domList=() domToRemoveList=() -piholeIPfile=/tmp/piholeIP piholeIPv6file=/etc/pihole/.useIPv6 # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') -piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') +piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') piholeIP=${piholeIPCIDR%/*} modifyHost=false @@ -52,7 +51,7 @@ fi function HandleOther(){ #check validity of domain - validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" @@ -69,9 +68,9 @@ function PopWhitelistFile(){ for dom in "${domList[@]}" do if $addmode; then - AddDomain $dom + AddDomain "$dom" else - RemoveDomain $dom + RemoveDomain "$dom" fi done } @@ -86,7 +85,7 @@ function AddDomain(){ if $versbose; then echo -n "::: Adding $1 to whitelist.txt..." fi - echo $1 >> $whitelist + echo "$1" >> $whitelist modifyHost=true if $versbose; then echo " done!" @@ -122,12 +121,12 @@ function ModifyHostFile(){ #remove domains in from hosts file if [[ -r $whitelist ]];then # Remove whitelist entries - numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) + numberOf=$($whitelist | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." - awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp - awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp + awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp + awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp echo "l" >> /etc/pihole/whitelist.tmp grep -F -x -v -f /etc/pihole/whitelist.tmp /etc/pihole/gravity.list > /etc/pihole/gravity.tmp rm /etc/pihole/gravity.list @@ -144,15 +143,15 @@ function ModifyHostFile(){ do if [[ -n $piholeIPv6 ]];then echo -n "::: Un-whitelisting $rdom on IPv4 and IPv6..." - echo $rdom | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList + echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList echo " done!" else echo -n "::: Un-whitelisting $rdom on IPv4" - echo $rdom | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList + echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList echo " done!" fi echo -n "::: Removing $rdom from whitelist.txt..." - echo $rdom| sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist + echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist echo " done!" done fi @@ -166,7 +165,7 @@ function Reload() { if [[ $dnsmasqPid ]]; then # service already running - reload config - sudo kill -HUP $dnsmasqPid + sudo kill -HUP "$dnsmasqPid" else # service not running, start it up sudo service dnsmasq start @@ -183,7 +182,7 @@ do "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; "-q" | "--quiet" ) versbose=false;; - * ) HandleOther $var;; + * ) HandleOther "$var";; esac done diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8068a485..fe385fbb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -40,7 +40,7 @@ c=$(( columns / 2 )) # Find IP used to route to outside world IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') -IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') +IPv4addr=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1) @@ -63,13 +63,13 @@ else fi fi - -if [ -d "/etc/pihole" ]; then - # Likely an existing install - upgrade=true - else - upgrade=false -fi +### Nate 3/26/2016 - Why are we declaring upgrade here? It isn't global (nor is it used anywhere else) +# if [ -d "/etc/pihole" ]; then + # # Likely an existing install + # upgrade=true + # else + # upgrade=false +# fi ####### FUNCTIONS ########## ###All credit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html @@ -78,10 +78,10 @@ spinner() { spin='-\|/' i=0 - while $SUDO kill -0 $pid 2>/dev/null + while $SUDO kill -0 "$pid" 2>/dev/null do i=$(( (i+1) %4 )) - printf "\b${spin:$i:1}" + printf "\b%s" "{$spin:$i:1}" sleep .1 done printf "\b" @@ -92,12 +92,12 @@ backupLegacyPihole() { if [[ -f /etc/dnsmasq.d/adList.conf ]];then echo "::: Original Pi-hole detected. Initiating sub space transport" $SUDO mkdir -p /etc/pihole/original/ - $SUDO mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf.$(date "+%Y-%m-%d") - $SUDO mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf.$(date "+%Y-%m-%d") - $SUDO mv /etc/resolv.conf /etc/pihole/original/resolv.conf.$(date "+%Y-%m-%d") - $SUDO mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf.$(date "+%Y-%m-%d") - $SUDO mv /var/www/pihole/index.html /etc/pihole/original/index.html.$(date "+%Y-%m-%d") - $SUDO mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh.$(date "+%Y-%m-%d") + $SUDO mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf."$(date "+%Y-%m-%d")" + $SUDO mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf."$(date "+%Y-%m-%d")" + $SUDO mv /etc/resolv.conf /etc/pihole/original/resolv.conf."$(date "+%Y-%m-%d")" + $SUDO mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf."$(date "+%Y-%m-%d")" + $SUDO mv /var/www/pihole/index.html /etc/pihole/original/index.html."$(date "+%Y-%m-%d")" + $SUDO mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh."$(date "+%Y-%m-%d")" else : fi @@ -120,9 +120,9 @@ verifyFreeDiskSpace() { # 25MB is the minimum space needed (20MB install + 5MB one day of logs.) requiredFreeBytes=51200 - existingFreeBytes=`df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1` + existingFreeBytes=$(df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1) if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then - existingFreeBytes=`df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1` + existingFreeBytes=$(df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1) fi if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then @@ -158,7 +158,7 @@ chooseInterface() { do piholeInterface=$desiredInterface echo "::: Using interface: $piholeInterface" - echo ${piholeInterface} > /tmp/piholeINT + echo "${piholeInterface}" > /tmp/piholeINT done else echo "::: Cancel selected, exiting...." @@ -169,7 +169,7 @@ chooseInterface() { cleanupIPv6() { # Removes IPv6 indicator file if we are not using IPv6 - if [ -f "/etc/pihole/.useIPv6" ] && [ ! $useIPv6 ]; then + if [ -f "/etc/pihole/.useIPv6" ] && [ ! "$useIPv6" ]; then rm /etc/pihole/.useIPv6 fi } @@ -244,11 +244,11 @@ getStaticIPv4Settings() { until [[ $ipSettingsCorrect = True ]] do # Ask for the IPv4 address - IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c $IPv4addr 3>&1 1>&2 2>&3) + IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c "$IPv4addr" 3>&1 1>&2 2>&3) if [[ $? = 0 ]];then echo "::: Your static IPv4 address: $IPv4addr" # Ask for the gateway - IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c $IPv4gw 3>&1 1>&2 2>&3) + IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c "$IPv4gw" 3>&1 1>&2 2>&3) if [[ $? = 0 ]];then echo "::: Your static IPv4 gateway: $IPv4gw" # Give the user a chance to review their settings before moving on @@ -257,8 +257,8 @@ getStaticIPv4Settings() { Gateway: $IPv4gw" $r $c)then # If the settings are correct, then we need to set the piholeIP # Saving it to a temporary file us to retrieve it later when we run the gravity.sh script - echo ${IPv4addr%/*} > /tmp/piholeIP - echo $piholeInterface > /tmp/piholeINT + echo "${IPv4addr%/*}" > /tmp/piholeIP + echo "$piholeInterface" > /tmp/piholeINT # After that's done, the loop ends and we move on ipSettingsCorrect=True else @@ -292,12 +292,12 @@ setDHCPCD() { setStaticIPv4() { # Tries to set the IPv4 address - if grep -q $IPv4addr $dhcpcdFile; then + if grep -q "$IPv4addr" $dhcpcdFile; then # address already set, noop : else setDHCPCD - $SUDO ip addr replace dev $piholeInterface $IPv4addr + $SUDO ip addr replace dev "$piholeInterface" "$IPv4addr" echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." echo ":::" @@ -377,14 +377,14 @@ setDNS(){ piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3) if [[ $? = 0 ]];then - piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') - piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') + piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') + piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') - if ! valid_ip $piholeDNS1 || [ ! $piholeDNS1 ]; then + if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then piholeDNS1=$strInvalid fi - if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then + if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then piholeDNS2=$strInvalid fi @@ -393,14 +393,14 @@ setDNS(){ exit 1 fi - if [[ $piholeDNS1 == $strInvalid ]] || [[ $piholeDNS2 == $strInvalid ]]; then + if [[ $piholeDNS1 == "$strInvalid" ]] || [[ $piholeDNS2 == "$strInvalid" ]]; then whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c - if [[ $piholeDNS1 == $strInvalid ]]; then + if [[ $piholeDNS1 == "$strInvalid" ]]; then piholeDNS1="" fi - if [[ $piholeDNS2 == $strInvalid ]]; then + if [[ $piholeDNS2 == "$strInvalid" ]]; then piholeDNS2="" fi @@ -510,7 +510,7 @@ checkForDependencies() { # it needs to have been run at least once on new installs! timestamp=$(stat -c %Y /var/cache/apt/) - timestampAsDate=$(date -d @$timestamp "+%b %e") + timestampAsDate=$(date -d @"$timestamp" "+%b %e") today=$(date "+%b %e") if [ ! "$today" == "$timestampAsDate" ]; then @@ -540,9 +540,9 @@ checkForDependencies() { do : echo -n "::: Checking for $i..." - if [ $(dpkg-query -W -f='${Status}' $i 2>/dev/null | grep -c "ok installed") -eq 0 ]; then + if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then echo -n " Not found! Installing...." - $SUDO apt-get -y -qq install $i > /dev/null & spinner $! + $SUDO apt-get -y -qq install "$i" > /dev/null & spinner $! echo " done!" else echo " already installed!" @@ -583,7 +583,7 @@ is_repo() { make_repo() { # Remove the non-repod interface and clone the interface echo -n "::: Cloning $2 into $1..." - $SUDO rm -rf $1 + $SUDO rm -rf "$1" $SUDO git clone -q "$2" "$1" > /dev/null & spinner $! echo " done!" } @@ -591,7 +591,7 @@ make_repo() { update_repo() { # Pull the latest commits echo -n "::: Updating repo in $1..." - cd "$1" + cd "$1" || exit $SUDO git pull -q > /dev/null & spinner $! echo " done!" } diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index ee4e80a0..d116c4e4 100644 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -27,9 +27,16 @@ fi ######### SCRIPT ########### -$SUDO apt-get -y remove --purge dnsutils bc toilet -$SUDO apt-get -y remove --purge dnsmasq -$SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 +read -p "Do you wish to purge PiHole's dependencies from your OS?\n WARNING: This is destructive if run on any non-Debian based OS \n(SAFE TO RUN ON RASPBIAN)" -n 1 -r +echo +if [[ $REPLY =~ ^{Yy]$ ]]; then + $SUDO apt-get -y remove --purge dnsutils bc toilet + $SUDO apt-get -y remove --purge dnsmasq + $SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 + + echo "Removing dnsmasq config files..." + $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig +fi # Only web directories/files that are created by pihole should be removed. echo "Removing the Pi-hole Web server files..." @@ -42,9 +49,6 @@ if [[ ! "$(ls -A /var/www/html)" ]]; then $SUDO rm -rf /var/www/html fi -echo "Removing dnsmasq config files..." -$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig - # Attempt to preserve backwards compatibility with older versions # to guarantee no additional changes were made to /etc/crontab after # the installation of pihole, /etc/crontab.pihole should be permanently @@ -63,7 +67,6 @@ if [[ -f /etc/cron.d/pihole ]];then fi echo "Removing config files and scripts..." -$SUDO rm /etc/dnsmasq.conf $SUDO rm -rf /etc/lighttpd/ $SUDO rm /var/log/pihole.log $SUDO rm /usr/local/bin/gravity.sh diff --git a/gravity.sh b/gravity.sh index 321aec27..4a04f222 100755 --- a/gravity.sh +++ b/gravity.sh @@ -41,7 +41,7 @@ if [[ -f $piholeIPfile ]];then else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') + piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}') piholeIP=${piholeIPCIDR%/*} fi @@ -54,18 +54,19 @@ fi # Variables for various stages of downloading and formatting the list +## Nate 3/26/2016 - Commented unused variables basename=pihole piholeDir=/etc/$basename adList=$piholeDir/gravity.list -blacklist=$piholeDir/blacklist.txt -whitelist=$piholeDir/whitelist.txt -latentWhitelist=$piholeDir/latentWhitelist.txt +#blacklist=$piholeDir/blacklist.txt +#whitelist=$piholeDir/whitelist.txt +#latentWhitelist=$piholeDir/latentWhitelist.txt justDomainsExtension=domains matterandlight=$basename.0.matterandlight.txt supernova=$basename.1.supernova.txt eventHorizon=$basename.2.eventHorizon.txt accretionDisc=$basename.3.accretionDisc.txt -eyeOfTheNeedle=$basename.4.wormhole.txt +#eyeOfTheNeedle=$basename.4.wormhole.txt # After setting defaults, check if there's local overrides if [[ -r $piholeDir/pihole.conf ]];then @@ -76,19 +77,18 @@ fi spinner(){ local pid=$1 - local delay=0.001 - local spinstr='/-\|' spin='-\|/' i=0 - while $SUDO kill -0 $pid 2>/dev/null + while $SUDO kill -0 "$pid" 2>/dev/null do i=$(( (i+1) %4 )) - printf "\b${spin:$i:1}" + printf "\b%s" "${spin:$i:1}" sleep .1 done printf "\b" } + ########################### # collapse - begin formation of pihole function gravity_collapse() { @@ -99,7 +99,7 @@ function gravity_collapse() { #custom file found, use this instead of default echo -n "::: Custom adList file detected. Reading..." sources=() - while read -a line; do + while read -r line; do #Do not read commented out or blank lines if [[ $line = \#* ]] || [[ ! $line ]]; then echo "" > /dev/null @@ -112,7 +112,7 @@ function gravity_collapse() { #no custom file found, use defaults! echo -n "::: No custom adlist file detected, reading from default file..." sources=() - while read -a line; do + while read -r line; do #Do not read commented out or blank lines if [[ $line = \#* ]] || [[ ! $line ]]; then echo "" > /dev/null @@ -146,7 +146,7 @@ function gravity_patternCheck() { # Some of the blocklists are copyright, they need to be downloaded # and stored as is. They can be processed for content after they # have been saved. - cp $patternBuffer $saveLocation + cp "$patternBuffer" "$saveLocation" echo " List updated, transport successful!" else # curl didn't download any host files, probably because of the date check @@ -169,12 +169,12 @@ function gravity_transport() { fi # Silently curl url - curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer + curl -s "$cmd_ext" "$heisenbergCompensator" -A "$agent" "$url" > "$patternBuffer" # Check for list updates - gravity_patternCheck $patternBuffer + gravity_patternCheck "$patternBuffer" # Cleanup - rm -f $patternBuffer + rm -f "$patternBuffer" } # spinup - main gravity function @@ -222,7 +222,7 @@ function gravity_Schwarzchild() { truncate -s 0 $piholeDir/$matterandlight & spinner $! for i in "${activeDomains[@]}" do - cat $i |tr -d '\r' >> $piholeDir/$matterandlight + "$i" |tr -d '\r' >> $piholeDir/$matterandlight done echo " done!" @@ -249,7 +249,7 @@ function gravity_Whitelist() { echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..." urls=() - for url in ${sources[@]} + for url in "${sources[@]}" do tmp=$(echo "$url" | awk -F '/' '{print $3}') urls=("${urls[@]}" $tmp) @@ -257,7 +257,7 @@ function gravity_Whitelist() { echo " done!" echo -n "::: Running whitelist script to update HOSTS file...." - $whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $! + $whitelistScript -f -nr -q "${urls[@]}" > /dev/null & spinner $! numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") plural=; [[ "$numWhitelisted" != "1" ]] && plural=s @@ -283,13 +283,13 @@ function gravity_hostFormat() { if [[ -n $piholeIPv6 ]];then #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc - cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc + $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc else # Otherwise, just create gravity.list as normal using IPv4 #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! echo -e "$piholeIP Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc - cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc + $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it cp $piholeDir/$accretionDisc $adList @@ -301,10 +301,10 @@ function gravity_blackbody() { for file in $piholeDir/*.$justDomainsExtension do # If list is in active array then leave it (noop) else rm the list - if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then + if [[ " ${activeDomains[@]} " =~ ${file} ]]; then : else - rm -f $file + rm -f "$file" fi done } @@ -343,7 +343,7 @@ function gravity_reload() { if [[ $dnsmasqPid ]]; then # service already running - reload config - $SUDO kill -HUP $dnsmasqPid & spinner $! + $SUDO kill -HUP "$dnsmasqPid" & spinner $! else # service not running, start it up $SUDO service dnsmasq start & spinner $! From 646c4a3ccc78c9167a79d5e4c95fe4bf6518cc86 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 26 Mar 2016 15:01:02 -0500 Subject: [PATCH 11/38] Newline not read correctly in prompt --- automated install/uninstall.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index d116c4e4..44cf2639 100644 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -27,7 +27,9 @@ fi ######### SCRIPT ########### -read -p "Do you wish to purge PiHole's dependencies from your OS?\n WARNING: This is destructive if run on any non-Debian based OS \n(SAFE TO RUN ON RASPBIAN)" -n 1 -r +read -p "Do you wish to purge PiHole's dependencies from your OS?" -n 1 -r +ehco "WARNING: This is destructive if run on any non-Debian based OS" +echo "(SAFE TO RUN ON RASPBIAN)" echo if [[ $REPLY =~ ^{Yy]$ ]]; then $SUDO apt-get -y remove --purge dnsutils bc toilet From 5223627b719008a124e4acacb1da3da5ddb037ab Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 26 Mar 2016 15:05:55 -0500 Subject: [PATCH 12/38] read locks echos... reordered to warn user --- automated install/uninstall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 44cf2639..dbc9cf00 100644 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -27,9 +27,9 @@ fi ######### SCRIPT ########### -read -p "Do you wish to purge PiHole's dependencies from your OS?" -n 1 -r -ehco "WARNING: This is destructive if run on any non-Debian based OS" +echo "WARNING: This is destructive if run on any non-Debian based OS" echo "(SAFE TO RUN ON RASPBIAN)" +read -p "Do you wish to purge PiHole's dependencies from your OS?" -n 1 -r echo if [[ $REPLY =~ ^{Yy]$ ]]; then $SUDO apt-get -y remove --purge dnsutils bc toilet From 7388461ede2a71d7f42b27fecf5072440b830db3 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 26 Mar 2016 15:18:53 -0500 Subject: [PATCH 13/38] Modularized uninstall for cleanliness and robust usability. --- automated install/uninstall.sh | 104 ++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 46 deletions(-) mode change 100644 => 100755 automated install/uninstall.sh diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh old mode 100644 new mode 100755 index dbc9cf00..5ddaa0ac --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -25,54 +25,66 @@ else fi fi +function removeAndPurge { + # Purge dependencies + echo "Purging dependencies!" + $SUDO apt-get -y remove --purge dnsutils bc toilet + $SUDO apt-get -y remove --purge dnsmasq + $SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 + + # Remove dependency config files + echo "Removing dnsmasq config files..." + $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig &> /dev/null +} + +function removeNoPurge { + # Only web directories/files that are created by pihole should be removed. + echo "Removing the Pi-hole Web server files..." + $SUDO rm -rf /var/www/html/admin &> /dev/null + $SUDO rm -rf /var/www/html/pihole &> /dev/null + $SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null + + # If the web directory is empty after removing these files, then the parent html folder can be removed. + if [[ ! "$(ls -A /var/www/html)" ]]; then + $SUDO rm -rf /var/www/html &> /dev/null + fi + + # Attempt to preserve backwards compatibility with older versions + # to guarantee no additional changes were made to /etc/crontab after + # the installation of pihole, /etc/crontab.pihole should be permanently + # preserved. + if [[ -f /etc/crontab.orig ]]; then + echo "Initial Pi-hole cron detected. Restoring the default system cron..." + $SUDO mv /etc/crontab /etc/crontab.pihole + $SUDO mv /etc/crontab.orig /etc/crontab + $SUDO service cron restart + fi + + # Attempt to preserve backwards compatibility with older versions + if [[ -f /etc/cron.d/pihole ]];then + echo "Removing cron.d/pihole..." + $SUDO rm /etc/cron.d/pihole &> /dev/null + fi + + echo "Removing config files and scripts..." + $SUDO rm -rf /etc/lighttpd/ &> /dev/null + $SUDO rm /var/log/pihole.log &> /dev/null + $SUDO rm /usr/local/bin/gravity.sh &> /dev/null + $SUDO rm /usr/local/bin/chronometer.sh &> /dev/null + $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null + $SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null + $SUDO rm -rf /etc/pihole/ &> /dev/null + +} ######### SCRIPT ########### echo "WARNING: This is destructive if run on any non-Debian based OS" echo "(SAFE TO RUN ON RASPBIAN)" -read -p "Do you wish to purge PiHole's dependencies from your OS?" -n 1 -r -echo -if [[ $REPLY =~ ^{Yy]$ ]]; then - $SUDO apt-get -y remove --purge dnsutils bc toilet - $SUDO apt-get -y remove --purge dnsmasq - $SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 +while true; do + read -p "Do you wish to purge PiHole's dependencies from your OS?" yn + case $yn in + [Yy]* ) removeAndPurge; break;; - echo "Removing dnsmasq config files..." - $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -fi - -# Only web directories/files that are created by pihole should be removed. -echo "Removing the Pi-hole Web server files..." -$SUDO rm -rf /var/www/html/admin -$SUDO rm -rf /var/www/html/pihole -$SUDO rm /var/www/html/index.lighttpd.orig - -# If the web directory is empty after removing these files, then the parent html folder can be removed. -if [[ ! "$(ls -A /var/www/html)" ]]; then - $SUDO rm -rf /var/www/html -fi - -# Attempt to preserve backwards compatibility with older versions -# to guarantee no additional changes were made to /etc/crontab after -# the installation of pihole, /etc/crontab.pihole should be permanently -# preserved. -if [[ -f /etc/crontab.orig ]]; then - echo "Initial Pi-hole cron detected. Restoring the default system cron..." - $SUDO mv /etc/crontab /etc/crontab.pihole - $SUDO mv /etc/crontab.orig /etc/crontab - $SUDO service cron restart -fi - -# Attempt to preserve backwards compatibility with older versions -if [[ -f /etc/cron.d/pihole ]];then - echo "Removing cron.d/pihole..." - $SUDO rm /etc/cron.d/pihole -fi - -echo "Removing config files and scripts..." -$SUDO rm -rf /etc/lighttpd/ -$SUDO rm /var/log/pihole.log -$SUDO rm /usr/local/bin/gravity.sh -$SUDO rm /usr/local/bin/chronometer.sh -$SUDO rm /usr/local/bin/whitelist.sh -$SUDO rm /usr/local/bin/piholeLogFlush.sh -$SUDO rm -rf /etc/pihole/ + [Nn]* ) removeNoPurge; break;; + esac +done From 901cb44f5e2fe688cde871e1304ae1805c519c73 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 26 Mar 2016 16:50:05 -0500 Subject: [PATCH 14/38] Added /etc/.pihole/ and /var/log/*pihole* to uninstall as well as fixed missing call to removeNoPurge. --- automated install/basic-install.sh | 26 +++++++++++++------------- automated install/uninstall.sh | 14 +++++++++++--- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index fe385fbb..2f910c03 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -72,19 +72,19 @@ fi # fi ####### FUNCTIONS ########## -###All credit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html -spinner() { - local pid=$1 - - spin='-\|/' - i=0 - while $SUDO kill -0 "$pid" 2>/dev/null - do - i=$(( (i+1) %4 )) - printf "\b%s" "{$spin:$i:1}" - sleep .1 - done - printf "\b" +spinner() +{ + local pid=$1 + local delay=0.75 + local spinstr='|/-\' + while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" } backupLegacyPihole() { diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 5ddaa0ac..9c47ce44 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -34,7 +34,10 @@ function removeAndPurge { # Remove dependency config files echo "Removing dnsmasq config files..." - $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig &> /dev/null + $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null + + # Call removeNoPurge to remove PiHole specific files + removeNoPurge } function removeNoPurge { @@ -45,8 +48,10 @@ function removeNoPurge { $SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null # If the web directory is empty after removing these files, then the parent html folder can be removed. - if [[ ! "$(ls -A /var/www/html)" ]]; then - $SUDO rm -rf /var/www/html &> /dev/null + if [ -d "/var/www/html" ]; then + if [[ ! "$(ls -A /var/www/html)" ]]; then + $SUDO rm -rf /var/www/html &> /dev/null + fi fi # Attempt to preserve backwards compatibility with older versions @@ -73,7 +78,10 @@ function removeNoPurge { $SUDO rm /usr/local/bin/chronometer.sh &> /dev/null $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null $SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null + $SUDO rm /usr/local/bin/piholeDebug.sh &> /dev/null + $SUDO rm -rf /var/log/*pihole* &> /dev/null $SUDO rm -rf /etc/pihole/ &> /dev/null + $SUDO rm -rf /etc/.pihole/ &> /dev/null } From 5ee382c8ebd96b920133e82c30079dcb6f6e6ab8 Mon Sep 17 00:00:00 2001 From: nate Date: Sat, 26 Mar 2016 17:00:52 -0500 Subject: [PATCH 15/38] Roll back addition of piholeDebug.sh (production master base) --- advanced/Scripts/piholeDebug.sh | 157 ----------------------------- automated install/basic-install.sh | 3 +- 2 files changed, 1 insertion(+), 159 deletions(-) delete mode 100644 advanced/Scripts/piholeDebug.sh diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh deleted file mode 100644 index ead75cd9..00000000 --- a/advanced/Scripts/piholeDebug.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/usr/bin/env bash -# Pi-hole: A black hole for Internet advertisements -# (c) 2015, 2016 by Jacob Salmela -# Network-wide ad blocking via your Raspberry Pi -# http://pi-hole.net -# Flushes /var/log/pihole.log -# -# Pi-hole is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# Nate Brandeburg -# nate@ubiquisoft.com -# 3/19/2016 - -######## GLOBAL VARS ######## -DEBUG_LOG="/var/log/pihole_debug.log" - -######## FIRST CHECK ######## -# Must be root to debug -if [[ $EUID -eq 0 ]];then - echo "::: You are root... Beginning debug!" -else - echo "::: sudo will be used for debugging." - # Check if sudo is actually installed - if [[ $(dpkg-query -s sudo) ]];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 1 - fi -fi - -# Ensure the file exists, create if not, clear if exists. -if [ ! -f "$DEBUG_LOG" ] -then - $SUDO touch $DEBUG_LOG - $SUDO chmod 644 $DEBUG_LOG - $SUDO chown "$USER":root $DEBUG_LOG -else - truncate -s 0 $DEBUG_LOG -fi - -### Check Pi internet connections ### -# Log the IP addresses of this Pi -IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e') -echo "Writing local IPs to debug log" -echo "IP Addresses of this Pi:" >> $DEBUG_LOG -echo "$IPADDR" >> $DEBUG_LOG -echo >> $DEBUG_LOG - -# Check if we can connect to the local gateway -GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error) -echo "Gateway check:" >> $DEBUG_LOG -echo "$GATEWAY_CHECK" >> $DEBUG_LOG -echo >> $DEBUG_LOG - -echo "Writing dnsmasq.conf to debug log..." -echo "############### Dnsmasq ###############" >> $DEBUG_LOG -DNSMASQFILE="/etc/dnsmasq.conf" -if [ -e "$DNSMASQFILE" ] -then - cat $DNSMASQFILE >> $DEBUG_LOG - echo >> $DEBUG_LOG -else - echo "No dnsmasq.conf file found!" >> $DEBUG_LOG - echo "No dnsmasq.conf file found!" -fi - -echo "Writing hosts file to debug log..." -echo "############### Hosts ###############" >> $DEBUG_LOG -HOSTSFILE="/etc/hosts" -if [ -e "$HOSTSFILE" ] -then - cat "$HOSTSFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG -else - echo "No hosts file found!" >> $DEBUG_LOG - echo "No hosts file found!" -fi - -### PiHole application specific logging ### -# Write Pi-Hole logs to debug log -echo "Writing whitelist to debug log..." -echo "############### Whitelist ###############" >> $DEBUG_LOG -WHITELISTFILE="/etc/pihole/whitelist.txt" -if [ -e "$WHITELISTFILE" ] -then - cat "$WHITELISTFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG -else - echo "No whitelist.txt file found!" >> $DEBUG_LOG - echo "No whitelist.txt file found!" -fi - -echo "Writing blacklist to debug log..." -echo "############### Blacklist ###############" >> $DEBUG_LOG -BLACKLISTFILE="/etc/pihole/blacklist.txt" -if [ -e "$BLACKLISTFILE" ] -then - cat "$BLACKLISTFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG -else - echo "No blacklist.txt file found!" >> $DEBUG_LOG - echo "No blacklist.txt file found!" -fi - -echo "Writing adlists.list to debug log..." -echo "############### adlists.list ###############" >> $DEBUG_LOG -ADLISTSFILE="/etc/pihole/adlists.list" -if [ -e "$ADLISTSFILE" ] -then - cat "$ADLISTSFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG -else - echo "No adlists.list file found!" >> $DEBUG_LOG - echo "No adlists.list file found!" -fi - - -# Continuously append the pihole.log file to the pihole_debug.log file -function dumpPiHoleLog { - trap '{ echo -e "\nFinishing debug write from interrupt... Quitting!" ; exit 1; }' INT - echo -e "Writing current pihole traffic to debug log...\nTry loading any/all sites that you are having trouble with now... (Press ctrl+C to finish)" - echo "############### pihole.log ###############" >> $DEBUG_LOG - PIHOLELOG="/var/log/pihole.log" - if [ -e "$PIHOLELOG" ] - then - while true; do - tail -f "$PIHOLELOG" >> $DEBUG_LOG - echo >> $DEBUG_LOG - done - else - echo "No pihole.log file found!" >> $DEBUG_LOG - echo "No pihole.log file found!" - fi -} - -function finalWrites { - # Write the gravity.list after the user is finished capturing the pihole.log output - echo "Writing gravity.list to debug log..." - echo "############### gravity.list ###############" >> $DEBUG_LOG - GRAVITYFILE="/etc/pihole/gravity.list" - if [ -e "$GRAVITYFILE" ] - then - cat /etc/pihole/gravity.list >> $DEBUG_LOG - echo >> $DEBUG_LOG - else - echo "No gravity.list file found!" >> $DEBUG_LOG - echo "No gravity.list file found" - fi -} -trap finalWrites EXIT - -### Method calls for additinal logging ### -dumpPiHoleLog diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2f910c03..d3ba437f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -477,8 +477,7 @@ installScripts() { $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /usr/local/bin/blacklist.sh $SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /usr/local/bin/piholeLogFlush.sh $SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /usr/local/bin/updateDashboard.sh - $SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /usr/local/bin/piholeDebug.sh - $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,piholeDebug}.sh + $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh $SUDO echo " done." } From 5442954db6cd63a81eddc3e66d5cd48179102d52 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 27 Mar 2016 01:53:48 -0500 Subject: [PATCH 16/38] Prompt user to remove each dependent package if they do choose to remove packages at all. --- automated install/basic-install.sh | 11 +++++-- automated install/uninstall.sh | 51 +++++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d3ba437f..7833c7e4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -75,9 +75,9 @@ fi spinner() { local pid=$1 - local delay=0.75 + local delay=0.50 local spinstr='|/-\' - while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do local temp=${spinstr#?} printf " [%c] " "$spinstr" local spinstr=$temp${spinstr%"$temp"} @@ -486,6 +486,10 @@ installConfigs() { $SUDO echo ":::" $SUDO echo "::: Installing configs..." versionCheckDNSmasq + if [ ! -d "/etc/lighttpd" ]; then + $SUDO mkdir /etc/lighttpd + $SUDO chown "$USER":root /etc/lighttpds + fi $SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig $SUDO cp /etc/.pihole/advanced/lighttpd.conf /etc/lighttpd/lighttpd.conf } @@ -664,6 +668,9 @@ installPihole() { stopServices setUser $SUDO mkdir -p /etc/pihole/ + if [ ! -d "/var/www/html" ]; then + $SUDO mkdir /var/www/html + fi $SUDO chown www-data:www-data /var/www/html $SUDO chmod 775 /var/www/html $SUDO usermod -a -G www-data pihole diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 9c47ce44..8467256f 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -14,7 +14,7 @@ if [[ $EUID -eq 0 ]];then echo "You are root." else - echo "sudo will be used for the install." + echo "sudo will be used for the uninstall." # Check if it is actually installed # If it isn't, exit because the unnstall cannot complete if [[ $(dpkg-query -s sudo) ]];then @@ -27,15 +27,49 @@ fi function removeAndPurge { # Purge dependencies - echo "Purging dependencies!" - $SUDO apt-get -y remove --purge dnsutils bc toilet - $SUDO apt-get -y remove --purge dnsmasq - $SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 + read -p "Do you wish to purge dnsutils?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + $SUDO apt-get -y remove --purge dnsutils + fi + + read -p "Do you wish to purge bc?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + $SUDO apt-get -y remove --purge bc + fi + + read -p "Do you wish to purge toilet?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + $SUDO apt-get -y remove --purge toilet + fi + + read -p "Do you wish to purge dnsmasq?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + $SUDO apt-get -y remove --purge dnsmasq + fi + + read -p "Do you wish to purge lighttpd?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + $SUDO apt-get -y remove --purge lighttpd + fi + + read -p "Do you wish to purge php5?" -n 1 -r + echo + if [[ $REPLY =~ ^[Yy]$ ]]; then + $SUDO apt-get -y remove --purge php5-common php5-cgi php5 + fi # Remove dependency config files echo "Removing dnsmasq config files..." $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null + # Take care of any additional package cleaning + $SUDO apt-get -y autoremove + # Call removeNoPurge to remove PiHole specific files removeNoPurge } @@ -86,13 +120,14 @@ function removeNoPurge { } ######### SCRIPT ########### -echo "WARNING: This is destructive if run on any non-Debian based OS" -echo "(SAFE TO RUN ON RASPBIAN)" +echo "Preparing to remove packages, be sure that each may be safely removed depending on your operating system." +echo "(SAFE TO REMOVE ALL ON RASPBIAN)" while true; do - read -p "Do you wish to purge PiHole's dependencies from your OS?" yn + read -rp "Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package)" yn case $yn in [Yy]* ) removeAndPurge; break;; [Nn]* ) removeNoPurge; break;; esac done + From 2b5cee05e6e5c1181256ef1b8dfb1b089851e09a Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 27 Mar 2016 01:57:52 -0500 Subject: [PATCH 17/38] Check for existing directory before trying to perform operations on it. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 7833c7e4..ca546256 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -488,7 +488,7 @@ installConfigs() { versionCheckDNSmasq if [ ! -d "/etc/lighttpd" ]; then $SUDO mkdir /etc/lighttpd - $SUDO chown "$USER":root /etc/lighttpds + $SUDO chown "$USER":root /etc/lighttpd fi $SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig $SUDO cp /etc/.pihole/advanced/lighttpd.conf /etc/lighttpd/lighttpd.conf From 8c45bd32b749e0b95840b974e7c7123da7a87eac Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 27 Mar 2016 12:31:05 -0500 Subject: [PATCH 18/38] Loop through dependencies for future expansion. Syntax of uninstall script now matches basic-install.sh. More error handling of missing default files. Force user prompt for removing packages when uninstalling. --- automated install/basic-install.sh | 11 ++-- automated install/uninstall.sh | 101 +++++++++++++++-------------- 2 files changed, 60 insertions(+), 52 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ca546256..134ec3e2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -489,8 +489,8 @@ installConfigs() { if [ ! -d "/etc/lighttpd" ]; then $SUDO mkdir /etc/lighttpd $SUDO chown "$USER":root /etc/lighttpd + $SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi - $SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig $SUDO cp /etc/.pihole/advanced/lighttpd.conf /etc/lighttpd/lighttpd.conf } @@ -622,9 +622,13 @@ installPiholeWeb() { $SUDO echo " Existing page detected, not overwriting" else $SUDO mkdir /var/www/html/pihole - $SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + if [ -f /var/www/html/index.lighttpd.html ]; then + $SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + else + printf "\n:::\tNo default index.lighttpd.html file found... not backing up" + fi $SUDO cp /etc/.pihole/advanced/index.html /var/www/html/pihole/index.html - $SUDO echo " done!" + $SUDO echo "::: done!" fi } @@ -646,7 +650,6 @@ runGravity() { fi #Don't run as SUDO, this was causing issues echo "::: Running gravity.sh" - echo ":::" /usr/local/bin/gravity.sh } diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 8467256f..ffbf4246 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -12,71 +12,71 @@ # Must be root to uninstall if [[ $EUID -eq 0 ]];then - echo "You are root." + echo "::: You are root." else - echo "sudo will be used for the uninstall." + echo "::: Sudo will be used for the uninstall." # Check if it is actually installed # If it isn't, exit because the unnstall cannot complete if [[ $(dpkg-query -s sudo) ]];then export SUDO="sudo" else - echo "Please install sudo or run this as root." + echo "::: Please install sudo or run this as root." exit 1 fi fi +spinner() +{ + local pid=$1 + local delay=0.50 + local spinstr='|/-\' + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" +} + function removeAndPurge { # Purge dependencies - read -p "Do you wish to purge dnsutils?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - $SUDO apt-get -y remove --purge dnsutils - fi - - read -p "Do you wish to purge bc?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - $SUDO apt-get -y remove --purge bc - fi - - read -p "Do you wish to purge toilet?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - $SUDO apt-get -y remove --purge toilet - fi - - read -p "Do you wish to purge dnsmasq?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - $SUDO apt-get -y remove --purge dnsmasq - fi - - read -p "Do you wish to purge lighttpd?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - $SUDO apt-get -y remove --purge lighttpd - fi - - read -p "Do you wish to purge php5?" -n 1 -r - echo - if [[ $REPLY =~ ^[Yy]$ ]]; then - $SUDO apt-get -y remove --purge php5-common php5-cgi php5 - fi +echo ":::" + dependencies=( dnsutils bc toilet figlet dnsmasq lighttpd php5-common php5-cgi php5 git curl unzip wget ) + for i in "${dependencies[@]}"; do + if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" | grep -c "ok installed")" -eq 1 ]; then + while true; do + read -rp "::: Do you wish to remove $i from your system? (y/n): " yn + case $yn in + [Yy]* ) echo "::: Removing $i..."; $SUDO apt-get -y remove --purge "$i" > /dev/null & spinner $!; echo "DONE!"; break;; + [Nn]* ) echo "::: Skipping $i"; break;; + * ) echo "::: You must answer yes or no!";; + esac + done + else + echo "IF FAILED ***" + fi + done # Remove dependency config files - echo "Removing dnsmasq config files..." + echo "::: Removing dnsmasq config files..." $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null # Take care of any additional package cleaning - $SUDO apt-get -y autoremove + echo "::: Auto removing remaining dependencies" + $SUDO apt-get -y autoremove &> /dev/null & spinner $!; echo "DONE!"; + echo "::: Auto cleaning remaining dependencies" + $SUDO apt-get -y autoclean &> /dev/null & spinner $!; echo "DONE!"; # Call removeNoPurge to remove PiHole specific files removeNoPurge } function removeNoPurge { + echo ":::" # Only web directories/files that are created by pihole should be removed. - echo "Removing the Pi-hole Web server files..." + echo "::: Removing the Pi-hole Web server files..." $SUDO rm -rf /var/www/html/admin &> /dev/null $SUDO rm -rf /var/www/html/pihole &> /dev/null $SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null @@ -93,7 +93,7 @@ function removeNoPurge { # the installation of pihole, /etc/crontab.pihole should be permanently # preserved. if [[ -f /etc/crontab.orig ]]; then - echo "Initial Pi-hole cron detected. Restoring the default system cron..." + echo "::: Initial Pi-hole cron detected. Restoring the default system cron..." $SUDO mv /etc/crontab /etc/crontab.pihole $SUDO mv /etc/crontab.orig /etc/crontab $SUDO service cron restart @@ -101,11 +101,11 @@ function removeNoPurge { # Attempt to preserve backwards compatibility with older versions if [[ -f /etc/cron.d/pihole ]];then - echo "Removing cron.d/pihole..." + echo "::: Removing cron.d/pihole..." $SUDO rm /etc/cron.d/pihole &> /dev/null fi - echo "Removing config files and scripts..." + echo "::: Removing config files and scripts..." $SUDO rm -rf /etc/lighttpd/ &> /dev/null $SUDO rm /var/log/pihole.log &> /dev/null $SUDO rm /usr/local/bin/gravity.sh &> /dev/null @@ -116,14 +116,18 @@ function removeNoPurge { $SUDO rm -rf /var/log/*pihole* &> /dev/null $SUDO rm -rf /etc/pihole/ &> /dev/null $SUDO rm -rf /etc/.pihole/ &> /dev/null - + + echo ":::" + printf "::: Finished removing PiHole from your system. Sorry to see you go!\n" + printf "::: Reach out to us at https://github.com/pi-hole/pi-hole/issues if you need help\n" + printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L install.pi-hole.net | bash\n:::\n::: at any time!\n:::\n" } ######### SCRIPT ########### -echo "Preparing to remove packages, be sure that each may be safely removed depending on your operating system." -echo "(SAFE TO REMOVE ALL ON RASPBIAN)" +echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system." +echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" while true; do - read -rp "Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package)" yn + read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package)" yn case $yn in [Yy]* ) removeAndPurge; break;; @@ -131,3 +135,4 @@ while true; do esac done + From 1a1026b367d0b34512e96b8f070a7452f049844b Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 27 Mar 2016 14:44:42 -0500 Subject: [PATCH 19/38] Consistent stdout to match basic-install.sh and uninstall.sh --- advanced/Scripts/piholeDebug.sh | 46 ++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ab417aa6..7656f963 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -31,14 +31,14 @@ WHITELISTMATCHES="/tmp/whitelistmatches.list" ######## FIRST CHECK ######## # Must be root to debug if [[ $EUID -eq 0 ]]; then - echo "You are root... Beginning debug!" + echo "::: You are root... Beginning debug!" else - echo "sudo will be used for debugging." + echo "::: Sudo will be used for debugging." # Check if sudo is actually installed if [[ $(dpkg-query -s sudo) ]]; then export SUDO="sudo" else - echo "Please install sudo or run this as root." + echo "::: Please install sudo or run this as root." exit 1 fi fi @@ -119,7 +119,7 @@ function testNslookup { ### Check Pi internet connections ### # Log the IP addresses of this Pi IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e') -echo "Writing local IPs to debug log" +echo "::: Writing local IPs to debug log" echo "IP Addresses of this Pi:" >> $DEBUG_LOG echo "$IPADDR" >> $DEBUG_LOG echo >> $DEBUG_LOG @@ -135,7 +135,7 @@ compareWhitelist compareBlacklist testNslookup -echo "Writing dnsmasq.conf to debug log..." +echo "::: Writing dnsmasq.conf to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############### Dnsmasq ###############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -151,10 +151,10 @@ then echo >> $DEBUG_LOG else echo "No dnsmasq.conf file found!" >> $DEBUG_LOG - echo "No dnsmasq.conf file found!" + printf ":::\tNo dnsmasq.conf file found!\n" fi -echo "Writing 01-pihole.conf to debug log..." +echo "::: Writing 01-pihole.conf to debug log..." echo "#######################################" >> $DEBUG_LOG echo "########### 01-pihole.conf ############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -170,10 +170,10 @@ then echo >> $DEBUG_LOG else echo "No 01-pihole.conf file found!" >> $DEBUG_LOG - echo "No 01-pihole.conf file found" + echo "::: No 01-pihole.conf file found\n" fi -echo "Writing lighttpd.conf to debug log..." +echo "::: Writing lighttpd.conf to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############ lighttpd.conf ############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -189,10 +189,10 @@ then echo >> $DEBUG_LOG else echo "No lighttpd.conf file found!" >> $DEBUG_LOG - echo "No lighttpd.conf file found" + printf ":::\tNo lighttpd.conf file found\n" fi -echo "Writing size of gravity.list to debug log..." +echo "::: Writing size of gravity.list to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############ gravity.list #############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -202,14 +202,14 @@ then echo >> $DEBUG_LOG else echo "No gravity.list file found!" >> $DEBUG_LOG - echo "No gravity.list file found" + printf ":::\tNo gravity.list file found\n" fi # Write the hostname output to compare against entries in /etc/hosts, which is logged next echo "Hostname of this pihole is: " >> $DEBUG_LOG hostname >> $DEBUG_LOG -echo "Writing hosts file to debug log..." +echo "::: Writing hosts file to debug log..." echo "#######################################" >> $DEBUG_LOG echo "################ Hosts ################" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -219,11 +219,11 @@ then echo >> $DEBUG_LOG else echo "No hosts file found!" >> $DEBUG_LOG - echo "No hosts file found!" + printf ":::\tNo hosts file found!\n" fi ### PiHole application specific logging ### -echo "Writing whitelist to debug log..." +echo "::: Writing whitelist to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############## Whitelist ##############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -233,10 +233,10 @@ then echo >> $DEBUG_LOG else echo "No whitelist.txt file found!" >> $DEBUG_LOG - echo "No whitelist.txt file found!" + printf ":::\tNo whitelist.txt file found!\n" fi -echo "Writing blacklist to debug log..." +echo "::: Writing blacklist to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############## Blacklist ##############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -246,10 +246,10 @@ then echo >> $DEBUG_LOG else echo "No blacklist.txt file found!" >> $DEBUG_LOG - echo "No blacklist.txt file found!" + printf ":::\tNo blacklist.txt file found!\n" fi -echo "Writing adlists.list to debug log..." +echo "::: Writing adlists.list to debug log..." echo "#######################################" >> $DEBUG_LOG echo "############ adlists.list #############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -259,14 +259,14 @@ then echo >> $DEBUG_LOG else echo "No adlists.list file found!" >> $DEBUG_LOG - echo "No adlists.list file found!" + printf ":::\tNo adlists.list file found!\n" fi # Continuously append the pihole.log file to the pihole_debug.log file function dumpPiHoleLog { trap '{ echo -e "\nFinishing debug write from interrupt... Quitting!" ; exit 1; }' INT - echo -e "Writing current pihole traffic to debug log...\nTry loading any/all sites that you are having trouble with now... (Press ctrl+C to finish)" + echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" echo "#######################################" >> $DEBUG_LOG echo "############# pihole.log ##############" >> $DEBUG_LOG echo "#######################################" >> $DEBUG_LOG @@ -278,13 +278,13 @@ function dumpPiHoleLog { done else echo "No pihole.log file found!" >> $DEBUG_LOG - echo "No pihole.log file found!" + printf ":::\tNo pihole.log file found!\n" fi } # Anything to be done after capturing of pihole.log terminates function finalWork { - echo "Finshed debugging!" + echo "::: Finshed debugging!" } trap finalWork EXIT From 6145748bfb3e922068b51c4d97108cdd6cb825c8 Mon Sep 17 00:00:00 2001 From: nate Date: Sun, 27 Mar 2016 20:36:31 -0500 Subject: [PATCH 20/38] Change single echo to printf to forrect \t interpretation --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 7656f963..d2c8e245 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -170,7 +170,7 @@ then echo >> $DEBUG_LOG else echo "No 01-pihole.conf file found!" >> $DEBUG_LOG - echo "::: No 01-pihole.conf file found\n" + printf ":::\tNo 01-pihole.conf file found\n" fi echo "::: Writing lighttpd.conf to debug log..." From c520c55ff4b7b5288cf5344fd2e0144abe018e98 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 10:24:13 -0500 Subject: [PATCH 21/38] Addressed UAT issues and moved scripts to /opt/pihole Symlinks now include the /etc/pihole scripts in the user's PATH. --- automated install/basic-install.sh | 32 +++++++++++++++++++++--------- automated install/uninstall.sh | 28 +++++++++++++++----------- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 134ec3e2..ff4962b7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -97,7 +97,12 @@ backupLegacyPihole() { $SUDO mv /etc/resolv.conf /etc/pihole/original/resolv.conf."$(date "+%Y-%m-%d")" $SUDO mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf."$(date "+%Y-%m-%d")" $SUDO mv /var/www/pihole/index.html /etc/pihole/original/index.html."$(date "+%Y-%m-%d")" - $SUDO mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh."$(date "+%Y-%m-%d")" + if [ ! -d /opt/pihole ]; then + $SUDO mkdir /opt/pihole + $SUDO chown "$USER":root /opt/pihole + $SUDO chmod 1766 /opt/pihole + fi + $SUDO mv /opt/pihole/gravity.sh /etc/pihole/original/gravity.sh."$(date "+%Y-%m-%d")" else : fi @@ -470,14 +475,23 @@ versionCheckDNSmasq(){ installScripts() { # Install the scripts from /etc/.pihole to their various locations $SUDO echo ":::" - $SUDO echo -n "::: Installing scripts..." - $SUDO cp /etc/.pihole/gravity.sh /usr/local/bin/gravity.sh - $SUDO cp /etc/.pihole/advanced/Scripts/chronometer.sh /usr/local/bin/chronometer.sh - $SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /usr/local/bin/whitelist.sh - $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /usr/local/bin/blacklist.sh - $SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /usr/local/bin/piholeLogFlush.sh - $SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /usr/local/bin/updateDashboard.sh - $SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh + $SUDO echo -n "::: Installing scripts to /opt/pihole..." + if [ ! -d /opt/pihole ]; then + $SUDO mkdir /opt/pihole + $SUDO chown "$USER":root /opt/pihole + $SUDO chmod 1766 /opt/pihole + fi + $SUDO cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh + $SUDO cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh + $SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh + $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/bin/blacklist.sh + $SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh + $SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /opt/pihole/updateDashboard.sh + $SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh + $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall}.sh + for f in /opt/pihole/*; do + $SUDO ln -s /opt/pihole/"$f" /usr/local/bin/"$f" + done $SUDO echo " done." } diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index ffbf4246..a08a9900 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -43,19 +43,20 @@ spinner() function removeAndPurge { # Purge dependencies echo ":::" - dependencies=( dnsutils bc toilet figlet dnsmasq lighttpd php5-common php5-cgi php5 git curl unzip wget ) + # Nate 3/28/2016 - Removed `php5-cgi` and `php5` as they are removed with php5-common + dependencies=( dnsutils bc toilet figlet dnsmasq lighttpd php5-common git curl unzip wget ) for i in "${dependencies[@]}"; do - if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" | grep -c "ok installed")" -eq 1 ]; then + if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then while true; do - read -rp "::: Do you wish to remove $i from your system? (y/n): " yn + read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn case $yn in - [Yy]* ) echo "::: Removing $i..."; $SUDO apt-get -y remove --purge "$i" > /dev/null & spinner $!; echo "DONE!"; break;; - [Nn]* ) echo "::: Skipping $i"; break;; - * ) echo "::: You must answer yes or no!";; + [Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO apt-get -y remove --purge "$i" &> /dev/null & spinner $!; printf "DONE!\n"; break;; + [Nn]* ) printf ":::\tSkipping %s" "$i"; break;; + * ) printf "::: You must answer yes or no!";; esac done else - echo "IF FAILED ***" + printf ":::\tPackage %s not installed... Not removing.\n" "$i" fi done @@ -64,10 +65,10 @@ echo ":::" $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null # Take care of any additional package cleaning - echo "::: Auto removing remaining dependencies" - $SUDO apt-get -y autoremove &> /dev/null & spinner $!; echo "DONE!"; - echo "::: Auto cleaning remaining dependencies" - $SUDO apt-get -y autoclean &> /dev/null & spinner $!; echo "DONE!"; + printf "::: Auto removing remaining dependencies" + $SUDO apt-get -y autoremove &> /dev/null & spinner $!; printf "DONE!\n"; + printf "::: Auto cleaning remaining dependencies" + $SUDO apt-get -y autoclean &> /dev/null & spinner $!; printf "DONE!\n"; # Call removeNoPurge to remove PiHole specific files removeNoPurge @@ -113,21 +114,24 @@ function removeNoPurge { $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null $SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null $SUDO rm /usr/local/bin/piholeDebug.sh &> /dev/null + $SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null $SUDO rm -rf /var/log/*pihole* &> /dev/null $SUDO rm -rf /etc/pihole/ &> /dev/null $SUDO rm -rf /etc/.pihole/ &> /dev/null + $SUDO rm -rf /opt/pihole/ &> /dev/null echo ":::" printf "::: Finished removing PiHole from your system. Sorry to see you go!\n" printf "::: Reach out to us at https://github.com/pi-hole/pi-hole/issues if you need help\n" printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L install.pi-hole.net | bash\n:::\n::: at any time!\n:::\n" + printf "::: PLEASE RESET YOUR DNS ON YOUR ROUTER/CLIENTS TO RESTORE INTERNET CONNECTIVITY!/n" } ######### SCRIPT ########### echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system." echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" while true; do - read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package)" yn + read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]" yn case $yn in [Yy]* ) removeAndPurge; break;; From f444c7d4a577ad3641458c1a024aab5251b82d28 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 12:21:49 -0500 Subject: [PATCH 22/38] Merge resolution --- automated install/basic-install.sh | 53 ------------------------------ 1 file changed, 53 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2d08f17d..870de00c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -63,13 +63,6 @@ else fi fi -### Nate 3/26/2016 - Why are we declaring upgrade here? It isn't global (nor is it used anywhere else) -# if [ -d "/etc/pihole" ]; then - # # Likely an existing install - # upgrade=true - # else - # upgrade=false -# fi ####### FUNCTIONS ########## spinner() @@ -124,17 +117,10 @@ welcomeDialogs() { verifyFreeDiskSpace() { # 25MB is the minimum space needed (20MB install + 5MB one day of logs.) requiredFreeBytes=51200 -<<<<<<< HEAD - - existingFreeBytes=`df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1` - if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then - existingFreeBytes=`df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1` -======= existingFreeBytes=$(df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1) if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then existingFreeBytes=$(df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1) ->>>>>>> ScriptCleanup fi if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then @@ -389,16 +375,6 @@ setDNS(){ piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3) if [[ $? = 0 ]];then -<<<<<<< HEAD - piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') - piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') - - if ! valid_ip $piholeDNS1 || [ ! $piholeDNS1 ]; then - piholeDNS1=$strInvalid - fi - - if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then -======= piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') @@ -407,7 +383,6 @@ setDNS(){ fi if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then ->>>>>>> ScriptCleanup piholeDNS2=$strInvalid fi @@ -415,17 +390,6 @@ setDNS(){ echo "::: Cancel selected, exiting...." exit 1 fi -<<<<<<< HEAD - - if [[ $piholeDNS1 == $strInvalid ]] || [[ $piholeDNS2 == $strInvalid ]]; then - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c - - if [[ $piholeDNS1 == $strInvalid ]]; then - piholeDNS1="" - fi - - if [[ $piholeDNS2 == $strInvalid ]]; then -======= if [[ $piholeDNS1 == "$strInvalid" ]] || [[ $piholeDNS2 == "$strInvalid" ]]; then whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c @@ -435,7 +399,6 @@ setDNS(){ fi if [[ $piholeDNS2 == "$strInvalid" ]]; then ->>>>>>> ScriptCleanup piholeDNS2="" fi @@ -709,19 +672,6 @@ setUser(){ fi } -setPassword() { - # Password needed to authorize changes to lists from admin page - pass=$(whiptail --passwordbox "Please enter a password to secure your Pi-hole web interface." 10 50 3>&1 1>&2 2>&3) - - if [ $? = 0 ]; then - # Entered password - echo $pass > /etc/pihole/password.txt - else - echo "::: Cancel selected, exiting...." - exit 1 - fi -} - installPihole() { # Install base files and web interface checkForDependencies # done @@ -775,9 +725,6 @@ use4andor6 # Decide what upstream DNS Servers to use setDNS -# Set the admin page password -setPassword - # Install and log everything to a file installPihole | tee $tmpLog From a4fbccac9b011f19a627df62a1eba669b4e53c3b Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 12:53:21 -0500 Subject: [PATCH 23/38] Merge conflict resolution --- advanced/Scripts/blacklist.sh | 58 +++++++---------------------------- advanced/Scripts/whitelist.sh | 10 ------ 2 files changed, 11 insertions(+), 57 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 3fd50e83..23313d54 100644 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -51,19 +51,11 @@ fi function HandleOther(){ #check validity of domain -<<<<<<< HEAD - validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - - if [ -z "$validDomain" ]; then - echo $1 is not a valid argument or domain name - else -======= validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') if [ -z "$validDomain" ]; then echo "$1" is not a valid argument or domain name else ->>>>>>> ScriptCleanup domList=("${domList[@]}" $validDomain) fi } @@ -73,16 +65,9 @@ function PopBlacklistFile(){ if [[ ! -f $blacklist ]];then touch $blacklist fi - for dom in "${domList[@]}" -<<<<<<< HEAD - do - if $addmode; then - AddDomain $dom -======= - do + for dom in "${domList[@]}"; do if "$addmode"; then AddDomain "$dom" ->>>>>>> ScriptCleanup else RemoveDomain "$dom" fi @@ -134,43 +119,27 @@ function ModifyHostFile(){ numberOf=$($blacklist | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" -<<<<<<< HEAD - echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." - if [[ -n $piholeIPv6 ]];then - cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList - else - cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList - fi - -======= echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." if [[ -n $piholeIPv6 ]];then $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList - else + else $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList - fi - ->>>>>>> ScriptCleanup + fi fi else - echo ":::" for dom in "${domToRemoveList[@]}" do #we need to remove the domains from the blacklist file and the host file - echo "::: $dom" - echo -n "::: removing from HOSTS file..." -<<<<<<< HEAD - echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList -======= - echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList ->>>>>>> ScriptCleanup - echo " done!" - echo -n "::: removing from blackist.txt..." - echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist - echo " done!" + echo "::: $dom" + echo -n "::: removing from HOSTS file..." + echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList + echo " done!" + echo -n "::: removing from blackist.txt..." + echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist + echo " done!" done - fi + fi } @@ -199,13 +168,8 @@ do "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; -<<<<<<< HEAD - "-q" | "--quiet" ) versbose=false;; - * ) HandleOther $var;; -======= "-q" | "--quiet" ) versbose=false;; * ) HandleOther "$var";; ->>>>>>> ScriptCleanup esac done diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index a241505b..199c1bbe 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -51,13 +51,8 @@ fi function HandleOther(){ #check validity of domain -<<<<<<< HEAD - validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - -======= validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') ->>>>>>> ScriptCleanup if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else @@ -186,13 +181,8 @@ do "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; -<<<<<<< HEAD - "-q" | "--quiet" ) versbose=false;; - * ) HandleOther $var;; -======= "-q" | "--quiet" ) versbose=false;; * ) HandleOther "$var";; ->>>>>>> ScriptCleanup esac done From eaf89995ee9e4f76ea981bee41e45cece815170f Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 12:59:45 -0500 Subject: [PATCH 24/38] Merge conflict resolution --- automated install/basic-install.sh | 46 ------------------------------ 1 file changed, 46 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f5586508..870de00c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -117,17 +117,10 @@ welcomeDialogs() { verifyFreeDiskSpace() { # 25MB is the minimum space needed (20MB install + 5MB one day of logs.) requiredFreeBytes=51200 -<<<<<<< HEAD - - existingFreeBytes=`df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1` - if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then - existingFreeBytes=`df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1` -======= existingFreeBytes=$(df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1) if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then existingFreeBytes=$(df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1) ->>>>>>> ScriptCleanup-Dev fi if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then @@ -382,16 +375,6 @@ setDNS(){ piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" $r $c "$prePopulate" 3>&1 1>&2 2>&3) if [[ $? = 0 ]];then -<<<<<<< HEAD - piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') - piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') - - if ! valid_ip $piholeDNS1 || [ ! $piholeDNS1 ]; then - piholeDNS1=$strInvalid - fi - - if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; then -======= piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') @@ -400,7 +383,6 @@ setDNS(){ fi if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then ->>>>>>> ScriptCleanup-Dev piholeDNS2=$strInvalid fi @@ -408,17 +390,6 @@ setDNS(){ echo "::: Cancel selected, exiting...." exit 1 fi -<<<<<<< HEAD - - if [[ $piholeDNS1 == $strInvalid ]] || [[ $piholeDNS2 == $strInvalid ]]; then - whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c - - if [[ $piholeDNS1 == $strInvalid ]]; then - piholeDNS1="" - fi - - if [[ $piholeDNS2 == $strInvalid ]]; then -======= if [[ $piholeDNS1 == "$strInvalid" ]] || [[ $piholeDNS2 == "$strInvalid" ]]; then whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c @@ -428,7 +399,6 @@ setDNS(){ fi if [[ $piholeDNS2 == "$strInvalid" ]]; then ->>>>>>> ScriptCleanup-Dev piholeDNS2="" fi @@ -702,19 +672,6 @@ setUser(){ fi } -setPassword() { - # Password needed to authorize changes to lists from admin page - pass=$(whiptail --passwordbox "Please enter a password to secure your Pi-hole web interface." 10 50 3>&1 1>&2 2>&3) - - if [ $? = 0 ]; then - # Entered password - echo $pass > /etc/pihole/password.txt - else - echo "::: Cancel selected, exiting...." - exit 1 - fi -} - installPihole() { # Install base files and web interface checkForDependencies # done @@ -768,9 +725,6 @@ use4andor6 # Decide what upstream DNS Servers to use setDNS -# Set the admin page password -setPassword - # Install and log everything to a file installPihole | tee $tmpLog From f2150ee7e102ae55daef3607a7f8388e304ac526 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 13:07:51 -0500 Subject: [PATCH 25/38] Merge conflict resolution --- README.md | 12 +-------- advanced/Scripts/blacklist.sh | 49 +---------------------------------- advanced/Scripts/whitelist.sh | 11 -------- gravity.sh | 28 -------------------- 4 files changed, 2 insertions(+), 98 deletions(-) diff --git a/README.md b/README.md index 99fb7547..c58d6820 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,5 @@ -<<<<<<< HEAD -# Automated Install -##### Designed For Raspberry Pi A+, B, B+, 2, Zero (with an Ethernet adapter), and also works on most Debian based distros! -======= # Automated Install -<<<<<<< HEAD -##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) ->>>>>>> PiholeDebug -======= -##### Designed For Raspberry Pi A+, B, B+, 2, and Zero (with an Ethernet/Wi-Fi adapter) ->>>>>>> ScriptCleanup ->>>>>>> ScriptCleanup-Dev +##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!) 1. Install Raspbian on Raspberry Pi variants or a Debian based distribution on other hardware or virtual machines 2. Run the command below diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index c8a1cfd9..1780b8ec 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -51,19 +51,10 @@ fi function HandleOther(){ #check validity of domain -<<<<<<< HEAD - validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - - if [ -z "$validDomain" ]; then - echo $1 is not a valid argument or domain name - else -======= validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - if [ -z "$validDomain" ]; then echo "$1" is not a valid argument or domain name else ->>>>>>> ScriptCleanup-Dev domList=("${domList[@]}" $validDomain) fi } @@ -73,16 +64,9 @@ function PopBlacklistFile(){ if [[ ! -f $blacklist ]];then touch $blacklist fi -<<<<<<< HEAD - for dom in "${domList[@]}" - do - if $addmode; then - AddDomain $dom -======= for dom in "${domList[@]}"; do if "$addmode"; then AddDomain "$dom" ->>>>>>> ScriptCleanup-Dev else RemoveDomain "$dom" fi @@ -134,18 +118,6 @@ function ModifyHostFile(){ numberOf=$($blacklist | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" -<<<<<<< HEAD - echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." - if [[ -n $piholeIPv6 ]];then - cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList - else - cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList - fi - - fi - else - -======= echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." if [[ -n $piholeIPv6 ]];then $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList @@ -154,22 +126,10 @@ function ModifyHostFile(){ fi fi else ->>>>>>> ScriptCleanup-Dev echo ":::" - for dom in "${domToRemoveList[@]}" + for dom in "${domToRemoveList[@]}" do #we need to remove the domains from the blacklist file and the host file -<<<<<<< HEAD - echo "::: $dom" - echo -n "::: removing from HOSTS file..." - echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList - echo " done!" - echo -n "::: removing from blackist.txt..." - echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist - echo " done!" - done - fi -======= echo "::: $dom" echo -n "::: removing from HOSTS file..." echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList @@ -179,8 +139,6 @@ function ModifyHostFile(){ echo " done!" done fi ->>>>>>> ScriptCleanup-Dev - } function Reload() { @@ -208,13 +166,8 @@ do "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; -<<<<<<< HEAD - "-q" | "--quiet" ) versbose=false;; - * ) HandleOther $var;; -======= "-q" | "--quiet" ) versbose=false;; * ) HandleOther "$var";; ->>>>>>> ScriptCleanup-Dev esac done diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 3a30d11a..5d732ddc 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -51,13 +51,7 @@ fi function HandleOther(){ #check validity of domain -<<<<<<< HEAD - validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - -======= validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') - ->>>>>>> ScriptCleanup-Dev if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else @@ -186,13 +180,8 @@ do "-nr"| "--noreload" ) reload=false;; "-d" | "--delmode" ) addmode=false;; "-f" | "--force" ) force=true;; -<<<<<<< HEAD - "-q" | "--quiet" ) versbose=false;; - * ) HandleOther $var;; -======= "-q" | "--quiet" ) versbose=false;; * ) HandleOther "$var";; ->>>>>>> ScriptCleanup-Dev esac done diff --git a/gravity.sh b/gravity.sh index a8ac7029..531ae4c1 100755 --- a/gravity.sh +++ b/gravity.sh @@ -169,22 +169,12 @@ function gravity_transport() { fi # Silently curl url -<<<<<<< HEAD curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer # Check for list updates gravity_patternCheck $patternBuffer -======= -<<<<<<< HEAD - curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer - # Check for list updates - gravity_patternCheck $patternBuffer -======= curl -s "$cmd_ext" "$heisenbergCompensator" -A "$agent" "$url" > "$patternBuffer" # Check for list updates gravity_patternCheck "$patternBuffer" ->>>>>>> ScriptCleanup ->>>>>>> ScriptCleanup-Dev - # Cleanup rm -f "$patternBuffer" } @@ -269,16 +259,7 @@ function gravity_Whitelist() { echo " done!" echo -n "::: Running whitelist script to update HOSTS file...." -<<<<<<< HEAD - $whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $! - -<<<<<<< HEAD -======= -======= $whitelistScript -f -nr -q "${urls[@]}" > /dev/null & spinner $! - ->>>>>>> ScriptCleanup ->>>>>>> ScriptCleanup-Dev numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") plural=; [[ "$numWhitelisted" != "1" ]] && plural=s echo " $numWhitelisted domain${plural} whitelisted!" @@ -303,16 +284,7 @@ function gravity_hostFormat() { if [[ -n $piholeIPv6 ]];then #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc -<<<<<<< HEAD - cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc - -<<<<<<< HEAD -======= -======= $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc - ->>>>>>> ScriptCleanup ->>>>>>> ScriptCleanup-Dev else # Otherwise, just create gravity.list as normal using IPv4 #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! From bed869b08ef467984cb869cbf01c4f4724453de1 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 16:02:36 -0500 Subject: [PATCH 26/38] .DS_Store banished! --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store From 80f4bf94759643e3add582982d412f9bb080e777 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 16:20:23 -0500 Subject: [PATCH 27/38] Bug fixes Fixed DONE! to done! Fixed symlinking user scripts Fixed /n to \n --- .gitignore | 1 + automated install/basic-install.sh | 7 ++++--- automated install/uninstall.sh | 14 +++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 870de00c..dd5aa3a1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -472,18 +472,19 @@ installScripts() { if [ ! -d /opt/pihole ]; then $SUDO mkdir /opt/pihole $SUDO chown "$USER":root /opt/pihole - $SUDO chmod 1766 /opt/pihole + $SUDO chmod u+srwx /opt/pihole fi $SUDO cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh $SUDO cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh $SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh - $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/bin/blacklist.sh + $SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/blacklist.sh $SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh $SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /opt/pihole/updateDashboard.sh $SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall}.sh for f in /opt/pihole/*; do - $SUDO ln -s /opt/pihole/"$f" /usr/local/bin/"$f" + filename=${f##*/} + $SUDO ln -s /opt/pihole/"$filename" /usr/local/bin/"$filename" done $SUDO echo " done." } diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index a08a9900..ef82fa07 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -50,7 +50,7 @@ echo ":::" while true; do read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn case $yn in - [Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO apt-get -y remove --purge "$i" &> /dev/null & spinner $!; printf "DONE!\n"; break;; + [Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO apt-get -y remove --purge "$i" &> /dev/null & spinner $!; printf "done!\n"; break;; [Nn]* ) printf ":::\tSkipping %s" "$i"; break;; * ) printf "::: You must answer yes or no!";; esac @@ -65,10 +65,10 @@ echo ":::" $SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null # Take care of any additional package cleaning - printf "::: Auto removing remaining dependencies" - $SUDO apt-get -y autoremove &> /dev/null & spinner $!; printf "DONE!\n"; - printf "::: Auto cleaning remaining dependencies" - $SUDO apt-get -y autoclean &> /dev/null & spinner $!; printf "DONE!\n"; + printf "::: Auto removing remaining dependencies..." + $SUDO apt-get -y autoremove &> /dev/null & spinner $!; printf "done!\n"; + printf "::: Auto cleaning remaining dependencies..." + $SUDO apt-get -y autoclean &> /dev/null & spinner $!; printf "done!\n"; # Call removeNoPurge to remove PiHole specific files removeNoPurge @@ -124,14 +124,14 @@ function removeNoPurge { printf "::: Finished removing PiHole from your system. Sorry to see you go!\n" printf "::: Reach out to us at https://github.com/pi-hole/pi-hole/issues if you need help\n" printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L install.pi-hole.net | bash\n:::\n::: at any time!\n:::\n" - printf "::: PLEASE RESET YOUR DNS ON YOUR ROUTER/CLIENTS TO RESTORE INTERNET CONNECTIVITY!/n" + printf "::: PLEASE RESET YOUR DNS ON YOUR ROUTER/CLIENTS TO RESTORE INTERNET CONNECTIVITY!\n" } ######### SCRIPT ########### echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system." echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" while true; do - read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]" yn + read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]: " yn case $yn in [Yy]* ) removeAndPurge; break;; From 138aeaf8c746714dfb8d5202d8404c0ba64c1649 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 16:25:12 -0500 Subject: [PATCH 28/38] Added uninstall.sh and updateDashboard.sh to be removed on uninstall from u/l/b --- automated install/uninstall.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index ef82fa07..941232ca 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -114,6 +114,8 @@ function removeNoPurge { $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null $SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null $SUDO rm /usr/local/bin/piholeDebug.sh &> /dev/null + $SUDO rm /usr/local/bin/updateDashboard.sh &> /dev/null + $SUDO rm /usr/local/bin/uninstall.sh &> /dev/null $SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null $SUDO rm -rf /var/log/*pihole* &> /dev/null $SUDO rm -rf /etc/pihole/ &> /dev/null From 660e71f0320e61f4d1d3458d01bfbd627412e456 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 16:32:42 -0500 Subject: [PATCH 29/38] Added blacklist.sh to be removed on uninstall from u/l/b --- automated install/uninstall.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 941232ca..cef36dd6 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -112,6 +112,7 @@ function removeNoPurge { $SUDO rm /usr/local/bin/gravity.sh &> /dev/null $SUDO rm /usr/local/bin/chronometer.sh &> /dev/null $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null + $SUDO rm /usr/local/bin/blacklist.sh &> /dev/null $SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null $SUDO rm /usr/local/bin/piholeDebug.sh &> /dev/null $SUDO rm /usr/local/bin/updateDashboard.sh &> /dev/null From 32dd594f06ecb3ca24a7881eeb8e890bcafedf9c Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 17:08:19 -0500 Subject: [PATCH 30/38] Check if lighttpd has been uninstalled before removing conf files If is still installed, then restore the original lighttpd.conf file. --- automated install/uninstall.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index cef36dd6..786e8cea 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -107,8 +107,13 @@ function removeNoPurge { fi echo "::: Removing config files and scripts..." - $SUDO rm -rf /etc/lighttpd/ &> /dev/null - $SUDO rm /var/log/pihole.log &> /dev/null + if [ ! "$(dpkg-query -W --showformat='${Status}\n' lighttpd 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then + $SUDO rm -rf /etc/lighttpd/ &> /dev/null + else + if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then + $SUDO mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf + fi + fi $SUDO rm /usr/local/bin/gravity.sh &> /dev/null $SUDO rm /usr/local/bin/chronometer.sh &> /dev/null $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null From 86dd4dd7849e3d7af7a38fd44e1058814076bc65 Mon Sep 17 00:00:00 2001 From: nate Date: Mon, 28 Mar 2016 18:45:55 -0500 Subject: [PATCH 31/38] New spinner for gravity.sh Spinner in gravity.sh now matches basic-install.sh and uninstall.sh --- gravity.sh | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/gravity.sh b/gravity.sh index 3434ac9c..ed94448b 100755 --- a/gravity.sh +++ b/gravity.sh @@ -75,18 +75,19 @@ if [[ -r $piholeDir/pihole.conf ]];then fi -spinner(){ - local pid=$1 - - spin='-\|/' - i=0 - while $SUDO kill -0 "$pid" 2>/dev/null - do - i=$(( (i+1) %4 )) - printf "\b%s" "${spin:$i:1}" - sleep .1 - done - printf "\b" +spinner() +{ + local pid=$1 + local delay=0.50 + local spinstr='|/-\' + while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do + local temp=${spinstr#?} + printf " [%c] " "$spinstr" + local spinstr=$temp${spinstr%"$temp"} + sleep $delay + printf "\b\b\b\b\b\b" + done + printf " \b\b\b\b" } ########################### From ec4d2d65a656e0bf479a99919cb740a8fa98bb27 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 30 Mar 2016 19:49:39 -0500 Subject: [PATCH 32/38] PromoFaux request: Detailed adlists.list output Now tells user (and logs to pihole_Debug.log) that the adlists.default file is in use --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d2c8e245..145a602c 100644 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -258,8 +258,8 @@ then cat "$ADLISTSFILE" >> $DEBUG_LOG echo >> $DEBUG_LOG else - echo "No adlists.list file found!" >> $DEBUG_LOG - printf ":::\tNo adlists.list file found!\n" + echo "No adlists.list file found... using adlists.default!" >> $DEBUG_LOG + printf ":::\tNo adlists.list file found... using adlists.default!\n" fi From 5f7c11f4959e1ca4dca1c0111d4401600522a264 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 30 Mar 2016 19:51:09 -0500 Subject: [PATCH 33/38] Sudo added to ifconfig to ensure it runs if debug not run as root --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 145a602c..e9d95234 100644 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -118,7 +118,7 @@ function testNslookup { ### Check Pi internet connections ### # Log the IP addresses of this Pi -IPADDR=$(ifconfig | perl -nle 's/dr:(\S+)/print $1/e') +IPADDR=$($SUDO ifconfig | perl -nle 's/dr:(\S+)/print $1/e') echo "::: Writing local IPs to debug log" echo "IP Addresses of this Pi:" >> $DEBUG_LOG echo "$IPADDR" >> $DEBUG_LOG From 45f24c8a85edf0162530e785e9b0a2bfea3318a4 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 30 Mar 2016 19:56:11 -0500 Subject: [PATCH 34/38] Readded `cat`s that were originally considered UUOC --- gravity.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 0e13cb95..ddc177a0 100755 --- a/gravity.sh +++ b/gravity.sh @@ -222,7 +222,7 @@ function gravity_Schwarzchild() { truncate -s 0 $piholeDir/$matterandlight & spinner $! for i in "${activeDomains[@]}" do - "$i" |tr -d '\r' >> $piholeDir/$matterandlight + cat "$i" | tr -d '\r' >> $piholeDir/$matterandlight done echo " done!" @@ -282,12 +282,12 @@ function gravity_hostFormat() { if [[ -n $piholeIPv6 ]];then #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc - $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc + cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc else # Otherwise, just create gravity.list as normal using IPv4 #Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain! echo -e "$piholeIP Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc - $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc + cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it cp $piholeDir/$accretionDisc $adList From 2625d9f7fe52fce75a19ba18964e93c99d6a9ea9 Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 30 Mar 2016 20:09:19 -0500 Subject: [PATCH 35/38] Made piholeDebug.sh +x --- advanced/Scripts/piholeDebug.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 advanced/Scripts/piholeDebug.sh diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh old mode 100644 new mode 100755 From 4b0a7c22524e0a7b9af1ed92e0a90c4f21f7179b Mon Sep 17 00:00:00 2001 From: nate Date: Wed, 30 Mar 2016 20:23:24 -0500 Subject: [PATCH 36/38] Added 01-pihole.conf to be removed on uninstall regardless of removing dnsmasq --- automated install/uninstall.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 786e8cea..44c40791 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -114,6 +114,7 @@ function removeNoPurge { $SUDO mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf fi fi + $SUDO rm /usr/local/bin/gravity.sh &> /dev/null $SUDO rm /usr/local/bin/chronometer.sh &> /dev/null $SUDO rm /usr/local/bin/whitelist.sh &> /dev/null @@ -123,6 +124,7 @@ function removeNoPurge { $SUDO rm /usr/local/bin/updateDashboard.sh &> /dev/null $SUDO rm /usr/local/bin/uninstall.sh &> /dev/null $SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null + $SUDO rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null $SUDO rm -rf /var/log/*pihole* &> /dev/null $SUDO rm -rf /etc/pihole/ &> /dev/null $SUDO rm -rf /etc/.pihole/ &> /dev/null From 7b8fa3b922022af237c28cd82040ccd68de9b4d8 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 1 Apr 2016 01:11:59 -0500 Subject: [PATCH 37/38] Permissions changed for /etc/pihole and cleaned up some output --- advanced/pihole.cron | 2 +- gravity.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index 83b431a4..9d390143 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -10,7 +10,7 @@ # (at your option) any later version. # Pi-hole: Update the ad sources once a week on Sunday at 01:59 -# Download any updates from the ad lists +# Download any updates from the adlists 59 1 * * 7 root /usr/local/bin/gravity.sh # Pi-hole: Update the Web interface shortly after gravity runs diff --git a/gravity.sh b/gravity.sh index ddc177a0..e541184f 100755 --- a/gravity.sh +++ b/gravity.sh @@ -130,8 +130,8 @@ function gravity_collapse() { # Will update later, needed for existing installs, new installs should # create this directory as non-root $SUDO chmod 777 $piholeDir - find "$piholeDir" -type f -exec $SUDO chmod 666 {} \; & spinner $! - echo "." + $SUDO chown root:root $piholeDir + echo "..." else echo -n "::: Creating pihole directory..." mkdir $piholeDir & spinner $! @@ -246,7 +246,7 @@ function gravity_Whitelist() { echo ":::" # Prevent our sources from being pulled into the hole plural=; [[ "${sources[@]}" != "1" ]] && plural=s - echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..." + echo -n "::: Adding ${#sources[@]} adlist source${plural} to the whitelist..." urls=() for url in "${sources[@]}" From cf01b5a00245e8cedd0fd702ac02dd665a77b070 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 1 Apr 2016 12:17:05 -0500 Subject: [PATCH 38/38] Readded `cat` calls to fix permission issue --- advanced/Scripts/blacklist.sh | 2 +- advanced/Scripts/whitelist.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index 1780b8ec..75bdcd19 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -115,7 +115,7 @@ function ModifyHostFile(){ if $addmode; then #add domains to the hosts file if [[ -r $blacklist ]];then - numberOf=$($blacklist | sed '/^\s*$/d' | wc -l) + numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 5d732ddc..1479c62a 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -120,7 +120,7 @@ function ModifyHostFile(){ #remove domains in from hosts file if [[ -r $whitelist ]];then # Remove whitelist entries - numberOf=$($whitelist | sed '/^\s*$/d' | wc -l) + numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."