From 6daf80ef56698e917b188967e075a4873eca4bb0 Mon Sep 17 00:00:00 2001 From: jacobsalmela Date: Fri, 18 Mar 2016 18:01:51 -0500 Subject: [PATCH 01/14] add update mechanism This is some nice code found on stack overflow that I have been using for a while that seems very reliable. I just commented out a few things since we really only want to check if it needs an update or if it is already up to date. --- advanced/Scripts/updatePihole | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 advanced/Scripts/updatePihole diff --git a/advanced/Scripts/updatePihole b/advanced/Scripts/updatePihole new file mode 100644 index 00000000..5a4f31f8 --- /dev/null +++ b/advanced/Scripts/updatePihole @@ -0,0 +1,31 @@ +#!/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 +# Checks if Pi-hole needs updating and then +# +# 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. + +# Taken from http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git + +# Move into the git directory +cd /etc/.pihole/ + +LOCAL=$(git rev-parse @) +REMOTE=$(git rev-parse @{u}) +BASE=$(git merge-base @ @{u}) + +if [[ $LOCAL = $REMOTE ]]; then + echo "Up-to-date" +elif [[ $LOCAL = $BASE ]]; then + echo "Updating Pi-hole..." + git pull +elif [[ $REMOTE = $BASE ]]; then + : # Need to push, so do nothing +else + : # Diverged, so do nothing +fi From 96bacc372a0dc5e8d25880e0b2a02c1c3553cba8 Mon Sep 17 00:00:00 2001 From: jacobsalmela Date: Fri, 18 Mar 2016 18:02:17 -0500 Subject: [PATCH 02/14] cron to update pi-hole This checks once a week if core Pi-hole needs updating. --- advanced/pihole.cron | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index 83b431a4..5e1fb271 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -9,6 +9,10 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Pi-hole: Check if Pi-hole needs to be updated. Check once a week on Monday at 01:59 +# New releases often come out on Sunday, so checking the next day should be effective. +59 1 * * 7 root /usr/local/bin/updatePihole + # Pi-hole: Update the ad sources once a week on Sunday at 01:59 # Download any updates from the ad lists 59 1 * * 7 root /usr/local/bin/gravity.sh From 0e59cf0fd15bdc959476a335ed0fee3bad82ab66 Mon Sep 17 00:00:00 2001 From: jacobsalmela Date: Fri, 18 Mar 2016 20:11:34 -0500 Subject: [PATCH 03/14] run at a different time than gravity update --- advanced/pihole.cron | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index 5e1fb271..d1c2d2cd 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -9,9 +9,9 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Pi-hole: Check if Pi-hole needs to be updated. Check once a week on Monday at 01:59 +# Pi-hole: Check if Pi-hole needs to be updated. Check once a week on Monday at 23:58 # New releases often come out on Sunday, so checking the next day should be effective. -59 1 * * 7 root /usr/local/bin/updatePihole +23 58 * * 1 root /usr/local/bin/updatePihole # Pi-hole: Update the ad sources once a week on Sunday at 01:59 # Download any updates from the ad lists From fbc400c67ef81149959e7cfafbf8d2bb01b888a4 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:09:12 +0100 Subject: [PATCH 04/14] rename to updatePihole.sh --- advanced/Scripts/updatePihole.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 advanced/Scripts/updatePihole.sh diff --git a/advanced/Scripts/updatePihole.sh b/advanced/Scripts/updatePihole.sh new file mode 100644 index 00000000..5a4f31f8 --- /dev/null +++ b/advanced/Scripts/updatePihole.sh @@ -0,0 +1,31 @@ +#!/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 +# Checks if Pi-hole needs updating and then +# +# 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. + +# Taken from http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git + +# Move into the git directory +cd /etc/.pihole/ + +LOCAL=$(git rev-parse @) +REMOTE=$(git rev-parse @{u}) +BASE=$(git merge-base @ @{u}) + +if [[ $LOCAL = $REMOTE ]]; then + echo "Up-to-date" +elif [[ $LOCAL = $BASE ]]; then + echo "Updating Pi-hole..." + git pull +elif [[ $REMOTE = $BASE ]]; then + : # Need to push, so do nothing +else + : # Diverged, so do nothing +fi From cec727be9da1ea7cd4d9a7ae8cb6a106018a5ee9 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:13:13 +0100 Subject: [PATCH 05/14] add pihole update script to 'pihole' command --- pihole | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pihole b/pihole index 5ff26246..b99f1697 100755 --- a/pihole +++ b/pihole @@ -57,6 +57,11 @@ function updateGravityFunc { exit 1 } +function updatePiholeFunc { + $SUDO /opt/pihole/updatePihole.sh + exit 1 +} + function setupLCDFunction { $SUDO /opt/pihole/setupLCD.sh exit 1 @@ -86,6 +91,7 @@ function helpFunc { echo "::: -d, debug Start a debugging session if having trouble" echo "::: -f, flush Flush the pihole.log file" echo "::: -u, updateDashboard Update the web dashboard manually" + echo "::: -up, updatePihole Update the Pi-hole core files manually" echo "::: -g, updateGravity Update the list of ad-serving domains" echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it" echo "::: -c, chronometer Calculates stats and displays to an LCD" @@ -105,6 +111,7 @@ case "$1" in "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-u" | "updateDashboard" ) updateDashboardFunc;; +"-up" | "updatePihole" ) updatePiholeFunc;; "-g" | "updateGravity" ) updateGravityFunc;; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; From 253dfdf0842fbd171899a443e75953a19567039a Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:15:18 +0100 Subject: [PATCH 06/14] add updatePihole.sh to install script --- automated install/basic-install.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 139a7a4b..9d197feb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -471,16 +471,17 @@ installScripts() { $SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.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/advanced/Scripts/updatePihole.sh /opt/pihole/updateDashboard.sh $SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh $SUDO cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh - $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD}.sh + $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard, updatePihole,uninstall,setupLCD, piholeDebug}.sh $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole $SUDO chmod 755 /usr/local/bin/pihole $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole #Tidy up /usr/local/bin directory if installing over previous install. - oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) + oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard updatePihole uninstall setupLCD piholeDebug) for i in "${oldFiles[@]}"; do if [ -f "/usr/local/bin/$i.sh" ]; then $SUDO rm /usr/local/bin/"$i".sh From 2ab6746d538037b094891fe68982f891db7ef346 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:16:38 +0100 Subject: [PATCH 07/14] remove `updatepihole` --- advanced/Scripts/updatePihole | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 advanced/Scripts/updatePihole diff --git a/advanced/Scripts/updatePihole b/advanced/Scripts/updatePihole deleted file mode 100644 index 5a4f31f8..00000000 --- a/advanced/Scripts/updatePihole +++ /dev/null @@ -1,31 +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 -# Checks if Pi-hole needs updating and then -# -# 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. - -# Taken from http://stackoverflow.com/questions/3258243/check-if-pull-needed-in-git - -# Move into the git directory -cd /etc/.pihole/ - -LOCAL=$(git rev-parse @) -REMOTE=$(git rev-parse @{u}) -BASE=$(git merge-base @ @{u}) - -if [[ $LOCAL = $REMOTE ]]; then - echo "Up-to-date" -elif [[ $LOCAL = $BASE ]]; then - echo "Updating Pi-hole..." - git pull -elif [[ $REMOTE = $BASE ]]; then - : # Need to push, so do nothing -else - : # Diverged, so do nothing -fi From 06f1aea3190c1a420459451e66fe6a278e256956 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:17:37 +0100 Subject: [PATCH 08/14] disable cron job (for now) to stop auto updates --- advanced/pihole.cron | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole.cron b/advanced/pihole.cron index fc648091..159f3b07 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -11,7 +11,7 @@ # Pi-hole: Check if Pi-hole needs to be updated. Check once a week on Monday at 23:58 # New releases often come out on Sunday, so checking the next day should be effective. -23 58 * * 1 root /usr/local/bin/updatePihole +#23 58 * * 1 root /usr/local/bin/updatePihole # Pi-hole: Update the ad sources once a week on Sunday at 01:59 # Download any updates from the adlists From e4ce5e3601eeb73b1027890055f6850b1aba1a38 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:31:15 +0100 Subject: [PATCH 09/14] add secondary update script. This is where the files will be distributed from once repo is up to date --- advanced/Scripts/updatePiholeSecondary.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 advanced/Scripts/updatePiholeSecondary.sh diff --git a/advanced/Scripts/updatePiholeSecondary.sh b/advanced/Scripts/updatePiholeSecondary.sh new file mode 100644 index 00000000..e69de29b From a04b7c4e99b1147a88e39502350e2910ed960240 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:42:34 +0100 Subject: [PATCH 10/14] Fix typo. Add secondary update script --- automated install/basic-install.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9d197feb..2c5161e5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -471,17 +471,18 @@ installScripts() { $SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.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/advanced/Scripts/updatePihole.sh /opt/pihole/updateDashboard.sh + $SUDO cp /etc/.pihole/advanced/Scripts/updatePihole.sh /opt/pihole/updatePihole.sh + $SUDO cp /etc/.pihole/advanced/Scripts/updatePiholeSecondary.sh /opt/pihole/updatePiholeSecondary.sh $SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh $SUDO cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh - $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard, updatePihole,uninstall,setupLCD, piholeDebug}.sh + $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,updatePihole,updatePiholeSecondary,uninstall,setupLCD, piholeDebug}.sh $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole $SUDO chmod 755 /usr/local/bin/pihole $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole #Tidy up /usr/local/bin directory if installing over previous install. - oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard updatePihole uninstall setupLCD piholeDebug) + oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard updatePihole updatePiholeSecondary uninstall setupLCD piholeDebug) for i in "${oldFiles[@]}"; do if [ -f "/usr/local/bin/$i.sh" ]; then $SUDO rm /usr/local/bin/"$i".sh From 5ab54012d59af99c84bd4908e5189e2832a9adee Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:43:22 +0100 Subject: [PATCH 11/14] Call secondary update script after pull --- advanced/Scripts/updatePihole.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/updatePihole.sh b/advanced/Scripts/updatePihole.sh index 5a4f31f8..0850764d 100644 --- a/advanced/Scripts/updatePihole.sh +++ b/advanced/Scripts/updatePihole.sh @@ -24,6 +24,7 @@ if [[ $LOCAL = $REMOTE ]]; then elif [[ $LOCAL = $BASE ]]; then echo "Updating Pi-hole..." git pull + /opt/pihole/updatePiholeSecondary.sh elif [[ $REMOTE = $BASE ]]; then : # Need to push, so do nothing else From f671eef3f089da4d061f1722d20321fbb758ad97 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 8 Apr 2016 23:43:31 +0100 Subject: [PATCH 12/14] ground work on secondary update script --- advanced/Scripts/updatePiholeSecondary.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/advanced/Scripts/updatePiholeSecondary.sh b/advanced/Scripts/updatePiholeSecondary.sh index e69de29b..88870e77 100644 --- a/advanced/Scripts/updatePiholeSecondary.sh +++ b/advanced/Scripts/updatePiholeSecondary.sh @@ -0,0 +1,20 @@ +#!/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 +# Checks if Pi-hole needs updating and then +# +# 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. + +function updateDependencies(){ + newDependencies=() + echo "::: Installing any new dependencies..." + for i in "${newDependencies[@]}"; do + echo "checking for $i" + done + } +} \ No newline at end of file From 5b0e73c9f30e05ee63f30f1ccf5549792b1f0af6 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 28 Apr 2016 21:32:24 +0100 Subject: [PATCH 13/14] Flesh out updateDependencies. Add in root check. --- advanced/Scripts/updatePiholeSecondary.sh | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/updatePiholeSecondary.sh b/advanced/Scripts/updatePiholeSecondary.sh index 88870e77..6989fea4 100644 --- a/advanced/Scripts/updatePiholeSecondary.sh +++ b/advanced/Scripts/updatePiholeSecondary.sh @@ -10,11 +10,44 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Must be root to use this tool +if [[ ! $EUID -eq 0 ]];then + #echo "::: You are root." +#else + #echo "::: Sudo will be used for this tool." + # Check if it is actually installed + # If it isn't, exit because the pihole cannot be invoked without privileges. + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi +fi + function updateDependencies(){ + #Add any new dependencies to the below array` newDependencies=() echo "::: Installing any new dependencies..." for i in "${newDependencies[@]}"; do echo "checking for $i" + 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 $! + echo " done!" + else + echo " already installed!" + fi done } -} \ No newline at end of file +} + +#uncomment the below if adding new dependencies (don't forget to update the install script!) +#updateDependencies + + + +#TODO: +# - Distribute files` +# - Run pihole -g +# - add root check, maybe? Do we need to? Probably a good idea. From 67834062bc2c6f05177f49609bbd85aeddf8b4a9 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Thu, 28 Apr 2016 21:40:25 +0100 Subject: [PATCH 14/14] Copy some scripts from basic_install.sh. Add todo list comments. --- advanced/Scripts/updatePiholeSecondary.sh | 54 ++++++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/updatePiholeSecondary.sh b/advanced/Scripts/updatePiholeSecondary.sh index 6989fea4..34cef677 100644 --- a/advanced/Scripts/updatePiholeSecondary.sh +++ b/advanced/Scripts/updatePiholeSecondary.sh @@ -42,12 +42,62 @@ function updateDependencies(){ } } +stopServices() { + # Stop dnsmasq and lighttpd + echo ":::" + echo -n "::: Stopping services..." + $SUDO service lighttpd stop + echo " done." +} + +installScripts() { + # Install the scripts from /etc/.pihole to their various locations + echo ":::" + echo -n "::: Updating scripts in /opt/pihole..." + + $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/blacklist.sh + $SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.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/advanced/Scripts/updatePihole.sh /opt/pihole/updatePihole.sh + $SUDO cp /etc/.pihole/advanced/Scripts/updatePiholeSecondary.sh /opt/pihole/updatePiholeSecondary.sh + $SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh + $SUDO cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh + $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,updatePihole,updatePiholeSecondary,uninstall,setupLCD, piholeDebug}.sh + $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole + $SUDO chmod 755 /usr/local/bin/pihole + $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole + . /etc/bash_completion.d/pihole + + #Tidy up /usr/local/bin directory if updating an old installation (can probably be removed at some point) + oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard updatePihole updatePiholeSecondary uninstall setupLCD piholeDebug) + for i in "${oldFiles[@]}"; do + if [ -f "/usr/local/bin/$i.sh" ]; then + $SUDO rm /usr/local/bin/"$i".sh + fi + done + + echo " done." +} + + +######################## +# SCRIPT STARTS HERE! # +####################### + #uncomment the below if adding new dependencies (don't forget to update the install script!) #updateDependencies - - +stopServices +installScripts #TODO: # - Distribute files` # - Run pihole -g # - add root check, maybe? Do we need to? Probably a good idea. +# - update install script to populate a config file with: +# -IPv4 +# -IPv6 +# -UpstreamDNS servers