From a4ba8d4b8fd0e44e11deeecf33267c82c3d8735e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:16:24 +0100 Subject: [PATCH 01/25] Prevent double disabling/enabling by checking BLOCKING_ENABLED value in setupVars.conf Signed-off-by: DL6ER --- pihole | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pihole b/pihole index fff3417d..84a5623f 100755 --- a/pihole +++ b/pihole @@ -144,6 +144,10 @@ Time: elif [[ "${1}" == "0" ]]; then # Disable Pi-hole + if grep -cq "BLOCKING_ENABLED=false" "${setupVars}"; then + echo -e " ${INFO} Blocking already disabled, nothing to do" + exit 0 + fi if [[ -e "${gravitylist}" ]]; then mv "${gravitylist}" "${gravitylist}.bck" echo "" > "${gravitylist}" @@ -193,6 +197,10 @@ Time: fi else # Enable Pi-hole + if grep -cq "BLOCKING_ENABLED=true" "${setupVars}"; then + echo -e " ${INFO} Blocking already enabled, nothing to do" + exit 0 + fi echo -e " ${INFO} Enabling blocking" local str="Pi-hole Enabled" From d996e9c9eee0f075ffa844044d86a62932193374 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:28:09 +0100 Subject: [PATCH 02/25] Fix inconsistent handling of binary variable. get_binary_variable() stores the result into a global variable we pass later on as argument to FTLinstall() and define a local variable with the same name. This is fixed by only using the globa variable in all places not. This is still not a very elegant solution but it is also not subject of the current PR. Signed-off-by: DL6ER --- automated install/basic-install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 990b1f34..f91363c9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -115,6 +115,9 @@ else OVER="\\r\\033[K" fi +# Define global binary variable +binary="tbd" + # A simple function that just echoes out our logo in ASCII format # This lets users know that it is a Pi-hole, LLC product show_ascii_berry() { @@ -2130,7 +2133,6 @@ clone_or_update_repos() { # Download FTL binary to random temp directory and install FTL binary FTLinstall() { # Local, named variables - local binary="${1}" local latesttag local str="Downloading and Installing FTL" printf " %b %s..." "${INFO}" "${str}" @@ -2377,7 +2379,7 @@ FTLdetect() { printf "\\n %b FTL Checks...\\n\\n" "${INFO}" if FTLcheckUpdate ; then - FTLinstall "${binary}" || return 1 + FTLinstall || return 1 fi } From 3cdd6204c562254b9368ce5b3153fe99bdf788a2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:31:02 +0100 Subject: [PATCH 03/25] Move dnsmasq disabling and config file rewriting into a dedicated subroutine Signed-off-by: DL6ER --- automated install/basic-install.sh | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f91363c9..092dafef 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2184,25 +2184,6 @@ FTLinstall() { popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; } # Install the FTL service printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" - # dnsmasq can now be stopped and disabled if it exists - if which dnsmasq &> /dev/null; then - if check_service_active "dnsmasq";then - printf " %b FTL can now resolve DNS Queries without dnsmasq running separately\\n" "${INFO}" - stop_service dnsmasq - disable_service dnsmasq - fi - fi - - # Backup existing /etc/dnsmasq.conf if present and ensure that - # /etc/dnsmasq.conf contains only "conf-dir=/etc/dnsmasq.d" - local conffile="/etc/dnsmasq.conf" - if [[ -f "${conffile}" ]]; then - printf " %b Backing up %s to %s.old\\n" "${INFO}" "${conffile}" "${conffile}" - mv "${conffile}" "${conffile}.old" - fi - # Create /etc/dnsmasq.conf - echo "conf-dir=/etc/dnsmasq.d" > "${conffile}" - return 0 # Otherwise, else @@ -2222,6 +2203,27 @@ FTLinstall() { fi } +disable_dnsmasq() { + # dnsmasq can now be stopped and disabled if it exists + if which dnsmasq &> /dev/null; then + if check_service_active "dnsmasq";then + printf " %b FTL can now resolve DNS Queries without dnsmasq running separately\\n" "${INFO}" + stop_service dnsmasq + disable_service dnsmasq + fi + fi + + # Backup existing /etc/dnsmasq.conf if present and ensure that + # /etc/dnsmasq.conf contains only "conf-dir=/etc/dnsmasq.d" + local conffile="/etc/dnsmasq.conf" + if [[ -f "${conffile}" ]]; then + printf " %b Backing up %s to %s.old\\n" "${INFO}" "${conffile}" "${conffile}" + mv "${conffile}" "${conffile}.old" + fi + # Create /etc/dnsmasq.conf + echo "conf-dir=/etc/dnsmasq.d" > "${conffile}" +} + get_binary_name() { # This gives the machine architecture which may be different from the OS architecture... local machine From de6dc90575df32800155fb2ecd3c075503388bb0 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:31:53 +0100 Subject: [PATCH 04/25] Don't diable pihole-FTL before calling install. root should be able to overwrite the binary in any case. The binary has already been downloaded and hash-verified here so we don't expect any errors in this binary. Signed-off-by: DL6ER --- automated install/basic-install.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 092dafef..03214f1a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2176,8 +2176,6 @@ FTLinstall() { # If we downloaded binary file (as opposed to text), if sha1sum --status --quiet -c "${binary}".sha1; then printf "transferred... " - # Stop FTL - stop_service pihole-FTL &> /dev/null # Install the new version with the correct permissions install -T -m 0755 "${binary}" /usr/bin/pihole-FTL # Move back into the original directory the user was in From d90d7b69273997be0285e79417b36a02f99f1485 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:36:27 +0100 Subject: [PATCH 05/25] Call FTL download/installation early on in the installation process. Signed-off-by: DL6ER --- automated install/basic-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 03214f1a..83abc49e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1909,8 +1909,9 @@ installPihole() { installCron # Install the logrotate file installLogrotate - # Check if FTL is installed - FTLdetect || printf " %b FTL Engine not installed\\n" "${CROSS}" + # Check if dnsmasq is present. If so, disable it and back up any possible + # config file + disable_dnsmasq # Configure the firewall if [[ "${useUpdateVars}" == false ]]; then configureFirewall @@ -2539,6 +2540,8 @@ main() { else LIGHTTPD_ENABLED=false fi + # Check if FTL is installed - do this early on as FTL is a hard dependency for Pi-hole + FTLdetect || printf " %b FTL Engine not installed\\n" "${CROSS}" # Install and log everything to a file installPihole | tee -a /proc/$$/fd/3 From cc657c0c263485c6c16e476db29236027ce0f598 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:37:03 +0100 Subject: [PATCH 06/25] Rename subroutine start_service() to restart_service() because this is what it does Signed-off-by: DL6ER --- automated install/basic-install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 83abc49e..d823e923 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1437,7 +1437,7 @@ stop_service() { } # Start/Restart service passed in as argument -start_service() { +restart_service() { # Local, named variables local str="Starting ${1} service" printf " %b %s..." "${INFO}" "${str}" @@ -2572,7 +2572,7 @@ main() { if [[ "${INSTALL_WEB_SERVER}" == true ]]; then if [[ "${LIGHTTPD_ENABLED}" == true ]]; then - start_service lighttpd + restart_service lighttpd enable_service lighttpd else printf " %b Lighttpd is disabled, skipping service restart\\n" "${INFO}" @@ -2587,7 +2587,7 @@ main() { # Fixes a problem reported on Ubuntu 18.04 where trying to start # the service before enabling causes installer to exit enable_service pihole-FTL - start_service pihole-FTL + restart_service pihole-FTL # Download and compile the aggregated block list runGravity From d26f2dcb2c4e865a4e69c72e7e2c2db3778b1d40 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 24 Jan 2019 09:47:28 +0100 Subject: [PATCH 07/25] Use global binary variable in tests for automated install Signed-off-by: DL6ER --- test/test_automated_install.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index a2593d83..ce0abfd2 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -484,7 +484,8 @@ def test_FTL_download_aarch64_no_errors(Pihole): # mock uname to return generic platform download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLinstall pihole-FTL-aarch64-linux-gnu + binary="pihole-FTL-aarch64-linux-gnu" + FTLinstall ''') expected_stdout = tick_box + ' Downloading and Installing FTL' assert expected_stdout in download_binary.stdout @@ -498,7 +499,8 @@ def test_FTL_download_unknown_fails_no_errors(Pihole): # mock uname to return generic platform download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLinstall pihole-FTL-mips + binary="pihole-FTL-mips" + FTLinstall ''') expected_stdout = cross_box + ' Downloading and Installing FTL' assert expected_stdout in download_binary.stdout From 7479485d4518e0fda8ea46d255e504d193013722 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 31 Jan 2019 20:00:26 +0100 Subject: [PATCH 08/25] Add test for the case the binary variable is unset (defaults to "tbd" in this case) Signed-off-by: DL6ER --- test/test_automated_install.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index ce0abfd2..853048d1 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -481,7 +481,6 @@ def test_FTL_download_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' - # mock uname to return generic platform download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh binary="pihole-FTL-aarch64-linux-gnu" @@ -496,7 +495,6 @@ def test_FTL_download_unknown_fails_no_errors(Pihole): ''' confirms unknown binary is not downloaded for FTL engine ''' - # mock uname to return generic platform download_binary = Pihole.run(''' source /opt/pihole/basic-install.sh binary="pihole-FTL-mips" @@ -510,6 +508,22 @@ def test_FTL_download_unknown_fails_no_errors(Pihole): assert error2 in download_binary.stdout +def test_FTL_download_binary_unset_no_errors(Pihole): + ''' + confirms unset binary variable does not download FTL engine + ''' + download_binary = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLinstall + ''') + expected_stdout = cross_box + ' Downloading and Installing FTL' + assert expected_stdout in download_binary.stdout + error1 = 'Error: URL https://github.com/pi-hole/FTL/releases/download/' + assert error1 in download_binary.stdout + error2 = 'not found' + assert error2 in download_binary.stdout + + def test_FTL_binary_installed_and_responsive_no_errors(Pihole): ''' confirms FTL binary is copied and functional in installed location From 4948862dced5a0ae9f9dba13f119277c533815db Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 31 Jan 2019 20:10:52 +0100 Subject: [PATCH 09/25] Fail hard if FTL binary could not be installed Signed-off-by: DL6ER --- automated install/basic-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d823e923..ac61783c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2541,7 +2541,10 @@ main() { LIGHTTPD_ENABLED=false fi # Check if FTL is installed - do this early on as FTL is a hard dependency for Pi-hole - FTLdetect || printf " %b FTL Engine not installed\\n" "${CROSS}" + if ! FTLdetect; then + printf " %b FTL Engine not installed\\n" "${CROSS}" + exit 1 + fi # Install and log everything to a file installPihole | tee -a /proc/$$/fd/3 From 9c0de0f73128da47378c18958bd04d37793be853 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 1 Feb 2019 17:39:12 +0100 Subject: [PATCH 10/25] Try to stop pihole-FTL before and (re)start pihole-FTL after the install command Signed-off-by: DL6ER --- automated install/basic-install.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ac61783c..2022a7bf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2177,11 +2177,24 @@ FTLinstall() { # If we downloaded binary file (as opposed to text), if sha1sum --status --quiet -c "${binary}".sha1; then printf "transferred... " + + # Stop pihole-FTL service if available + # Allow failing without tripping set -e as the + # service might not be available (e.g. on first install) + service pihole-FTL stop > /dev/null 2>&1 || true + # Install the new version with the correct permissions install -T -m 0755 "${binary}" /usr/bin/pihole-FTL + + # Start pihole-FTL service if available + # Allow failing without tripping set -e as the + # service might not be available (e.g. on first install) + service pihole-FTL restart > /dev/null 2>&1 || true + # Move back into the original directory the user was in popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; } - # Install the FTL service + + # Installed the FTL service printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" return 0 # Otherwise, From e8dabc71af52238726da2a0a9454a09dca5e66bb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 1 Feb 2019 17:54:21 +0100 Subject: [PATCH 11/25] Don't try to start pihole-FTL after it has been installed. This will be done a few moments later when gravity is invoked. Signed-off-by: DL6ER --- automated install/basic-install.sh | 5 ----- 1 file changed, 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2022a7bf..865750ad 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2186,11 +2186,6 @@ FTLinstall() { # Install the new version with the correct permissions install -T -m 0755 "${binary}" /usr/bin/pihole-FTL - # Start pihole-FTL service if available - # Allow failing without tripping set -e as the - # service might not be available (e.g. on first install) - service pihole-FTL restart > /dev/null 2>&1 || true - # Move back into the original directory the user was in popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n"; return 1; } From ec79e86bee709cbbf94b677a5c515212081e70a6 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 1 Feb 2019 18:06:57 +0100 Subject: [PATCH 12/25] We should really use stop_service as it also includes some nice output Signed-off-by: DL6ER --- automated install/basic-install.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 865750ad..cf73864b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2179,9 +2179,7 @@ FTLinstall() { printf "transferred... " # Stop pihole-FTL service if available - # Allow failing without tripping set -e as the - # service might not be available (e.g. on first install) - service pihole-FTL stop > /dev/null 2>&1 || true + stop_service pihole-FTL &> /dev/null # Install the new version with the correct permissions install -T -m 0755 "${binary}" /usr/bin/pihole-FTL From ae654730c4a54d7b7c9a7734e010bff1fda97c1a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 2 Feb 2019 08:00:58 +0100 Subject: [PATCH 13/25] Update automated install/basic-install.sh Co-Authored-By: DL6ER --- 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 cf73864b..51fb2810 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1439,7 +1439,7 @@ stop_service() { # Start/Restart service passed in as argument restart_service() { # Local, named variables - local str="Starting ${1} service" + local str="Restarting ${1} service" printf " %b %s..." "${INFO}" "${str}" # If systemctl exists, if is_command systemctl ; then From 5c4ee237959f0fd475d56d053f8cc0ddf1c0962e Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 2 Feb 2019 10:19:44 -0800 Subject: [PATCH 14/25] Fix missed start_service -> restart_service call start_service was changed to restart_service. Signed-off-by: Mcat12 --- advanced/Scripts/piholeCheckout.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 977d1552..1bfe5e21 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -167,7 +167,7 @@ checkout() { echo " ${TICK} Branch ${2} exists" echo "${2}" > /etc/pihole/ftlbranch FTLinstall "${binary}" - start_service pihole-FTL + restart_service pihole-FTL enable_service pihole-FTL else echo " ${CROSS} Requested branch \"${2}\" is not available" From 26f2410fe6f75688e133a2f96538516e4e025f54 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 2 Feb 2019 10:37:12 -0800 Subject: [PATCH 15/25] Change /var/run/shm to /dev/shm The /var directory may not exist (does not exist on Fedora 29), and is simply a symlink to /dev/shm. Signed-off-by: Mcat12 --- 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 281425bf..c840ed04 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -76,7 +76,7 @@ WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" #BLOCK_PAGE_DIRECTORY="${HTML_DIRECTORY}/pihole" -SHM_DIRECTORY="/var/run/shm" +SHM_DIRECTORY="/dev/shm" # Files required by Pi-hole # https://discourse.pi-hole.net/t/what-files-does-pi-hole-use/1684 From 7a19d24058ef6ff88f9eedaa32de36f41c396497 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 3 Feb 2019 10:55:18 -0800 Subject: [PATCH 16/25] Remove user/group from dnsmasq config In the case that FTL is started under root, dnsmasq changes the user to pihole due to this setting. The shared memory is created before this switch, and may cause issues such as failing to delete or reallocate the shared memory. These config lines were necessary before dnsmasq became part of FTL, but now since dnsmasq runs under FTL, we can configure the user/group through FTL. Signed-off-by: Mcat12 --- advanced/01-pihole.conf | 3 --- 1 file changed, 3 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index af46e918..502293bf 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -22,9 +22,6 @@ addn-hosts=/etc/pihole/gravity.list addn-hosts=/etc/pihole/black.list addn-hosts=/etc/pihole/local.list -user=pihole -group=pihole - domain-needed localise-queries From dc91d4b1f90192fb71aa73e8af85c338bda2882e Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:06:57 +0000 Subject: [PATCH 17/25] basic_install: If a static interface is already set up we are done Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8666e70a..acf5b92d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -873,6 +873,13 @@ setStaticIPv4() { # Local, named variables local IFCFG_FILE local CONNECTION_NAME + + # If a static interface is already configured, we are done. + if [[ -r "/etc/sysconfig/network/ifcfg-${PIHOLE_INTERFACE}" ]]; then + if grep -q '^BOOTPROTO=.static.' "/etc/sysconfig/network/ifcfg-${PIHOLE_INTERFACE}"; then + return 0 + fi + fi # For the Debian family, if dhcpcd.conf exists, if [[ -f "/etc/dhcpcd.conf" ]]; then # configure networking via dhcpcd From d5bbb2b6404301b07aecac2f7a8c913223f5af8d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:17:53 +0000 Subject: [PATCH 18/25] basic_install: Use a varibale for the pihole dashboard dir Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index acf5b92d..87347541 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -62,6 +62,7 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi # This directory is where the Pi-hole scripts will be installed PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" +PI_HOLE_BLOCKPAGE_DIR="/var/www/html/pihole" useUpdateVars=false adlistFile="/etc/pihole/adlists.list" @@ -1387,7 +1388,7 @@ installConfigs() { # Make sure the external.conf file exists, as lighttpd v1.4.50 crashes without it touch /etc/lighttpd/external.conf # if there is a custom block page in the html/pihole directory, replace 404 handler in lighttpd config - if [[ -f "/var/www/html/pihole/custom.php" ]]; then + if [[ -f "${PI_HOLE_BLOCKPAGE_DIR}/custom.php" ]]; then sed -i 's/^\(server\.error-handler-404\s*=\s*\).*$/\1"pihole\/custom\.php"/' /etc/lighttpd/lighttpd.conf fi # Make the directories if they do not exist and set the owners @@ -1653,13 +1654,13 @@ installPiholeWeb() { local str="Creating directory for blocking page, and copying files" printf " %b %s..." "${INFO}" "${str}" # Install the directory - install -d /var/www/html/pihole + install -d ${PI_HOLE_BLOCKPAGE_DIR} # and the blockpage - install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ + install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* ${PI_HOLE_BLOCKPAGE_DIR}/ # Remove superseded file - if [[ -e "/var/www/html/pihole/index.js" ]]; then - rm "/var/www/html/pihole/index.js" + if [[ -e "${PI_HOLE_BLOCKPAGE_DIR}/index.js" ]]; then + rm "${PI_HOLE_BLOCKPAGE_DIR}/index.js" fi printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" From 838e1b19ecb6a58ba58a72acfd008810c8a7e07c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:23:23 +0000 Subject: [PATCH 19/25] basic_install: Set permissons for PI_HOLE_DASHBOARD_DIR Signed-off-by: Andreas Schneider --- 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 87347541..4e3e0636 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1654,7 +1654,7 @@ installPiholeWeb() { local str="Creating directory for blocking page, and copying files" printf " %b %s..." "${INFO}" "${str}" # Install the directory - install -d ${PI_HOLE_BLOCKPAGE_DIR} + install -d -m 0755 ${PI_HOLE_BLOCKPAGE_DIR} # and the blockpage install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* ${PI_HOLE_BLOCKPAGE_DIR}/ From f187b42a98b984f49d2df2ba20672f5f2497ceca Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:30:43 +0000 Subject: [PATCH 20/25] basic_install: Define webroot globally as a variable Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4e3e0636..5d0f6e23 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -52,9 +52,12 @@ lighttpdConfig=/etc/lighttpd/lighttpd.conf # This is a file used for the colorized output coltable=/opt/pihole/COL_TABLE +# Root of the web server +webroot="/var/www/html" + # We store several other directories and webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" -webInterfaceDir="/var/www/html/admin" +webInterfaceDir="${webroot}/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" PI_HOLE_LOCAL_REPO="/etc/.pihole" # These are the names of pi-holes files, stored in an array @@ -62,7 +65,7 @@ PI_HOLE_FILES=(chronometer list piholeDebug piholeLogFlush setupLCD update versi # This directory is where the Pi-hole scripts will be installed PI_HOLE_INSTALL_DIR="/opt/pihole" PI_HOLE_CONFIG_DIR="/etc/pihole" -PI_HOLE_BLOCKPAGE_DIR="/var/www/html/pihole" +PI_HOLE_BLOCKPAGE_DIR="${webroot}/pihole" useUpdateVars=false adlistFile="/etc/pihole/adlists.list" @@ -1668,9 +1671,9 @@ installPiholeWeb() { local str="Backing up index.lighttpd.html" printf " %b %s..." "${INFO}" "${str}" # If the default index file exists, - if [[ -f "/var/www/html/index.lighttpd.html" ]]; then + if [[ -f "${webroot}/index.lighttpd.html" ]]; then # back it up - mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig + mv ${webroot}/index.lighttpd.html ${webroot}/index.lighttpd.orig printf "%b %b %s\\n" "${OVER}" "${TICK}" "${str}" # Otherwise, else @@ -1880,15 +1883,15 @@ installPihole() { # If the user wants to install the Web interface, if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - if [[ ! -d "/var/www/html" ]]; then + if [[ ! -d "${webroot}" ]]; then # make the Web directory if necessary - mkdir -p /var/www/html + install -d -m 0755 ${webroot} fi if [[ "${INSTALL_WEB_SERVER}" == true ]]; then # Set the owner and permissions - chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - chmod 775 /var/www/html + chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} ${webroot} + chmod 0775 ${webroot} # Give pihole access to the Web server group usermod -a -G ${LIGHTTPD_GROUP} pihole # If the lighttpd command is executable, From 2f0e6a6dda2cbfc7719d5197aaf2721889633002 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:33:31 +0000 Subject: [PATCH 21/25] basic_install: Make sure the PI_HOLE_CONFIG_DIR exists Signed-off-by: Andreas Schneider --- automated install/basic-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5d0f6e23..bc8daa35 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1362,7 +1362,8 @@ installConfigs() { echo "${DNS_SERVERS}" > "${PI_HOLE_CONFIG_DIR}/dns-servers.conf" # Install empty file if it does not exist - if [[ ! -f "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then + if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then + install -d -m 0755 ${PI_HOLE_CONFIG_DIR} if ! install -o pihole -g pihole -m 664 /dev/null "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then printf " %bError: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 From 2f189cd0762daf725862e7d10a3c7cf2771fec6f Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 09:40:47 +0000 Subject: [PATCH 22/25] basic_install: There is no pihole group, remove it Only a user has been created beforehand. Only some distributions create a group with the same name based on their configuration. We cannot assume this is always the default. Signed-off-by: Andreas Schneider --- 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 bc8daa35..087e0b38 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1364,7 +1364,7 @@ installConfigs() { # Install empty file if it does not exist if [[ ! -r "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" ]]; then install -d -m 0755 ${PI_HOLE_CONFIG_DIR} - if ! install -o pihole -g pihole -m 664 /dev/null "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then + if ! install -o pihole -m 664 /dev/null "${PI_HOLE_CONFIG_DIR}/pihole-FTL.conf" &>/dev/null; then printf " %bError: Unable to initialize configuration file %s/pihole-FTL.conf\\n" "${COL_LIGHT_RED}" "${PI_HOLE_CONFIG_DIR}" return 1 fi From 5ca1bfc11c67d6492de6e7810299e9802d8814e0 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 8 Feb 2019 14:56:44 +0100 Subject: [PATCH 23/25] Delete /dev/shm/FTL-* files on (re)start of pihole-FTL Signed-off-by: DL6ER --- advanced/Templates/pihole-FTL.service | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index d19e2bd5..9eb183ed 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -33,6 +33,8 @@ start() { mkdir -p /var/run/pihole mkdir -p /var/log/pihole chown pihole:pihole /var/run/pihole /var/log/pihole + # Remove possible leftovers from previous pihole-FTL processes + rm -f /dev/shm/FTL-* 2> /dev/null rm /var/run/pihole/FTL.sock 2> /dev/null # Ensure that permissions are set so that pihole-FTL can edit all necessary files chown pihole:pihole /run/pihole-FTL.pid /run/pihole-FTL.port From 860ec1a7c4313412456d7858ac86f0305105f3a7 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 5 Feb 2019 13:45:52 +0100 Subject: [PATCH 24/25] basic_install: Use install for sudoers Signed-off-by: Andreas Schneider --- 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 087e0b38..110399f8 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1689,7 +1689,7 @@ installPiholeWeb() { # Make the .d directory if it doesn't exist mkdir -p /etc/sudoers.d/ # and copy in the pihole sudoers file - cp ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.sudo /etc/sudoers.d/pihole + install -m 0640 ${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole.sudo /etc/sudoers.d/pihole # Add lighttpd user (OS dependent) to sudoers file echo "${LIGHTTPD_USER} ALL=NOPASSWD: /usr/local/bin/pihole" >> /etc/sudoers.d/pihole From a145f1d931488bb4514adb3b79be6be20d9c5934 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 18 Feb 2019 22:32:53 +0000 Subject: [PATCH 25/25] Be more verbose with debug script output If output of `git status -s` is non-null display changes if output of `git diff` is non-null, display diff Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c840ed04..15c005b8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -269,6 +269,9 @@ compare_local_version_to_git_version() { # The commit they are on local remote_commit remote_commit=$(git describe --long --dirty --tags --always) + # Status of the repo + local local_status + local_status=$(git status -s) # echo this information out to the user in a nice format # If the current version matches what pihole -v produces, the user is up-to-date if [[ "${remote_version}" == "$(pihole -v | awk '/${search_term}/ {print $6}' | cut -d ')' -f1)" ]]; then @@ -291,6 +294,16 @@ compare_local_version_to_git_version() { fi # echo the current commit log_write "${INFO} Commit: ${remote_commit}" + # if `local_status` is non-null, then the repo is not clean, display details here + if [[ ${local_status} ]]; then + #Replace new lines in the status with 12 spaces to make the output cleaner + log_write "${INFO} Status: ${local_status//$'\n'/'\n '}" + local local_diff + local_diff=$(git diff) + if [[ ${local_diff} ]]; then + log_write "${INFO} Diff: ${local_diff//$'\n'/'\n '}" + fi + fi # If git status failed, else # Return an error message