From 72d8d10e647599723ec21ccf827d3b0c098e3fad Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 16 Jan 2017 22:39:58 +0100 Subject: [PATCH 001/165] Show most recently blocked domain in chronometer (using FTL). Fixes #717 --- advanced/Scripts/chronometer.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 93b0cbb18b..92842afa12 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -50,6 +50,9 @@ normalChrono() { uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' echo "-------------------------------" # Uncomment to continually read the log file and display the current domain being blocked + domain=$(curl -s -X GET http://127.0.0.1/admin/api.php?recentBlocked) + echo "Recently blocked:" + echo " $domain" #tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}' json=$(curl -s -X GET http://127.0.0.1/admin/api.php?summaryRaw) From 58f3ff69d893a69ad71a3fcbb40cb5a75281d9c3 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Mon, 16 Jan 2017 18:51:13 -0500 Subject: [PATCH 002/165] Align comment with referenced line --- advanced/Scripts/chronometer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 92842afa12..c52ae489f4 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -49,10 +49,10 @@ normalChrono() { #uptime -p #Doesn't work on all versions of uptime uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' echo "-------------------------------" - # Uncomment to continually read the log file and display the current domain being blocked domain=$(curl -s -X GET http://127.0.0.1/admin/api.php?recentBlocked) echo "Recently blocked:" echo " $domain" + # Uncomment to continually read the log file and display the current domain being blocked #tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}' json=$(curl -s -X GET http://127.0.0.1/admin/api.php?summaryRaw) From 52a2f166fd44ea3e40604f71d8ea6c984863eb31 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 10:29:27 +0100 Subject: [PATCH 003/165] Add FTLdownload() subroutine --- automated install/basic-install.sh | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index c70dd39308..5ce4898d6b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1150,6 +1150,38 @@ if [[ "${reconfigure}" == true ]]; then fi } +FTLdownload() { + + local machine=$(uname -m) + + echo $machine + + if [[ $machine == arm* ]]; then + # ARM + if [ -f "/lib/ld-linux-aarch64.so.1" ]; then + echo "Detected ARM-aarch64 architecture" + binary="pihole-FTL-aarch64-linux-gnu" + elif [ -f "/lib/ld-linux-armhf.so.3" ]; then + echo "Detected ARM-hf architecture" + binary="pihole-FTL-arm-linux-gnueabihf" + else + echo "Detected ARM architecture" + binary="pihole-FTL-arm-linux-gnueabi" + fi + elif [[ $machine == x86_64 ]]; then + # 64bit + echo "Detected x86_64 architecture" + binary="pihole-FTL-linux-x86_64" + else + # Something else - we try to use 32bit executable and warn the user + echo "Not able to detect architecture" + binary="pihole-FTL-linux-x86_32" + fi + + curl -sSL "https://github.com/pi-hole/FTL/releases/latest/${binary}" -o "/etc/pihole/pihole-FTL" +} + + main() { ######## FIRST CHECK ######## From 6018c0c2fcfd4fb521f718ba6564719cd712ef8b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 11:07:29 +0100 Subject: [PATCH 004/165] Add FTLinstall() --- automated install/basic-install.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5ce4898d6b..936c845b0d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1026,6 +1026,8 @@ installPihole() { fi installCron installLogrotate + FTLdownload + FTLinstall configureFirewall finalExports #runGravity @@ -1057,6 +1059,8 @@ updatePihole() { fi installCron installLogrotate + FTLdownload + FTLinstall finalExports #re-export setupVars.conf to account for any new vars added in new versions #runGravity } @@ -1178,9 +1182,14 @@ FTLdownload() { binary="pihole-FTL-linux-x86_32" fi - curl -sSL "https://github.com/pi-hole/FTL/releases/latest/${binary}" -o "/etc/pihole/pihole-FTL" + curl -sSL "https://github.com/pi-hole/FTL/releases/latest/${binary}" -o "/opt/pihole/pihole-FTL" } +FTLinstall() { + install -m 0755 /opt/pihole-FTL /usr/local/bin + touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port +} main() { From fbe3dc0dcdbd833faf0489949af4e970a7333599 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 11:27:52 +0100 Subject: [PATCH 005/165] Have to get latest tag via GitHub API for downloading the binaries --- automated install/basic-install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 936c845b0d..37fe469d66 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1182,7 +1182,13 @@ FTLdownload() { binary="pihole-FTL-linux-x86_32" fi - curl -sSL "https://github.com/pi-hole/FTL/releases/latest/${binary}" -o "/opt/pihole/pihole-FTL" + latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") + if [ ! "${latesttag}" ]; then + echo "Error in getting latest release tag from GitHub" + return 0 + fi + curl -sSL "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL" + return 0 } FTLinstall() { From 07e37d7fc3a2a36ac0e028cf74a54e13793b2d83 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 11:33:09 +0100 Subject: [PATCH 006/165] Proper error handling --- automated install/basic-install.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 37fe469d66..64a190e2f3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1026,8 +1026,9 @@ installPihole() { fi installCron installLogrotate - FTLdownload - FTLinstall + if FTLdownload; then + FTLinstall + fi configureFirewall finalExports #runGravity @@ -1059,8 +1060,9 @@ updatePihole() { fi installCron installLogrotate - FTLdownload - FTLinstall + if FTLdownload; then + FTLinstall + fi finalExports #re-export setupVars.conf to account for any new vars added in new versions #runGravity } @@ -1185,10 +1187,13 @@ FTLdownload() { latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") if [ ! "${latesttag}" ]; then echo "Error in getting latest release tag from GitHub" + return 1 + fi + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then return 0 + else + return 1 fi - curl -sSL "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL" - return 0 } FTLinstall() { From 7fb6b71d52c6ba6983c96133532bfe3821c83d29 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 14:40:31 +0100 Subject: [PATCH 007/165] Fix install path --- 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 64a190e2f3..d7e1442041 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1197,7 +1197,7 @@ FTLdownload() { } FTLinstall() { - install -m 0755 /opt/pihole-FTL /usr/local/bin + install -m 0755 /opt/pihole/pihole-FTL /usr/local/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port } From 09d6e73b0a41b24530587c0b2526be838048a376 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 14:42:11 +0100 Subject: [PATCH 008/165] Don't print error message on 32bit platforms --- automated install/basic-install.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d7e1442041..da69421e92 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1180,7 +1180,9 @@ FTLdownload() { binary="pihole-FTL-linux-x86_64" else # Something else - we try to use 32bit executable and warn the user - echo "Not able to detect architecture" + if [[ ! $machine == i686 ]]; then + echo "Not able to detect architecture, trying 32bit executable" + fi binary="pihole-FTL-linux-x86_32" fi From a052f397fec92d5a14da650d782e59e56210553a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 14:47:06 +0100 Subject: [PATCH 009/165] Be more verbose during install --- automated install/basic-install.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index da69421e92..23aeb4c347 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1157,6 +1157,9 @@ if [[ "${reconfigure}" == true ]]; then } FTLdownload() { + # Download suitable FTL binary + echo ":::" + echo "::: Downloading latest FTL binary..." local machine=$(uname -m) @@ -1188,20 +1191,28 @@ FTLdownload() { latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") if [ ! "${latesttag}" ]; then - echo "Error in getting latest release tag from GitHub" + echo "::: failed (error in getting latest release tag from GitHub)" return 1 fi if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then + echo "::: done" return 0 else + echo "::: failed (download of binary from Github failed)" return 1 fi } FTLinstall() { + # Download suitable FTL binary + echo ":::" + echo -n "::: Downloading latest FTL binary..." + install -m 0755 /opt/pihole/pihole-FTL /usr/local/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + + echo "done" } main() { From 95d7fe76b578b62ddd2e3ffccc01e959a957004d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 14:50:25 +0100 Subject: [PATCH 010/165] Make comments more pretty --- automated install/basic-install.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 23aeb4c347..467a58c539 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1159,7 +1159,7 @@ if [[ "${reconfigure}" == true ]]; then FTLdownload() { # Download suitable FTL binary echo ":::" - echo "::: Downloading latest FTL binary..." + echo "::: Downloading latest version of FTL..." local machine=$(uname -m) @@ -1168,23 +1168,24 @@ FTLdownload() { if [[ $machine == arm* ]]; then # ARM if [ -f "/lib/ld-linux-aarch64.so.1" ]; then - echo "Detected ARM-aarch64 architecture" + echo "::: Detected ARM-aarch64 architecture" binary="pihole-FTL-aarch64-linux-gnu" elif [ -f "/lib/ld-linux-armhf.so.3" ]; then - echo "Detected ARM-hf architecture" + echo "::: Detected ARM-hf architecture" binary="pihole-FTL-arm-linux-gnueabihf" else - echo "Detected ARM architecture" + echo "::: Detected ARM architecture" binary="pihole-FTL-arm-linux-gnueabi" fi elif [[ $machine == x86_64 ]]; then # 64bit - echo "Detected x86_64 architecture" + echo "::: Detected x86_64 architecture" binary="pihole-FTL-linux-x86_64" else # Something else - we try to use 32bit executable and warn the user if [[ ! $machine == i686 ]]; then - echo "Not able to detect architecture, trying 32bit executable" + echo "::: Not able to detect architecture (unknown: ${machine}), trying 32bit executable" + echo "::: Contact Pi-hole support if you experience problems (like FTL not running)" fi binary="pihole-FTL-linux-x86_32" fi @@ -1206,7 +1207,7 @@ FTLdownload() { FTLinstall() { # Download suitable FTL binary echo ":::" - echo -n "::: Downloading latest FTL binary..." + echo -n "::: Installing FTL ... " install -m 0755 /opt/pihole/pihole-FTL /usr/local/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port From abd44dd284fa8085ea9c62da0604e0b04a44127b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 16:33:22 +0100 Subject: [PATCH 011/165] Add 32bit message --- 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 467a58c539..b549e930fc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1187,6 +1187,7 @@ FTLdownload() { echo "::: Not able to detect architecture (unknown: ${machine}), trying 32bit executable" echo "::: Contact Pi-hole support if you experience problems (like FTL not running)" fi + echo "::: Detected 32bit (i686) architecture" binary="pihole-FTL-linux-x86_32" fi @@ -1205,7 +1206,7 @@ FTLdownload() { } FTLinstall() { - # Download suitable FTL binary + # Install FTL binary echo ":::" echo -n "::: Installing FTL ... " From 4035c933df61682ae79f36207c7197cfce236a53 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 13 Feb 2017 16:50:48 +0100 Subject: [PATCH 012/165] Moved echo to else block --- 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 b549e930fc..ae8b48f6b5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1186,8 +1186,9 @@ FTLdownload() { if [[ ! $machine == i686 ]]; then echo "::: Not able to detect architecture (unknown: ${machine}), trying 32bit executable" echo "::: Contact Pi-hole support if you experience problems (like FTL not running)" + else + echo "::: Detected 32bit (i686) architecture" fi - echo "::: Detected 32bit (i686) architecture" binary="pihole-FTL-linux-x86_32" fi From 378338c6847ca3864047197b67ca31ac67503ab1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 Feb 2017 10:42:07 +0100 Subject: [PATCH 013/165] Install pihole-FTL to /usr/bin instead of /usr/local/bin --- 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 ae8b48f6b5..4e69ef19bc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1211,7 +1211,7 @@ FTLinstall() { echo ":::" echo -n "::: Installing FTL ... " - install -m 0755 /opt/pihole/pihole-FTL /usr/local/bin + install -m 0755 /opt/pihole/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port From f24f77c5bd4555a92f4b7b5451c738b6fd6a07d0 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 Feb 2017 11:14:23 +0100 Subject: [PATCH 014/165] Detect if architecture is *aarch* + use hf binary only if ARMv7+ is detected --- automated install/basic-install.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4e69ef19bc..5de6873463 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1163,16 +1163,21 @@ FTLdownload() { local machine=$(uname -m) - echo $machine - - if [[ $machine == arm* ]]; then + if [[ $machine == arm* || $machine == *aarch* ]]; then # ARM + local rev=$(uname -m | sed "s/[^0-9]//g;") if [ -f "/lib/ld-linux-aarch64.so.1" ]; then echo "::: Detected ARM-aarch64 architecture" binary="pihole-FTL-aarch64-linux-gnu" elif [ -f "/lib/ld-linux-armhf.so.3" ]; then - echo "::: Detected ARM-hf architecture" - binary="pihole-FTL-arm-linux-gnueabihf" + if [ "$rev" -gt "6" ]; then + echo "::: Detected ARM-hf architecture (armv7+)" + binary="pihole-FTL-arm-linux-gnueabihf" + else + echo "::: Detected ARM-hf architecture (armv6 or lower)" + echo "::: Using ARM binary" + binary="pihole-FTL-arm-linux-gnueabi" + fi else echo "::: Detected ARM architecture" binary="pihole-FTL-arm-linux-gnueabi" From 70a6a79b8c68072b464da0d029d7249ad38fd4d4 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 20 Feb 2017 13:40:32 +0100 Subject: [PATCH 015/165] Detect library differently --- 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 5de6873463..5cc086c5e2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1166,10 +1166,11 @@ FTLdownload() { if [[ $machine == arm* || $machine == *aarch* ]]; then # ARM local rev=$(uname -m | sed "s/[^0-9]//g;") - if [ -f "/lib/ld-linux-aarch64.so.1" ]; then + local lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') + if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then echo "::: Detected ARM-aarch64 architecture" binary="pihole-FTL-aarch64-linux-gnu" - elif [ -f "/lib/ld-linux-armhf.so.3" ]; then + elif [[ "$lib" == "/lib/ld-linux-armhf.so.3" ]]; then if [ "$rev" -gt "6" ]; then echo "::: Detected ARM-hf architecture (armv7+)" binary="pihole-FTL-arm-linux-gnueabihf" From 7032be6049854e259921cfadf1ddb201b0b3b14b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 19 Feb 2017 21:38:02 -0800 Subject: [PATCH 016/165] Template for FTL engine type tests. Signed-off-by: Dan Schaper --- test/test_automated_install.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 89d9a0e07c..5096e2b2cd 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -297,6 +297,35 @@ def test_update_package_cache_failure_no_errors(Pihole): assert 'ERROR' in updateCache.stdout assert 'done!' not in updateCache.stdout +def test_FTL_download_aarch64_no_errors(Pihole): + ''' confirms only aarch64 package is downloaded for FTL engine ''' + # mock uname to return aarch64 platform + mock_command('uname', {'-m':('aarch64', '0')}, Pihole) + detectPlatform = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdownload + touch /lib/ld-linux-aarch64.so.1 + ''') + expected_stdout = 'Detected ARM-aarch64 architecture' + assert expected_stdout in detectPlatform.stdout + FTL_binary = Pihole.run('echo ${binary}').stdout + assert 'pihole-FTL-aarch64-linux-gnu' in FTL_binary + +def test_FTL_download_armv6l_Pi_Zero_no_errors(Pihole): + ''' confirms only armv6l package is downloaded for FTL engine (Pi-Zero) ''' + # mock uname to return aarch64 platform + mock_command('uname', {'-m':('armv6l', '0')}, Pihole) + detectPlatform = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdownload + touch /lib/ld-linux-armhf.so.3 + ls -lach /lib/ + ''') + expected_stdout = 'Detected ARM-hf architecture' + assert expected_stdout in detectPlatform.stdout + FTL_binary = Pihole.run('echo ${binary}').stdout + assert 'pihole-FTL-arm-linux-gnueabihf' in FTL_binary + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From b4450a39184156a0a2e1c180e71866ba6258d14c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 04:44:31 -0800 Subject: [PATCH 017/165] Mock ldd command response. Test aarch64 detection Signed-off-by: Dan Schaper --- test/test_automated_install.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 5096e2b2cd..76fbe7efb7 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -301,30 +301,14 @@ def test_FTL_download_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' # mock uname to return aarch64 platform mock_command('uname', {'-m':('aarch64', '0')}, Pihole) + # mock ldd to respond with aarch64 shared library + mock_command('ldd', {'/bin/ls':('/lib/ld-linux-aarch64.so.1', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh FTLdownload - touch /lib/ld-linux-aarch64.so.1 ''') expected_stdout = 'Detected ARM-aarch64 architecture' assert expected_stdout in detectPlatform.stdout - FTL_binary = Pihole.run('echo ${binary}').stdout - assert 'pihole-FTL-aarch64-linux-gnu' in FTL_binary - -def test_FTL_download_armv6l_Pi_Zero_no_errors(Pihole): - ''' confirms only armv6l package is downloaded for FTL engine (Pi-Zero) ''' - # mock uname to return aarch64 platform - mock_command('uname', {'-m':('armv6l', '0')}, Pihole) - detectPlatform = Pihole.run(''' - source /opt/pihole/basic-install.sh - FTLdownload - touch /lib/ld-linux-armhf.so.3 - ls -lach /lib/ - ''') - expected_stdout = 'Detected ARM-hf architecture' - assert expected_stdout in detectPlatform.stdout - FTL_binary = Pihole.run('echo ${binary}').stdout - assert 'pihole-FTL-arm-linux-gnueabihf' in FTL_binary # Helper functions def mock_command(script, args, container): From 59d6907d71bc8e3b601ae33d78530a78a6fcc9c0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 06:24:35 -0800 Subject: [PATCH 018/165] Test aarch64 detection Signed-off-by: Dan Schaper --- test/test_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 76fbe7efb7..4e84c1470e 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -297,7 +297,7 @@ def test_update_package_cache_failure_no_errors(Pihole): assert 'ERROR' in updateCache.stdout assert 'done!' not in updateCache.stdout -def test_FTL_download_aarch64_no_errors(Pihole): +def test_FTL_detect_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' # mock uname to return aarch64 platform mock_command('uname', {'-m':('aarch64', '0')}, Pihole) From 26c628f8a5667611b29724cb7950a6c614b491eb Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 04:44:31 -0800 Subject: [PATCH 019/165] Mock ldd command response. Test aarch64 detection Arm v6/v7 little endian. x86_64 native Test aarch64 detection Unknown platform detection. Signed-off-by: Dan Schaper --- test/test_automated_install.py | 54 ++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 5096e2b2cd..449a1f316b 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -297,34 +297,64 @@ def test_update_package_cache_failure_no_errors(Pihole): assert 'ERROR' in updateCache.stdout assert 'done!' not in updateCache.stdout -def test_FTL_download_aarch64_no_errors(Pihole): +def test_FTL_detect_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' # mock uname to return aarch64 platform mock_command('uname', {'-m':('aarch64', '0')}, Pihole) + # mock ldd to respond with aarch64 shared library + mock_command('ldd', {'/bin/ls':('/lib/ld-linux-aarch64.so.1', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh FTLdownload - touch /lib/ld-linux-aarch64.so.1 ''') expected_stdout = 'Detected ARM-aarch64 architecture' assert expected_stdout in detectPlatform.stdout - FTL_binary = Pihole.run('echo ${binary}').stdout - assert 'pihole-FTL-aarch64-linux-gnu' in FTL_binary -def test_FTL_download_armv6l_Pi_Zero_no_errors(Pihole): - ''' confirms only armv6l package is downloaded for FTL engine (Pi-Zero) ''' - # mock uname to return aarch64 platform +def test_FTL_detect_armv6l_no_errors(Pihole): + ''' confirms only armv6l package is downloaded for FTL engine ''' + # mock uname to return armv6l platform mock_command('uname', {'-m':('armv6l', '0')}, Pihole) + # mock ldd to respond with aarch64 shared library + mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) + detectPlatform = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdownload + ''') + expected_stdout = 'Detected ARM-hf architecture (armv6 or lower)' + assert expected_stdout in detectPlatform.stdout + +def test_FTL_detect_armv7l_no_errors(Pihole): + ''' confirms only armv7l package is downloaded for FTL engine ''' + # mock uname to return armv7l platform + mock_command('uname', {'-m':('armv7l', '0')}, Pihole) + # mock ldd to respond with aarch64 shared library + mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) + detectPlatform = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdownload + ''') + expected_stdout = 'Detected ARM-hf architecture (armv7+)' + assert expected_stdout in detectPlatform.stdout + +def test_FTL_detect_x86_64_no_errors(Pihole): + ''' confirms only x86_64 package is downloaded for FTL engine ''' + detectPlatform = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdownload + ''') + expected_stdout = 'Detected x86_64 architecture' + assert expected_stdout in detectPlatform.stdout + +def test_FTL_detect_unknown_no_errors(Pihole): + ''' confirms only generic package is downloaded for FTL engine ''' + # mock uname to return generic platform + mock_command('uname', {'-m':('mips', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh FTLdownload - touch /lib/ld-linux-armhf.so.3 - ls -lach /lib/ ''') - expected_stdout = 'Detected ARM-hf architecture' + expected_stdout = 'Not able to detect architecture (unknown: mips)' assert expected_stdout in detectPlatform.stdout - FTL_binary = Pihole.run('echo ${binary}').stdout - assert 'pihole-FTL-arm-linux-gnueabihf' in FTL_binary # Helper functions def mock_command(script, args, container): From 339f95b00c62543fe6aa9e72e90d5f84db422fb5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 08:13:46 -0800 Subject: [PATCH 020/165] Change from `uname -m` to straight `arch` Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 4 ++-- test/test_automated_install.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5cc086c5e2..dc302f4848 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1161,11 +1161,11 @@ FTLdownload() { echo ":::" echo "::: Downloading latest version of FTL..." - local machine=$(uname -m) + local machine=$(arch) if [[ $machine == arm* || $machine == *aarch* ]]; then # ARM - local rev=$(uname -m | sed "s/[^0-9]//g;") + local rev=$(arch | sed "s/[^0-9]//g;") local lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then echo "::: Detected ARM-aarch64 architecture" diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 97c8e503eb..a448823947 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -300,7 +300,7 @@ def test_update_package_cache_failure_no_errors(Pihole): def test_FTL_detect_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' # mock uname to return aarch64 platform - mock_command('uname', {'-m':('aarch64', '0')}, Pihole) + mock_command('arch', {'*':('aarch64', '0')}, Pihole) # mock ldd to respond with aarch64 shared library mock_command('ldd', {'/bin/ls':('/lib/ld-linux-aarch64.so.1', '0')}, Pihole) detectPlatform = Pihole.run(''' @@ -313,7 +313,7 @@ def test_FTL_detect_aarch64_no_errors(Pihole): def test_FTL_detect_armv6l_no_errors(Pihole): ''' confirms only armv6l package is downloaded for FTL engine ''' # mock uname to return armv6l platform - mock_command('uname', {'-m':('armv6l', '0')}, Pihole) + mock_command('arch', {'*':('armv6l', '0')}, Pihole) # mock ldd to respond with aarch64 shared library mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' @@ -326,7 +326,7 @@ def test_FTL_detect_armv6l_no_errors(Pihole): def test_FTL_detect_armv7l_no_errors(Pihole): ''' confirms only armv7l package is downloaded for FTL engine ''' # mock uname to return armv7l platform - mock_command('uname', {'-m':('armv7l', '0')}, Pihole) + mock_command('arch', {'*':('armv7l', '0')}, Pihole) # mock ldd to respond with aarch64 shared library mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' @@ -348,7 +348,7 @@ def test_FTL_detect_x86_64_no_errors(Pihole): def test_FTL_detect_unknown_no_errors(Pihole): ''' confirms only generic package is downloaded for FTL engine ''' # mock uname to return generic platform - mock_command('uname', {'-m':('mips', '0')}, Pihole) + mock_command('arch', {'*':('mips', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh FTLdownload From 87edbeaf5812d229ac4c931cbfa72448934f2818 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 08:24:19 -0800 Subject: [PATCH 021/165] Factor out downloader from detector function. Signed-off-by: Dan Schaper --- .pullapprove.yml | 38 ------------------ automated install/basic-install.sh | 64 +++++++++++++++--------------- test/test_automated_install.py | 10 ++--- 3 files changed, 38 insertions(+), 74 deletions(-) delete mode 100644 .pullapprove.yml diff --git a/.pullapprove.yml b/.pullapprove.yml deleted file mode 100644 index f9d1006221..0000000000 --- a/.pullapprove.yml +++ /dev/null @@ -1,38 +0,0 @@ -version: 2 - -always_pending: - title_regex: '(WIP|wip)' - labels: - - wip - explanation: 'This PR is a work in progress...' - -group_defaults: - reset_on_push: - enabled: true - reject_value: -2 - approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' - reject_regex: '^(Rejected|:-1:|Borg)' - author_approval: - auto: true - - -groups: - development: - approve_by_comment: - enabled: true - conditions: - branches: - - development - required: 2 - teams: - - approvers - - master: - approve_by_comment: - enabled: true - conditions: - branches: - - master - required: -1 - teams: - - admin diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index dc302f4848..aead05834b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1026,9 +1026,7 @@ installPihole() { fi installCron installLogrotate - if FTLdownload; then - FTLinstall - fi + FTLdetect || echo "::: FTL Engine not installed." configureFirewall finalExports #runGravity @@ -1060,9 +1058,7 @@ updatePihole() { fi installCron installLogrotate - if FTLdownload; then - FTLinstall - fi + FTLdetect || echo "::: FTL Engine not installed." finalExports #re-export setupVars.conf to account for any new vars added in new versions #runGravity } @@ -1156,12 +1152,40 @@ if [[ "${reconfigure}" == true ]]; then fi } -FTLdownload() { +FTLinstall() { + # Download and Install FTL binary + local binary="${1}" + local latesttag + echo ":::" + echo -n "::: Installing FTL ... " + + latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") + if [ ! "${latesttag}" ]; then + echo "::: failed (error in getting latest release tag from GitHub)" + return 1 + fi + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then + echo "::: done" + install -m 0755 /opt/pihole/pihole-FTL /usr/bin + touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + return 0 + else + echo "::: failed (download of binary from Github failed)" + return 1 + fi + echo "done" +} + +FTLdetect() { # Download suitable FTL binary echo ":::" echo "::: Downloading latest version of FTL..." - local machine=$(arch) + local machine + local binary + + machine=$(arch) if [[ $machine == arm* || $machine == *aarch* ]]; then # ARM @@ -1198,30 +1222,8 @@ FTLdownload() { binary="pihole-FTL-linux-x86_32" fi - latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") - if [ ! "${latesttag}" ]; then - echo "::: failed (error in getting latest release tag from GitHub)" - return 1 - fi - if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then - echo "::: done" - return 0 - else - echo "::: failed (download of binary from Github failed)" - return 1 - fi -} - -FTLinstall() { - # Install FTL binary - echo ":::" - echo -n "::: Installing FTL ... " + FTLinstall "${binary}" || return 1 - install -m 0755 /opt/pihole/pihole-FTL /usr/bin - touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - - echo "done" } main() { diff --git a/test/test_automated_install.py b/test/test_automated_install.py index a448823947..b0dded5cd1 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -305,7 +305,7 @@ def test_FTL_detect_aarch64_no_errors(Pihole): mock_command('ldd', {'/bin/ls':('/lib/ld-linux-aarch64.so.1', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected ARM-aarch64 architecture' assert expected_stdout in detectPlatform.stdout @@ -318,7 +318,7 @@ def test_FTL_detect_armv6l_no_errors(Pihole): mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected ARM-hf architecture (armv6 or lower)' assert expected_stdout in detectPlatform.stdout @@ -331,7 +331,7 @@ def test_FTL_detect_armv7l_no_errors(Pihole): mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected ARM-hf architecture (armv7+)' assert expected_stdout in detectPlatform.stdout @@ -340,7 +340,7 @@ def test_FTL_detect_x86_64_no_errors(Pihole): ''' confirms only x86_64 package is downloaded for FTL engine ''' detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Detected x86_64 architecture' assert expected_stdout in detectPlatform.stdout @@ -351,7 +351,7 @@ def test_FTL_detect_unknown_no_errors(Pihole): mock_command('arch', {'*':('mips', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh - FTLdownload + FTLdetect ''') expected_stdout = 'Not able to detect architecture (unknown: mips)' assert expected_stdout in detectPlatform.stdout From 7a269e757ebbac6c5c2762b012767b30d3b6bdc6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 09:24:47 -0800 Subject: [PATCH 022/165] Debian buildpack image for docker (Need `curl` for testing, using scm version to add `curl` and `git`.) Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 12 ++++++------ test/debian.Dockerfile | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index aead05834b..98322cb7e5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1155,18 +1155,18 @@ if [[ "${reconfigure}" == true ]]; then FTLinstall() { # Download and Install FTL binary local binary="${1}" - local latesttag + local latestURL echo ":::" echo -n "::: Installing FTL ... " - latesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | grep "tag_name" | sed "s/.*: \"//;s/\",//;") - if [ ! "${latesttag}" ]; then - echo "::: failed (error in getting latest release tag from GitHub)" + latestURL=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk '{print $2}') + if [ ! "${latestURL}" ]; then + echo "::: failed (error in getting latest release location from GitHub)" return 1 fi - if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/opt/pihole/pihole-FTL"; then + if curl -sSL --fail "${latestURL}${binary}" -o "/tmp/pihole-FTL"; then echo "::: done" - install -m 0755 /opt/pihole/pihole-FTL /usr/bin + install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port return 0 diff --git a/test/debian.Dockerfile b/test/debian.Dockerfile index 931c0ba766..66436f1a96 100644 --- a/test/debian.Dockerfile +++ b/test/debian.Dockerfile @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM buildpack-deps:jessie-scm ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From 70e876ee1335bd8d9147bb7137d32df0b2ec7a67 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 09:36:24 -0800 Subject: [PATCH 023/165] Download tests. Make sure we download a binary and not just get the GitHub page. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 22 ++++++++++++---------- test/test_automated_install.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 98322cb7e5..7499336b02 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1164,17 +1164,19 @@ FTLinstall() { echo "::: failed (error in getting latest release location from GitHub)" return 1 fi - if curl -sSL --fail "${latestURL}${binary}" -o "/tmp/pihole-FTL"; then - echo "::: done" - install -m 0755 /tmp/pihole-FTL /usr/bin - touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - return 0 - else - echo "::: failed (download of binary from Github failed)" - return 1 + if curl -sSL --fail "${latestURL%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then + if [[ -f /tmp/pihole-FTL ]]; then + echo "::: done" + install -m 0755 /tmp/pihole-FTL /usr/bin + touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + return 0 + else + echo "::: failed (download of binary from Github failed)" + return 1 + fi + echo "done" fi - echo "done" } FTLdetect() { diff --git a/test/test_automated_install.py b/test/test_automated_install.py index b0dded5cd1..40e0000b80 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -355,6 +355,29 @@ def test_FTL_detect_unknown_no_errors(Pihole): ''') expected_stdout = 'Not able to detect architecture (unknown: mips)' assert expected_stdout in detectPlatform.stdout + +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 + FTLinstall pihole-FTL-aarch64-linux-gnu + ''') + expected_stdout = 'done' + assert expected_stdout in download_binary.stdout + assert 'failed' not in download_binary.stdout + +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 + FTLinstall pihole-FTL-mips + ''') + expected_stdout = 'failed' + assert expected_stdout in download_binary.stdout + assert 'done' not in download_binary.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 875a5d309d5f482f7e0ffe7f6cdf0e28fc2d72e2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 10:25:17 -0800 Subject: [PATCH 024/165] Check downloaded file for binary or text. Signed-off-by: Dan Schaper --- 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 7499336b02..bdc1cf2531 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1155,17 +1155,18 @@ if [[ "${reconfigure}" == true ]]; then FTLinstall() { # Download and Install FTL binary local binary="${1}" - local latestURL + local latesttag echo ":::" echo -n "::: Installing FTL ... " - latestURL=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk '{print $2}') - if [ ! "${latestURL}" ]; then + latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') + if [ ! "${latesttag}" ]; then echo "::: failed (error in getting latest release location from GitHub)" return 1 fi - if curl -sSL --fail "${latestURL%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then - if [[ -f /tmp/pihole-FTL ]]; then + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/tmp/pihole-FTL"; then + # Check if we just downloaded text, or a binary file. + if ! grep -qI '.' /tmp/pihole-FTL; then echo "::: done" install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port From 48351fed79181d2f457430f4d275ba1767dc9676 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 11:33:55 -0800 Subject: [PATCH 025/165] Remove trailing newline from curl'd variable. Signed-off-by: Dan Schaper --- 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 bdc1cf2531..059f8f10cc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1164,7 +1164,7 @@ FTLinstall() { echo "::: failed (error in getting latest release location from GitHub)" return 1 fi - if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag}/${binary}" -o "/tmp/pihole-FTL"; then + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then # Check if we just downloaded text, or a binary file. if ! grep -qI '.' /tmp/pihole-FTL; then echo "::: done" From 5e6f8489a919324d3ebeeac3aa238f1670e9514b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 11:45:58 -0800 Subject: [PATCH 026/165] Find 404 errors and relay message. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 059f8f10cc..4fefbc0fdb 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1161,22 +1161,24 @@ FTLinstall() { latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') if [ ! "${latesttag}" ]; then - echo "::: failed (error in getting latest release location from GitHub)" + echo "failed (error in getting latest release location from GitHub)" return 1 fi if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then # Check if we just downloaded text, or a binary file. if ! grep -qI '.' /tmp/pihole-FTL; then - echo "::: done" + echo "done" install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port return 0 else - echo "::: failed (download of binary from Github failed)" + echo "failed (download of binary from Github failed)" return 1 fi echo "done" + else + echo "failed (URL not found.)" fi } From e087797edc34b740a231397bdea2b080fa2d562c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 11:49:20 -0800 Subject: [PATCH 027/165] Test for format of tag version. Signed-off-by: Dan Schaper --- 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 4fefbc0fdb..04febe5793 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1160,7 +1160,8 @@ FTLinstall() { echo -n "::: Installing FTL ... " latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') - if [ ! "${latesttag}" ]; then + # Tags should always start with v, check for that. + if [[ ! "${latesttag}" == v* ]]; then echo "failed (error in getting latest release location from GitHub)" return 1 fi From dd1aa9163c02b9f79fd42512aa2b0f552c4e0ff8 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 12:01:38 -0800 Subject: [PATCH 028/165] Fix IDEA ignoring pullapprove. Signed-off-by: Dan Schaper --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c4b497a099..d7bdfd375c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ *.swp __pycache__ .cache -.pullapprove.yml From 883aa30acabdc35822b8f38eac16c7e343d1c920 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 13:25:28 -0800 Subject: [PATCH 029/165] Revert reversion. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d7bdfd375c..91014dcdcb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ *.swp __pycache__ .cache - +.pullapprove.yml From 057cecb3e03dfa58038d8a3b065c95cceace6507 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 14:12:45 -0800 Subject: [PATCH 030/165] Replace ignored file. --- .pullapprove.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .pullapprove.yml diff --git a/.pullapprove.yml b/.pullapprove.yml new file mode 100644 index 0000000000..c02b5486ec --- /dev/null +++ b/.pullapprove.yml @@ -0,0 +1,38 @@ +version: 2 + +always_pending: + title_regex: '(WIP|wip)' + labels: + - wip + explanation: 'This PR is a work in progress...' + +group_defaults: + reset_on_push: + enabled: true + reject_value: -2 + approve_regex: '^(Approved|:shipit:|:\+1:|Engage)' + reject_regex: '^(Rejected|:-1:|Borg)' + author_approval: + auto: true + + +groups: + development: + approve_by_comment: + enabled: true + conditions: + branches: + - development + required: 2 + teams: + - approvers + + master: + approve_by_comment: + enabled: true + conditions: + branches: + - master + required: -1 + teams: + - admin \ No newline at end of file From b36a44a954bfe2e249c40a5a8d2081a9ab407e84 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 14:44:34 -0800 Subject: [PATCH 031/165] Check sha1 of transferred file. --- automated install/basic-install.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 04febe5793..129f88fdea 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1157,7 +1157,7 @@ FTLinstall() { local binary="${1}" local latesttag echo ":::" - echo -n "::: Installing FTL ... " + echo -n "::: Installing FTL... " latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') # Tags should always start with v, check for that. @@ -1165,10 +1165,12 @@ FTLinstall() { echo "failed (error in getting latest release location from GitHub)" return 1 fi - if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/${binary}"; then + # Get sha1 of the binary we just downloaded for verification. + curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}.sha1" -o "/tmp/${binary}.sha1" # Check if we just downloaded text, or a binary file. - if ! grep -qI '.' /tmp/pihole-FTL; then - echo "done" + if sha1sum -c "${binary}".sha1; then + echo -n "transferred... " install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port @@ -1177,7 +1179,7 @@ FTLinstall() { echo "failed (download of binary from Github failed)" return 1 fi - echo "done" + echo "done." else echo "failed (URL not found.)" fi From cde7b53de394d543434de98ce5936d9a868b2aca Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 14:44:34 -0800 Subject: [PATCH 032/165] Check sha1 of transferred file. Sha1sum file in temp directory. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 04febe5793..f3249f9f17 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1157,7 +1157,7 @@ FTLinstall() { local binary="${1}" local latesttag echo ":::" - echo -n "::: Installing FTL ... " + echo -n "::: Installing FTL... " latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') # Tags should always start with v, check for that. @@ -1165,10 +1165,12 @@ FTLinstall() { echo "failed (error in getting latest release location from GitHub)" return 1 fi - if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/pihole-FTL"; then + if curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}" -o "/tmp/${binary}"; then + # Get sha1 of the binary we just downloaded for verification. + curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}.sha1" -o "/tmp/${binary}.sha1" # Check if we just downloaded text, or a binary file. - if ! grep -qI '.' /tmp/pihole-FTL; then - echo "done" + if sha1sum -c /tmp/"${binary}".sha1 /tmp/"${binary}"; then + echo -n "transferred... " install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port @@ -1177,7 +1179,7 @@ FTLinstall() { echo "failed (download of binary from Github failed)" return 1 fi - echo "done" + echo "done." else echo "failed (URL not found.)" fi From 6023984703579bb76dfc178efabffd33a4b0a932 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 15:10:46 -0800 Subject: [PATCH 033/165] Silence sha check Signed-off-by: Dan Schaper --- 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 f3249f9f17..3ffdba2aea 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1169,7 +1169,7 @@ FTLinstall() { # Get sha1 of the binary we just downloaded for verification. curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}.sha1" -o "/tmp/${binary}.sha1" # Check if we just downloaded text, or a binary file. - if sha1sum -c /tmp/"${binary}".sha1 /tmp/"${binary}"; then + if sha1sum -c /tmp/"${binary}".sha1 /tmp/"${binary}" &> /dev/null; then echo -n "transferred... " install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port From a0c17368ed8dd172a18e695310251ee39c6fd7f9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 15:27:24 -0800 Subject: [PATCH 034/165] `cd` to directory to sha1sum Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3ffdba2aea..5a0aae736f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1156,9 +1156,11 @@ FTLinstall() { # Download and Install FTL binary local binary="${1}" local latesttag + local orig_dir echo ":::" echo -n "::: Installing FTL... " + orig_dir="${PWD}" latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') # Tags should always start with v, check for that. if [[ ! "${latesttag}" == v* ]]; then @@ -1169,16 +1171,20 @@ FTLinstall() { # Get sha1 of the binary we just downloaded for verification. curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${latesttag%$'\r'}/${binary}.sha1" -o "/tmp/${binary}.sha1" # Check if we just downloaded text, or a binary file. - if sha1sum -c /tmp/"${binary}".sha1 /tmp/"${binary}" &> /dev/null; then + cd /tmp + if sha1sum --status --quiet -c "${binary}".sha1; then echo -n "transferred... " install -m 0755 /tmp/pihole-FTL /usr/bin touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + cd "${orig_dir}" return 0 else echo "failed (download of binary from Github failed)" + cd "${orig_dir}" return 1 fi + cd "${orig_dir}" echo "done." else echo "failed (URL not found.)" From 2ffb103acb064f7aa3f81bdb2723fbdb73bdcf9f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 15:32:02 -0800 Subject: [PATCH 035/165] Move binary to final home. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5a0aae736f..11ffbec2bc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1153,7 +1153,7 @@ if [[ "${reconfigure}" == true ]]; then } FTLinstall() { - # Download and Install FTL binary + # Download and install FTL binary local binary="${1}" local latesttag local orig_dir @@ -1174,25 +1174,25 @@ FTLinstall() { cd /tmp if sha1sum --status --quiet -c "${binary}".sha1; then echo -n "transferred... " - install -m 0755 /tmp/pihole-FTL /usr/bin + install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port cd "${orig_dir}" + echo "done." return 0 else echo "failed (download of binary from Github failed)" cd "${orig_dir}" return 1 fi - cd "${orig_dir}" - echo "done." else + cd "${orig_dir}" echo "failed (URL not found.)" fi } FTLdetect() { - # Download suitable FTL binary + # Detect suitable FTL binary platform echo ":::" echo "::: Downloading latest version of FTL..." @@ -1236,7 +1236,7 @@ FTLdetect() { binary="pihole-FTL-linux-x86_32" fi - FTLinstall "${binary}" || return 1 + FTLdownload "${binary}" || return 1 } From 8eeb8ad779169608c520d73708e2626f5fc0de8a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 17:15:04 -0800 Subject: [PATCH 036/165] Check binary installed and functional. Signed-off-by: Dan Schaper --- test/test_automated_install.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 40e0000b80..250accf704 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -378,6 +378,16 @@ def test_FTL_download_unknown_fails_no_errors(Pihole): assert expected_stdout in download_binary.stdout assert 'done' not in download_binary.stdout +def test_FTL_binary_installed_and_responsive_no_errors(Pihole): + ''' confirms FTL binary is copied and functional in installed location ''' + installed_binary = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdetect + pihole-FTL version + ''') + expected_stdout = 'v' + assert expected_stdout in installed_binary.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 4cd598ae103c66d89b62fd2addbefe635a5ec4bf Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 17:28:38 -0800 Subject: [PATCH 037/165] Check support files installed and permissions. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 6 +++--- test/test_automated_install.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 11ffbec2bc..715d6e957a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1175,8 +1175,8 @@ FTLinstall() { if sha1sum --status --quiet -c "${binary}".sha1; then echo -n "transferred... " install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL - touch /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port - chmod 0666 /var/log/pihole-FTL.log /var/run/pihole-FTL.pid /var/run/pihole-FTL.port + touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port + chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port cd "${orig_dir}" echo "done." return 0 @@ -1236,7 +1236,7 @@ FTLdetect() { binary="pihole-FTL-linux-x86_32" fi - FTLdownload "${binary}" || return 1 + FTLinstall "${binary}" || return 1 } diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 250accf704..1fb1a20af8 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -388,6 +388,20 @@ def test_FTL_binary_installed_and_responsive_no_errors(Pihole): expected_stdout = 'v' assert expected_stdout in installed_binary.stdout +def test_FTL_support_files_installed(Pihole): + ''' confirms FTL support files are installed ''' + support_files = Pihole.run(''' + source /opt/pihole/basic-install.sh + FTLdetect + stat -c '%a %n' /var/log/pihole-FTL.log + stat -c '%a %n' /run/pihole-FTL.port + stat -c '%a %n' /run/pihole-FTL.pid + ls -lac /run + ''') + assert '644 pihole-FTL.port' in support_files.stdout + assert '644 pihole-FTL.pid' in support_files.stdout + assert '644 pihole-FTL.log' in support_files.stdout + # Helper functions def mock_command(script, args, container): ''' Allows for setup of commands we don't really want to have to run for real in unit tests ''' From 02ea9b9abc917d1eba7faef0e762c56377b61f13 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 20 Feb 2017 18:15:40 -0800 Subject: [PATCH 038/165] Check file path and permissions in one go. Signed-off-by: Dan Schaper --- test/test_automated_install.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 1fb1a20af8..b42262dee3 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -398,9 +398,9 @@ def test_FTL_support_files_installed(Pihole): stat -c '%a %n' /run/pihole-FTL.pid ls -lac /run ''') - assert '644 pihole-FTL.port' in support_files.stdout - assert '644 pihole-FTL.pid' in support_files.stdout - assert '644 pihole-FTL.log' in support_files.stdout + assert '644 /run/pihole-FTL.port' in support_files.stdout + assert '644 /run/pihole-FTL.pid' in support_files.stdout + assert '644 /var/log/pihole-FTL.log' in support_files.stdout # Helper functions def mock_command(script, args, container): From 90ccbef4313dc61c97443feee0e917adb4221251 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 11:18:47 +0100 Subject: [PATCH 039/165] pihole-FTL init.d script --- advanced/pihole-FTL.service | 81 ++++++++++++++++++++++++++++++ automated install/basic-install.sh | 10 +++- 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 advanced/pihole-FTL.service diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service new file mode 100644 index 0000000000..1fcd9b0162 --- /dev/null +++ b/advanced/pihole-FTL.service @@ -0,0 +1,81 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: pihole-FTL +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: pihole-FTL daemon +# Description: Enable service provided by pihole-FTL daemon +### END INIT INFO + +FTLUSER=pi +PIDFILE=/var/run/pihole-FTL.pid + +get_pid() { + cat "$PIDFILE" +} + +is_running() { + [ -f "$PIDFILE" ] && ps $(get_pid) > /dev/null 2>&1 +} + +# Start the service +start() { + if is_running; then + echo "pihole-FTL is already running" + else + touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port + chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port + su -c "/usr/bin/pihole-FTL" "$FTLUSER" &> /dev/null + echo + fi +} + +# Stop the service +stop() { + if is_running; then + kill $(get_pid) + for i in {1..10}; do + if ! is_running; then + break + fi + + echo -n "." + sleep 1 + done + echo + + if is_running; then + echo "Not stopped; may still be shutting down or shutdown may have failed" + exit 1 + else + echo "Stopped" + fi + else + echo "Not running" + fi + echo +} + +### main logic ### +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status pihole-FTL + ;; + restart|reload|condrestart) + stop + start + ;; + *) + echo $"Usage: $0 {start|stop|restart|reload|status}" + exit 1 +esac + +exit 0 diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 715d6e957a..8a135e9bad 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1174,10 +1174,13 @@ FTLinstall() { cd /tmp if sha1sum --status --quiet -c "${binary}".sha1; then echo -n "transferred... " + stop_service pihole-FTL install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL - touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port - chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port cd "${orig_dir}" + install -T -m 0755 "/etc/.pihole/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" + update-rc.d pihole-FTL defaults + # startup on boot + update-rc.d pihole-FTL enable echo "done." return 0 else @@ -1384,6 +1387,9 @@ main() { runGravity + start_service pihole-FTL + enable_service pihole-FTL + echo "::: done." if [[ "${useUpdateVars}" == false ]]; then From 77b3764481197578d692df915537dd0e9556a4e5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 11:23:01 +0100 Subject: [PATCH 040/165] Remove resundant code (FTL will later be enabled by enable_service) --- automated install/basic-install.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8a135e9bad..fb9842c900 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1178,9 +1178,6 @@ FTLinstall() { install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL cd "${orig_dir}" install -T -m 0755 "/etc/.pihole/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" - update-rc.d pihole-FTL defaults - # startup on boot - update-rc.d pihole-FTL enable echo "done." return 0 else From e9b50442fa498781c0423db036db15c1ead015d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 11:25:18 +0100 Subject: [PATCH 041/165] Remove test_FTL_support_files_installed as we create them using the init.d script as of now --- test/test_automated_install.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index b42262dee3..ac463d78c0 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -388,19 +388,19 @@ def test_FTL_binary_installed_and_responsive_no_errors(Pihole): expected_stdout = 'v' assert expected_stdout in installed_binary.stdout -def test_FTL_support_files_installed(Pihole): - ''' confirms FTL support files are installed ''' - support_files = Pihole.run(''' - source /opt/pihole/basic-install.sh - FTLdetect - stat -c '%a %n' /var/log/pihole-FTL.log - stat -c '%a %n' /run/pihole-FTL.port - stat -c '%a %n' /run/pihole-FTL.pid - ls -lac /run - ''') - assert '644 /run/pihole-FTL.port' in support_files.stdout - assert '644 /run/pihole-FTL.pid' in support_files.stdout - assert '644 /var/log/pihole-FTL.log' in support_files.stdout +# def test_FTL_support_files_installed(Pihole): +# ''' confirms FTL support files are installed ''' +# support_files = Pihole.run(''' +# source /opt/pihole/basic-install.sh +# FTLdetect +# stat -c '%a %n' /var/log/pihole-FTL.log +# stat -c '%a %n' /run/pihole-FTL.port +# stat -c '%a %n' /run/pihole-FTL.pid +# ls -lac /run +# ''') +# assert '644 /run/pihole-FTL.port' in support_files.stdout +# assert '644 /run/pihole-FTL.pid' in support_files.stdout +# assert '644 /var/log/pihole-FTL.log' in support_files.stdout # Helper functions def mock_command(script, args, container): From 032f94afc021f6ea3dc470001311ef0b36a4362a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 11:46:31 +0100 Subject: [PATCH 042/165] Don't suppress su's output --- advanced/pihole-FTL.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index 1fcd9b0162..c161e0706a 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -27,7 +27,7 @@ start() { else touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port - su -c "/usr/bin/pihole-FTL" "$FTLUSER" &> /dev/null + su -c "/usr/bin/pihole-FTL" "$FTLUSER" echo fi } From e339f3852c30592baaebdb0b8138173af1deb900 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 11:50:08 +0100 Subject: [PATCH 043/165] Change ownership of FTL log to pihole user --- advanced/pihole-FTL.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index c161e0706a..caffd00e7d 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -9,7 +9,7 @@ # Description: Enable service provided by pihole-FTL daemon ### END INIT INFO -FTLUSER=pi +FTLUSER=pihole PIDFILE=/var/run/pihole-FTL.pid get_pid() { @@ -26,6 +26,7 @@ start() { echo "pihole-FTL is already running" else touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port + chown pihole:pihole /var/log/pihole-FTL.log chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port su -c "/usr/bin/pihole-FTL" "$FTLUSER" echo From e8fde702a0bc38195875941dc6021ea3a7ed3c25 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 11:52:07 +0100 Subject: [PATCH 044/165] Also chown the other files --- advanced/pihole-FTL.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index caffd00e7d..6e1a9786b1 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -26,7 +26,7 @@ start() { echo "pihole-FTL is already running" else touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port - chown pihole:pihole /var/log/pihole-FTL.log + chown pihole:pihole /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port su -c "/usr/bin/pihole-FTL" "$FTLUSER" echo From 4f85ace5259c10052c539db2d7fb3266bfcb3ab3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 14:46:53 +0100 Subject: [PATCH 045/165] Force pihole user to use sh-shell (instead of nologin) --- advanced/pihole-FTL.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index 6e1a9786b1..da04738bda 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -28,7 +28,7 @@ start() { touch /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port chown pihole:pihole /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port - su -c "/usr/bin/pihole-FTL" "$FTLUSER" + su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER" echo fi } From 1645677c3abec24f9ba04347efb13dd20872b260 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 16:42:52 +0100 Subject: [PATCH 046/165] Cosmetics --- 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 fb9842c900..a8bb014b6c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1174,7 +1174,7 @@ FTLinstall() { cd /tmp if sha1sum --status --quiet -c "${binary}".sha1; then echo -n "transferred... " - stop_service pihole-FTL + stop_service pihole-FTL &> /dev/null install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL cd "${orig_dir}" install -T -m 0755 "/etc/.pihole/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" From a64211123fe0ff232574fc993c27e6b5a788c2c3 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 21 Feb 2017 16:46:54 +0100 Subject: [PATCH 047/165] Some debug additions --- advanced/Scripts/piholeDebug.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 74d2f05cf6..b6b71fb729 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -317,8 +317,8 @@ testResolver() { checkProcesses() { header_write "Processes Check" - echo "::: Logging status of lighttpd and dnsmasq..." - PROCESSES=( lighttpd dnsmasq ) + echo "::: Logging status of lighttpd, dnsmasq and pihole-FTL..." + PROCESSES=( lighttpd dnsmasq pihole-FTL ) for i in "${PROCESSES[@]}"; do log_write "" log_write "${i}" @@ -360,6 +360,7 @@ ip_check daemon_check lighttpd http daemon_check dnsmasq domain +daemon_check pihole-FTL 4711 checkProcesses testResolver debugLighttpd From 4dcee5cd84dd28c9fc10c47560ae97cb91f8f0ac Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 21 Feb 2017 09:14:49 -0800 Subject: [PATCH 048/165] `arch` is not portable. Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a8bb014b6c..3f8122cd4c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1199,11 +1199,11 @@ FTLdetect() { local machine local binary - machine=$(arch) + machine=$(uname -m) if [[ $machine == arm* || $machine == *aarch* ]]; then # ARM - local rev=$(arch | sed "s/[^0-9]//g;") + local rev=$(uname -m | sed "s/[^0-9]//g;") local lib=$(ldd /bin/ls | grep -E '^\s*/lib' | awk '{ print $1 }') if [[ "$lib" == "/lib/ld-linux-aarch64.so.1" ]]; then echo "::: Detected ARM-aarch64 architecture" From dcb9797f35134a94bbb5b009b1851e1f0b9ff1ca Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 21 Feb 2017 09:24:00 -0800 Subject: [PATCH 049/165] Tests changed to reflect `uname` calls. Signed-off-by: Dan Schaper --- test/test_automated_install.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index ac463d78c0..19c662c69c 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -300,7 +300,7 @@ def test_update_package_cache_failure_no_errors(Pihole): def test_FTL_detect_aarch64_no_errors(Pihole): ''' confirms only aarch64 package is downloaded for FTL engine ''' # mock uname to return aarch64 platform - mock_command('arch', {'*':('aarch64', '0')}, Pihole) + mock_command('uname', {'-m':('aarch64', '0')}, Pihole) # mock ldd to respond with aarch64 shared library mock_command('ldd', {'/bin/ls':('/lib/ld-linux-aarch64.so.1', '0')}, Pihole) detectPlatform = Pihole.run(''' @@ -313,7 +313,7 @@ def test_FTL_detect_aarch64_no_errors(Pihole): def test_FTL_detect_armv6l_no_errors(Pihole): ''' confirms only armv6l package is downloaded for FTL engine ''' # mock uname to return armv6l platform - mock_command('arch', {'*':('armv6l', '0')}, Pihole) + mock_command('uname', {'-m':('armv6l', '0')}, Pihole) # mock ldd to respond with aarch64 shared library mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' @@ -326,7 +326,7 @@ def test_FTL_detect_armv6l_no_errors(Pihole): def test_FTL_detect_armv7l_no_errors(Pihole): ''' confirms only armv7l package is downloaded for FTL engine ''' # mock uname to return armv7l platform - mock_command('arch', {'*':('armv7l', '0')}, Pihole) + mock_command('uname', {'-m':('armv7l', '0')}, Pihole) # mock ldd to respond with aarch64 shared library mock_command('ldd', {'/bin/ls':('/lib/ld-linux-armhf.so.3', '0')}, Pihole) detectPlatform = Pihole.run(''' @@ -348,7 +348,7 @@ def test_FTL_detect_x86_64_no_errors(Pihole): def test_FTL_detect_unknown_no_errors(Pihole): ''' confirms only generic package is downloaded for FTL engine ''' # mock uname to return generic platform - mock_command('arch', {'*':('mips', '0')}, Pihole) + mock_command('uname', {'-m':('mips', '0')}, Pihole) detectPlatform = Pihole.run(''' source /opt/pihole/basic-install.sh FTLdetect From af2893d2ce3b4279d74f67813ca0a10e2a3a4e98 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 22 Feb 2017 10:43:13 +0100 Subject: [PATCH 050/165] Updater implementation for FTL --- advanced/Scripts/update.sh | 27 +++++++++++++++++++++++++++ automated install/basic-install.sh | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 10847ead1d..b5a7e1a45b 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -75,6 +75,18 @@ GitCheckUpdateAvail() { fi } +FTLcheckUpdate() { + + local FTLversion=$(/usr/bin/pihole-FTL tag) + local FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep 'Location' | awk -F '/' '{print $NF}' | tr -d '\r\n') + + if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then + return 0 + else + return 1 + fi +} + main() { local pihole_version_current local web_version_current @@ -96,6 +108,21 @@ main() { echo "::: Pi-hole Core: up to date" fi + if FTLcheckUpdate ; then + FTL_update=true + echo "::: FTL: update available" + else + FTL_update=false + echo "::: FTL: up to date" + fi + + if ${FTL_update}; then + echo ":::" + echo "::: FTL out of date" + FTLdetect + echo ":::" + fi + if [[ ${INSTALL_WEB} == true ]]; then if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then echo "::: Critical Error: Web Admin repo is missing from system!" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3f8122cd4c..e784ab1855 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1157,8 +1157,7 @@ FTLinstall() { local binary="${1}" local latesttag local orig_dir - echo ":::" - echo -n "::: Installing FTL... " + echo -n "::: Installing FTL... " orig_dir="${PWD}" latesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep "Location" | awk -F '/' '{print $NF}') From 078cc7660e7d9d953a891172439a464a2060e634 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 22 Feb 2017 11:00:45 +0100 Subject: [PATCH 051/165] Improved updater logic --- advanced/Scripts/update.sh | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index b5a7e1a45b..2a384217b6 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -149,9 +149,11 @@ main() { # pull pihole repo run install --unattended if ! ${core_update} && ! ${web_update} ; then - echo ":::" - echo "::: Everything is up to date!" - exit 0 + if ! ${FTL_update} ; then + echo ":::" + echo "::: Everything is up to date!" + exit 0 + fi elif ! ${core_update} && ${web_update} ; then echo ":::" @@ -166,7 +168,7 @@ main() { elif ${core_update} && ${web_update} ; then echo ":::" - echo "::: Updating Everything" + echo "::: Updating Pi-hole core and web admin files" getGitFiles "${PI_HOLE_FILES_DIR}" "${PI_HOLE_GIT_URL}" ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 else @@ -175,9 +177,11 @@ main() { fi else # Web Admin not installed, so only verify if core is up to date if ! ${core_update}; then - echo ":::" - echo "::: Everything is up to date!" - exit 0 + if ! ${FTL_update} ; then + echo ":::" + echo "::: Everything is up to date!" + exit 0 + fi else echo ":::" echo "::: Pi-hole core files out of date" @@ -200,6 +204,15 @@ main() { echo "::: If you had made any changes in '/etc/.pihole/', they have been stashed using 'git stash'" fi + if [[ ${FTL_update} == true ]]; then + FTL_version_current="$(/usr/bin/pihole-FTL tag)" + echo ":::" + echo "::: FTL version is now at ${FTL_version_current}" + start_service pihole-FTL + enable_service pihole-FTL + fi + + echo "" exit 0 From 24fd23493dd5cc3895a84f9668796039a96b7385 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 2 Mar 2017 15:54:58 -0800 Subject: [PATCH 052/165] Exit script immediately if we can't update package cache. Signed-off-by: Dan Schaper --- 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 219b08cb80..713f83379e 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -741,7 +741,8 @@ update_package_cache() { if eval ${UPDATE_PKG_CACHE} &> /dev/null; then echo " done!" else - echo -n "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" + echo -en "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" + return 1 fi } @@ -1209,7 +1210,7 @@ main() { fi # Update package cache - update_package_cache + update_package_cache || exit 1 # Notify user of package availability notify_package_updates_available From 2c762899de062300958017d0ba905d5ea995e9f5 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Mar 2017 11:28:35 +0100 Subject: [PATCH 053/165] Add loop to wait if package manager is blocked externally --- automated install/basic-install.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 219b08cb80..878ac31948 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -59,7 +59,7 @@ distro_check() { if command -v apt-get &> /dev/null; then #Debian Family ############################################# - PKG_MANAGER="apt-get" + PKG_MANAGER="test_dpkg_lock; apt-get" UPDATE_PKG_CACHE="${PKG_MANAGER} update" PKG_INSTALL=(${PKG_MANAGER} --yes --no-install-recommends install) # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE @@ -87,6 +87,32 @@ if command -v apt-get &> /dev/null; then LIGHTTPD_CFG="lighttpd.conf.debian" DNSMASQ_USER="dnsmasq" + test_dpkg_lock() { + i=0 + while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do + echo -en "\r::: Waiting for package manager to finish" + j=0 + while [ $j -lt 6 ]; do + if [ $j -lt $i ]; then + echo -n "." + else + echo -n " " + fi + ((j=j+1)) + done + sleep 0.5 + if [ $i -lt 6 ]; then + ((i=i+1)) + else + i=0 + fi + done + # Add final newline only if we entered the loop at least once + if [ $j -gt 0 ]; then + echo "" + fi + } + elif command -v rpm &> /dev/null; then # Fedora Family if command -v dnf &> /dev/null; then From a535ca9db4504dc75c57097fec57b123d6b2ce90 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Mar 2017 11:35:44 +0100 Subject: [PATCH 054/165] Some tweaks to the new dpkg lock detector --- automated install/basic-install.sh | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 878ac31948..19e23c167d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -90,27 +90,12 @@ if command -v apt-get &> /dev/null; then test_dpkg_lock() { i=0 while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do - echo -en "\r::: Waiting for package manager to finish" - j=0 - while [ $j -lt 6 ]; do - if [ $j -lt $i ]; then - echo -n "." - else - echo -n " " - fi - ((j=j+1)) - done sleep 0.5 - if [ $i -lt 6 ]; then - ((i=i+1)) - else - i=0 - fi + ((i=i+1)) done - # Add final newline only if we entered the loop at least once - if [ $j -gt 0 ]; then - echo "" - fi + # Always return success, since we only return if there is no + # lock (anymore) + return 0 } elif command -v rpm &> /dev/null; then @@ -764,7 +749,7 @@ update_package_cache() { echo ":::" echo -n "::: Updating local cache of available packages..." - if eval ${UPDATE_PKG_CACHE} &> /dev/null; then + if eval "${UPDATE_PKG_CACHE}" &> /dev/null; then echo " done!" else echo -n "\n!!! ERROR - Unable to update package cache. Please try \"${UPDATE_PKG_CACHE}\"" From 95023569803115e9cf913c0878b018f91c0a7429 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 3 Mar 2017 11:52:49 +0100 Subject: [PATCH 055/165] Move test_dpkg_lock to initial UPDATE_PKG_CACHE. There was unpredictable interference with debconf-apt-progress --- 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 19e23c167d..57c49233cf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -59,8 +59,8 @@ distro_check() { if command -v apt-get &> /dev/null; then #Debian Family ############################################# - PKG_MANAGER="test_dpkg_lock; apt-get" - UPDATE_PKG_CACHE="${PKG_MANAGER} update" + PKG_MANAGER="apt-get" + UPDATE_PKG_CACHE="test_dpkg_lock; ${PKG_MANAGER} update" PKG_INSTALL=(${PKG_MANAGER} --yes --no-install-recommends install) # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" @@ -799,6 +799,7 @@ install_dependent_packages() { fi done if [[ ${#installArray[@]} -gt 0 ]]; then + test_dpkg_lock debconf-apt-progress -- "${PKG_INSTALL[@]}" "${installArray[@]}" return fi From 81939ab265f9b85516f673df3b3b13467371ded7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 19:14:30 -0800 Subject: [PATCH 056/165] Get short hash of local and remote Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 11a7af0053..271665071b 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -17,11 +17,34 @@ current=false DEFAULT="-1" normalOutput() { - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) + piholeVersion=$(cd /etc/.pihole/ \ + && git describe --tags --abbrev=0) + webVersion=$(cd /var/www/html/admin/ \ + && git describe --tags --abbrev=0) - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') + piholeHash=$(cd /etc/.pihole/ \ + && git rev-parse --short HEAD) + webHash=$(cd /var/www/html/admin/ \ + && git rev-parse --short HEAD) + + piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ + grep -Po '"tag_name":.*?[^\\]",' | \ + perl -pe 's/"tag_name": "//; s/^"//; s/",$//') + webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \ + grep -Po '"tag_name":.*?[^\\]",' | \ + perl -pe 's/"tag_name": "//; s/^"//; s/",$//') + + piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ + grep sha | \ + head -n1 | \ + awk -F ' ' '{ print $2}' | \ + tr -cd '[[:alnum:]]._-') + + piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ + grep sha | \ + head -n1 | \ + awk -F ' ' '{ print $2}' | \ + tr -cd '[[:alnum:]]._-') echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" From ebfffea5dce3befd2ea6a1067228c5069a96cc64 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 20:04:55 -0800 Subject: [PATCH 057/165] Always show something, even if it's just the short hash of the latest commit. Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 271665071b..3a04d2ec09 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -8,8 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - # Flags: latest=false current=false @@ -18,9 +16,9 @@ DEFAULT="-1" normalOutput() { piholeVersion=$(cd /etc/.pihole/ \ - && git describe --tags --abbrev=0) + && git describe --tags --always) webVersion=$(cd /var/www/html/admin/ \ - && git describe --tags --abbrev=0) + && git describe --tags --always) piholeHash=$(cd /etc/.pihole/ \ && git rev-parse --short HEAD) From 9bb4a5fb253957a2969decc48f80ee115d315e4e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 20:16:53 -0800 Subject: [PATCH 058/165] Factor out variables from display. Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 77 ++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 3a04d2ec09..a094ba16b1 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -12,40 +12,39 @@ latest=false current=false +# Variables DEFAULT="-1" +PHVERSION=$(cd /etc/.pihole/ \ + && git describe --tags --always) +WEBVERSION=$(cd /var/www/html/admin/ \ + && git describe --tags --always) -normalOutput() { - piholeVersion=$(cd /etc/.pihole/ \ - && git describe --tags --always) - webVersion=$(cd /var/www/html/admin/ \ - && git describe --tags --always) - - piholeHash=$(cd /etc/.pihole/ \ - && git rev-parse --short HEAD) - webHash=$(cd /var/www/html/admin/ \ - && git rev-parse --short HEAD) +PHHASH=$(cd /etc/.pihole/ \ + && git rev-parse --short HEAD) +WEBHASH=$(cd /var/www/html/admin/ \ + && git rev-parse --short HEAD) - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ - grep -Po '"tag_name":.*?[^\\]",' | \ - perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \ - grep -Po '"tag_name":.*?[^\\]",' | \ - perl -pe 's/"tag_name": "//; s/^"//; s/",$//') +PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ + grep -Po '"tag_name":.*?[^\\]",' | \ + perl -pe 's/"tag_name": "//; s/^"//; s/",$//') +WEBVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \ + grep -Po '"tag_name":.*?[^\\]",' | \ + perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ - grep sha | \ - head -n1 | \ - awk -F ' ' '{ print $2}' | \ - tr -cd '[[:alnum:]]._-') +PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ + grep sha | \ + head -n1 | \ + awk -F ' ' '{ print $2}' | \ + tr -cd '[[:alnum:]]._-') - piholeHashLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ - grep sha | \ - head -n1 | \ - awk -F ' ' '{ print $2}' | \ - tr -cd '[[:alnum:]]._-') - - echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" - echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" +WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ + grep sha | \ + head -n1 | \ + awk -F ' ' '{ print $2}' | \ + tr -cd '[[:alnum:]]._-') +normalOutput() { + echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" + echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" } webOutput() { @@ -58,15 +57,11 @@ webOutput() { done if [[ "${latest}" == true && "${current}" == false ]]; then - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "${webVersionLatest:--1}" + echo "${WEBVERSIONLATEST:--1}" elif [[ "${latest}" == false && "${current}" == true ]]; then - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - echo "${webVersion}" + echo "${WEBVERSION}" else - webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) - webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest:-${DEFAULT}})" + echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" fi } @@ -80,15 +75,11 @@ coreOutput() { done if [[ "${latest}" == true && "${current}" == false ]]; then - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "${piholeVersionLatest:--1}" + echo "${PHVERSIONLATEST:--1}" elif [[ "${latest}" == false && "${current}" == true ]]; then - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - echo "${piholeVersion}" + echo "${PHVERSION}" else - piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) - piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest:-${DEFAULT}})" + echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" fi } From 0341bd175871f2e6bdc6dce5c3ca8c0aa500f2b6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 20:32:26 -0800 Subject: [PATCH 059/165] Optimize code, undoc flag for current hash. Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index a094ba16b1..b8876fc804 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -50,37 +50,23 @@ normalOutput() { webOutput() { for var in "$@"; do case "${var}" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; + "-l" | "--latest" ) echo "${WEBVERSIONLATEST:--1}";; + "-c" | "--current" ) echo "${WEBVERSION}";; + "-h" | "--hash" ) echo "${WEBHASH}";; * ) echo "::: Invalid Option!"; exit 1; esac done - - if [[ "${latest}" == true && "${current}" == false ]]; then - echo "${WEBVERSIONLATEST:--1}" - elif [[ "${latest}" == false && "${current}" == true ]]; then - echo "${WEBVERSION}" - else - echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" - fi } coreOutput() { for var in "$@"; do case "${var}" in - "-l" | "--latest" ) latest=true;; - "-c" | "--current" ) current=true;; + "-l" | "--latest" ) echo "${PHVERSIONLATEST:--1}";; + "-c" | "--current" ) echo "${PHVERSION}";; + "-h" | "--hash" ) echo "${PHHASH}";; * ) echo "::: Invalid Option!"; exit 1; esac done - - if [[ "${latest}" == true && "${current}" == false ]]; then - echo "${PHVERSIONLATEST:--1}" - elif [[ "${latest}" == false && "${current}" == true ]]; then - echo "${PHVERSION}" - else - echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" - fi } helpFunc() { From 8831b22fc89a0aba2cf75c5cd86644ac760a301f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 21:36:38 -0800 Subject: [PATCH 060/165] Prototype function for getting version of local repo Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index b8876fc804..3bd9d4d289 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -14,8 +14,26 @@ current=false # Variables DEFAULT="-1" -PHVERSION=$(cd /etc/.pihole/ \ - && git describe --tags --always) +PHGITDIR="/etc/.pihole/" +WEBGITDIR="/var/www/html/admin/" + +getLocalPHVersion(){ + # Get the tagged version of the local Pi-hole repository + local version + + cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return -1; } + version=$(git describe --tags --always || \ + echo "${DEFAULT}") + if [[ "${version}" =~ ^v ]]; then + PHVERSION="${version}" + elif [[ "${version}" == "-1" ]]; then + PHVERSION="ERROR" + else + PHVERSION="Untagged" + fi + return 0 +} + WEBVERSION=$(cd /var/www/html/admin/ \ && git describe --tags --always) @@ -42,16 +60,18 @@ WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/ma head -n1 | \ awk -F ' ' '{ print $2}' | \ tr -cd '[[:alnum:]]._-') + + normalOutput() { echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" - echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" + echo "::: Web-Admin version is ${WEBVERSION:-Untagged} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" } webOutput() { for var in "$@"; do case "${var}" in - "-l" | "--latest" ) echo "${WEBVERSIONLATEST:--1}";; - "-c" | "--current" ) echo "${WEBVERSION}";; + "-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";; + "-c" | "--current" ) echo "${WEBVERSION:-Untagged}";; "-h" | "--hash" ) echo "${WEBHASH}";; * ) echo "::: Invalid Option!"; exit 1; esac @@ -61,7 +81,7 @@ webOutput() { coreOutput() { for var in "$@"; do case "${var}" in - "-l" | "--latest" ) echo "${PHVERSIONLATEST:--1}";; + "-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";; "-c" | "--current" ) echo "${PHVERSION}";; "-h" | "--hash" ) echo "${PHHASH}";; * ) echo "::: Invalid Option!"; exit 1; @@ -87,6 +107,8 @@ EOM exit 0 } +getLocalPHVersion + if [[ $# = 0 ]]; then normalOutput fi From ed8088f20377be8eb9918f7c1b0f732415486499 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 22:10:32 -0800 Subject: [PATCH 061/165] Functions for Core/Web version and hash. And only check first argument in each section. Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 58 ++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 3bd9d4d289..edcb8958f9 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -8,10 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -# Flags: -latest=false -current=false - # Variables DEFAULT="-1" PHGITDIR="/etc/.pihole/" @@ -20,27 +16,54 @@ WEBGITDIR="/var/www/html/admin/" getLocalPHVersion(){ # Get the tagged version of the local Pi-hole repository local version + local hash - cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return -1; } + cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return 1; } version=$(git describe --tags --always || \ echo "${DEFAULT}") if [[ "${version}" =~ ^v ]]; then PHVERSION="${version}" - elif [[ "${version}" == "-1" ]]; then + elif [[ "${version}" == "${DEFAULT}" ]]; then PHVERSION="ERROR" else PHVERSION="Untagged" fi + + hash=$(git rev-parse --short HEAD || \ + echo "${DEFAULT}") + if [[ "${hash}" == "${DEFAULT}" ]]; then + PHHASH="ERROR" + else + PHHASH="${hash}" + fi return 0 } -WEBVERSION=$(cd /var/www/html/admin/ \ - && git describe --tags --always) +getLocalWebVersion(){ + # Get the tagged version of the local Pi-hole repository + local version + local hash + + cd "${WEBGITDIR}" || { WEBVERSION="${DEFAULT}"; return 1; } + version=$(git describe --tags --always || \ + echo "${DEFAULT}") + if [[ "${version}" =~ ^v ]]; then + WEBVERSION="${version}" + elif [[ "${version}" == "${DEFAULT}" ]]; then + WEBVERSION="ERROR" + else + WEBVERSION="Untagged" + fi -PHHASH=$(cd /etc/.pihole/ \ - && git rev-parse --short HEAD) -WEBHASH=$(cd /var/www/html/admin/ \ - && git rev-parse --short HEAD) + hash=$(git rev-parse --short HEAD || \ + echo "${DEFAULT}") + if [[ "${hash}" == "${DEFAULT}" ]]; then + WEBHASH="ERROR" + else + WEBHASH="${hash}" + fi + return 0 +} PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ grep -Po '"tag_name":.*?[^\\]",' | \ @@ -64,14 +87,14 @@ WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/ma normalOutput() { echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" - echo "::: Web-Admin version is ${WEBVERSION:-Untagged} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" + echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" } webOutput() { - for var in "$@"; do + for var in "$1"; do case "${var}" in "-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";; - "-c" | "--current" ) echo "${WEBVERSION:-Untagged}";; + "-c" | "--current" ) echo "${WEBVERSION}";; "-h" | "--hash" ) echo "${WEBHASH}";; * ) echo "::: Invalid Option!"; exit 1; esac @@ -79,7 +102,7 @@ webOutput() { } coreOutput() { - for var in "$@"; do + for var in "$1"; do case "${var}" in "-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";; "-c" | "--current" ) echo "${PHVERSION}";; @@ -108,12 +131,13 @@ EOM } getLocalPHVersion +getLocalWebVersion if [[ $# = 0 ]]; then normalOutput fi -for var in "$@"; do +for var in "$1"; do case "${var}" in "-a" | "--admin" ) shift; webOutput "$@";; "-p" | "--pihole" ) shift; coreOutput "$@" ;; From 77ab47a9849bb0491e30bd437cf112791098836b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 22:34:55 -0800 Subject: [PATCH 062/165] Awk for perl Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index edcb8958f9..d930b8a201 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -66,23 +66,23 @@ getLocalWebVersion(){ } PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ - grep -Po '"tag_name":.*?[^\\]",' | \ - perl -pe 's/"tag_name": "//; s/^"//; s/",$//') + awk -F: '$1 ~/tag_name/ { print $2 }' | \ + tr -cd '[[:alnum:]]._-') WEBVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \ - grep -Po '"tag_name":.*?[^\\]",' | \ - perl -pe 's/"tag_name": "//; s/^"//; s/",$//') - -PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ - grep sha | \ - head -n1 | \ - awk -F ' ' '{ print $2}' | \ - tr -cd '[[:alnum:]]._-') - -WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ - grep sha | \ - head -n1 | \ - awk -F ' ' '{ print $2}' | \ - tr -cd '[[:alnum:]]._-') + awk -F: '$1 ~/tag_name/ { print $2 }' | \ + tr -cd '[[:alnum:]]._-') + +#PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ +# grep sha | \ +# head -n1 | \ +# awk -F ' ' '{ print $2 }' | \ +# tr -cd '[[:alnum:]]._-') + +#WEBHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/commits/master | \ +# grep sha | \ +# head -n1 | \ +# awk -F ' ' '{ print $2 }' | \ +# tr -cd '[[:alnum:]]._-') normalOutput() { From 945e22874e260d1be8d6fd453c8142ff68d30dd5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 23:12:28 -0800 Subject: [PATCH 063/165] Collapse duplicate functions, and take out argument loops. Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 93 +++++++++++++++---------------------- 1 file changed, 37 insertions(+), 56 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index d930b8a201..3089e00c7e 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -13,54 +13,38 @@ DEFAULT="-1" PHGITDIR="/etc/.pihole/" WEBGITDIR="/var/www/html/admin/" -getLocalPHVersion(){ - # Get the tagged version of the local Pi-hole repository +getLocalVersion() { + # Get the tagged version of the local repository + local directory="${1}" local version - local hash - cd "${PHGITDIR}" || { PHVERSION="${DEFAULT}"; return 1; } + cd "${directory}" || { echo "${DEFAULT}"; return 1; } version=$(git describe --tags --always || \ echo "${DEFAULT}") if [[ "${version}" =~ ^v ]]; then - PHVERSION="${version}" + echo "${version}" elif [[ "${version}" == "${DEFAULT}" ]]; then - PHVERSION="ERROR" - else - PHVERSION="Untagged" - fi - - hash=$(git rev-parse --short HEAD || \ - echo "${DEFAULT}") - if [[ "${hash}" == "${DEFAULT}" ]]; then - PHHASH="ERROR" + echo "ERROR" + return 1 else - PHHASH="${hash}" + echo "Untagged" fi return 0 } -getLocalWebVersion(){ - # Get the tagged version of the local Pi-hole repository - local version +getLocalHash() { + # Get the short hash of the local repository + local directory="${1}" local hash - cd "${WEBGITDIR}" || { WEBVERSION="${DEFAULT}"; return 1; } - version=$(git describe --tags --always || \ - echo "${DEFAULT}") - if [[ "${version}" =~ ^v ]]; then - WEBVERSION="${version}" - elif [[ "${version}" == "${DEFAULT}" ]]; then - WEBVERSION="ERROR" - else - WEBVERSION="Untagged" - fi - + cd "${directory}" || { echo "${DEFAULT}"; return 1; } hash=$(git rev-parse --short HEAD || \ echo "${DEFAULT}") if [[ "${hash}" == "${DEFAULT}" ]]; then - WEBHASH="ERROR" + echo "ERROR" + return 1 else - WEBHASH="${hash}" + echo "${hash}" fi return 0 } @@ -91,25 +75,21 @@ normalOutput() { } webOutput() { - for var in "$1"; do - case "${var}" in - "-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";; - "-c" | "--current" ) echo "${WEBVERSION}";; - "-h" | "--hash" ) echo "${WEBHASH}";; - * ) echo "::: Invalid Option!"; exit 1; - esac - done + case "${1}" in + "-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";; + "-c" | "--current" ) echo "${WEBVERSION}";; + "-h" | "--hash" ) echo "${WEBHASH}";; + * ) echo "::: Invalid Option!"; exit 1; + esac } coreOutput() { - for var in "$1"; do - case "${var}" in - "-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";; - "-c" | "--current" ) echo "${PHVERSION}";; - "-h" | "--hash" ) echo "${PHHASH}";; - * ) echo "::: Invalid Option!"; exit 1; - esac - done + case "${1}" in + "-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";; + "-c" | "--current" ) echo "${PHVERSION}";; + "-h" | "--hash" ) echo "${PHHASH}";; + * ) echo "::: Invalid Option!"; exit 1; + esac } helpFunc() { @@ -130,17 +110,18 @@ EOM exit 0 } -getLocalPHVersion -getLocalWebVersion +PHVERSION=$(getLocalVersion "${PHGITDIR}") +PHHASH=$(getLocalHash "${PHGITDIR}") +WEBVERSION=$(getLocalVersion "${WEBGITDIR}") +WEBHASH=$(getLocalHash "${WEBGITDIR}") + if [[ $# = 0 ]]; then normalOutput fi -for var in "$1"; do - case "${var}" in - "-a" | "--admin" ) shift; webOutput "$@";; - "-p" | "--pihole" ) shift; coreOutput "$@" ;; - "-h" | "--help" ) helpFunc;; - esac -done +case "${1}" in + "-a" | "--admin" ) shift; webOutput "$@";; + "-p" | "--pihole" ) shift; coreOutput "$@" ;; + "-h" | "--help" ) helpFunc;; +esac From 0e8fd49669e5b5018439597585da424b516f9f57 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 3 Mar 2017 23:30:57 -0800 Subject: [PATCH 064/165] Function... Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 3089e00c7e..68e849005b 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -49,12 +49,22 @@ getLocalHash() { return 0 } -PHVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | \ - awk -F: '$1 ~/tag_name/ { print $2 }' | \ - tr -cd '[[:alnum:]]._-') -WEBVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | \ - awk -F: '$1 ~/tag_name/ { print $2 }' | \ - tr -cd '[[:alnum:]]._-') +getRemoteVersion(){ + # Get the version from the remote origin + local daemon="${1}" + local version + + version=$(curl --silent --fail https://api.github.com/repos/pi-hole/${daemon}/releases/latest | \ + awk -F: '$1 ~/tag_name/ { print $2 }' | \ + tr -cd '[[:alnum:]]._-') + if [[ "${version}" =~ ^v ]]; then + echo "${version}" + else + echo "ERROR" + return 1 + fi + return 0 +} #PHHASHLATEST=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/commits/master | \ # grep sha | \ @@ -70,13 +80,13 @@ WEBVERSIONLATEST=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/release normalOutput() { - echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST:-${DEFAULT}})" - echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST:-${DEFAULT}})" + echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST})" + echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST})" } webOutput() { case "${1}" in - "-l" | "--latest" ) echo "${WEBVERSIONLATEST:-${DEFAULT}}";; + "-l" | "--latest" ) echo "${WEBVERSIONLATEST}";; "-c" | "--current" ) echo "${WEBVERSION}";; "-h" | "--hash" ) echo "${WEBHASH}";; * ) echo "::: Invalid Option!"; exit 1; @@ -85,7 +95,7 @@ webOutput() { coreOutput() { case "${1}" in - "-l" | "--latest" ) echo "${PHVERSIONLATEST:-${DEFAULT}}";; + "-l" | "--latest" ) echo "${PHVERSIONLATEST}";; "-c" | "--current" ) echo "${PHVERSION}";; "-h" | "--hash" ) echo "${PHHASH}";; * ) echo "::: Invalid Option!"; exit 1; @@ -112,9 +122,10 @@ EOM PHVERSION=$(getLocalVersion "${PHGITDIR}") PHHASH=$(getLocalHash "${PHGITDIR}") +PHVERSIONLATEST=$(getRemoteVersion pi-hole) WEBVERSION=$(getLocalVersion "${WEBGITDIR}") WEBHASH=$(getLocalHash "${WEBGITDIR}") - +WEBVERSIONLATEST=$(getRemoteVersion AdminLTE) if [[ $# = 0 ]]; then normalOutput From b85af50d14381dc7eab4e0688af44baba8fd7f3d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 4 Mar 2017 14:08:11 +0100 Subject: [PATCH 065/165] Generate only the information that is actually asked for --- advanced/Scripts/version.sh | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 68e849005b..5674bce1bf 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -86,18 +86,18 @@ normalOutput() { webOutput() { case "${1}" in - "-l" | "--latest" ) echo "${WEBVERSIONLATEST}";; - "-c" | "--current" ) echo "${WEBVERSION}";; - "-h" | "--hash" ) echo "${WEBHASH}";; + "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; + "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; * ) echo "::: Invalid Option!"; exit 1; esac } coreOutput() { case "${1}" in - "-l" | "--latest" ) echo "${PHVERSIONLATEST}";; - "-c" | "--current" ) echo "${PHVERSION}";; - "-h" | "--hash" ) echo "${PHHASH}";; + "-l" | "--latest" ) echo $(getRemoteVersion pi-hole);; + "-c" | "--current" ) echo $(getLocalVersion "${PHGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${PHGITDIR}");; * ) echo "::: Invalid Option!"; exit 1; esac } @@ -120,13 +120,6 @@ EOM exit 0 } -PHVERSION=$(getLocalVersion "${PHGITDIR}") -PHHASH=$(getLocalHash "${PHGITDIR}") -PHVERSIONLATEST=$(getRemoteVersion pi-hole) -WEBVERSION=$(getLocalVersion "${WEBGITDIR}") -WEBHASH=$(getLocalHash "${WEBGITDIR}") -WEBVERSIONLATEST=$(getRemoteVersion AdminLTE) - if [[ $# = 0 ]]; then normalOutput fi From abd3e828de63f28f7853839298093c20ff0ca2e5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 07:46:00 -0800 Subject: [PATCH 066/165] Optimize normalOutput Signed-off-by: Dan Schaper --- advanced/Scripts/version.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 5674bce1bf..fd74c2de93 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -80,8 +80,8 @@ getRemoteVersion(){ normalOutput() { - echo "::: Pi-hole version is ${PHVERSION} (Latest version is ${PHVERSIONLATEST})" - echo "::: Web-Admin version is ${WEBVERSION} (Latest version is ${WEBVERSIONLATEST})" + echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" + echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" } webOutput() { From 6cd4ff6d68ba6f45b8582a878e2c751c819d178e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 11:34:34 -0800 Subject: [PATCH 067/165] Organize functions and function calls. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 137 ++++++++++++++++---------------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index a671a49f26..9ee226ac67 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -266,39 +266,42 @@ daemon_check() { testResolver() { header_write "Resolver Functions Check" + local url + local testurl + local localdig + local piholedig + # Find a blocked url that has not been whitelisted. - TESTURL="doubleclick.com" - 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}" + url=$(shuf -n 1 "${GRAVITYFILE}" | awk -F ' ' '{ print $2 }') + + testurl="${url:-doubleclick.com}" + + + log_write "Resolution of ${testurl} from Pi-hole (localhost):" + + if localdig=$(dig "${testurl}" @localhost +short); then + log_write "${localdig}" + else + log_write "Failed to resolve ${testurl} on Pi-hole" fi + log_write "" - log_write "Resolution of ${TESTURL} from Pi-hole:" - LOCALDIG=$(dig "${TESTURL}" @127.0.0.1) - if [[ $? = 0 ]]; then - log_write "${LOCALDIG}" + log_write "Resolution of ${testurl} from Pi-hole (direct IP):" + + if piholedig=$(dig "${testurl}" @"${IPV4_ADDRESS%/*}" +short); then + log_write "${piholedig}" else - log_write "Failed to resolve ${TESTURL} on Pi-hole" + log_write "Failed to resolve ${testurl} on Pi-hole" fi log_write "" - log_write "Resolution of ${TESTURL} from 8.8.8.8:" - REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8) + log_write "Resolution of ${testurl} from 8.8.8.8:" + remotedig=$(dig "${testurl}" @8.8.8.8 +short) if [[ $? = 0 ]]; then - log_write "${REMOTEDIG}" + log_write "${remotedig:-NXDOMAIN}" else - log_write "Failed to resolve ${TESTURL} on 8.8.8.8" + log_write "Failed to resolve ${testurl} on 8.8.8.8" fi log_write "" @@ -347,50 +350,6 @@ countdown() { tuvix=$(( tuvix - 5 )) done } -### END FUNCTIONS ### - -# Gather version of required packages / repositories -version_check || echo "REQUIRED FILES MISSING" -# Check for newer setupVars storage file -source_file "/etc/pihole/setupVars.conf" -# Gather information about the running distribution -distro_check || echo "Distro Check soft fail" -# Gather processor type -processor_check || echo "Processor Check soft fail" - -ip_check 6 ${IPV6_ADDRESS} -ip_check 4 ${IPV4_ADDRESS} - -daemon_check lighttpd http -daemon_check dnsmasq domain -daemon_check pihole-FTL 4711 -checkProcesses -testResolver -debugLighttpd - -files_check "${DNSMASQFILE}" -dir_check "${DNSMASQCONFDIR}" -files_check "${WHITELISTFILE}" -files_check "${BLACKLISTFILE}" -files_check "${ADLISTFILE}" - - -header_write "Analyzing gravity.list" - - gravity_length=$(grep -c ^ "${GRAVITYFILE}") \ - && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ - || log_echo "Warning: No gravity.list file found!" - -header_write "Analyzing pihole.log" - - pihole_length=$(grep -c ^ "${PIHOLELOG}") \ - && log_write "${PIHOLELOG} is ${pihole_length} lines long." \ - || log_echo "Warning: No pihole.log file found!" - - pihole_size=$(du -h "${PIHOLELOG}" | awk '{ print $1 }') \ - && log_write "${PIHOLELOG} is ${pihole_size}." \ - || log_echo "Warning: No pihole.log file found!" - # Continuously append the pihole.log file to the pihole_debug.log file dumpPiHoleLog() { @@ -440,6 +399,50 @@ finalWork() { echo "::: A local copy of the Debug log can be found at : /var/log/pihole_debug.log" } +### END FUNCTIONS ### + +# Gather version of required packages / repositories +version_check || echo "REQUIRED FILES MISSING" +# Check for newer setupVars storage file +source_file "/etc/pihole/setupVars.conf" +# Gather information about the running distribution +distro_check || echo "Distro Check soft fail" +# Gather processor type +processor_check || echo "Processor Check soft fail" + +ip_check 6 ${IPV6_ADDRESS} +ip_check 4 ${IPV4_ADDRESS} + +daemon_check lighttpd http +daemon_check dnsmasq domain +daemon_check pihole-FTL 4711 +checkProcesses +testResolver +debugLighttpd + +files_check "${DNSMASQFILE}" +dir_check "${DNSMASQCONFDIR}" +files_check "${WHITELISTFILE}" +files_check "${BLACKLISTFILE}" +files_check "${ADLISTFILE}" + + +header_write "Analyzing gravity.list" + + gravity_length=$(grep -c ^ "${GRAVITYFILE}") \ + && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ + || log_echo "Warning: No gravity.list file found!" + +header_write "Analyzing pihole.log" + + pihole_length=$(grep -c ^ "${PIHOLELOG}") \ + && log_write "${PIHOLELOG} is ${pihole_length} lines long." \ + || log_echo "Warning: No pihole.log file found!" + + pihole_size=$(du -h "${PIHOLELOG}" | awk '{ print $1 }') \ + && log_write "${PIHOLELOG} is ${pihole_size}." \ + || log_echo "Warning: No pihole.log file found!" + trap finalWork EXIT ### Method calls for additional logging ### From 709b44f7365717a58136d4140954b212dd830051 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 12:16:16 -0800 Subject: [PATCH 068/165] IPv4 DNS tests Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 9ee226ac67..484cb737b5 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -265,11 +265,13 @@ daemon_check() { testResolver() { header_write "Resolver Functions Check" - + local protocol="${1}" + local IP="${2}" local url local testurl local localdig local piholedig + local remotedig # Find a blocked url that has not been whitelisted. url=$(shuf -n 1 "${GRAVITYFILE}" | awk -F ' ' '{ print $2 }') @@ -278,8 +280,7 @@ testResolver() { log_write "Resolution of ${testurl} from Pi-hole (localhost):" - - if localdig=$(dig "${testurl}" @localhost +short); then + if localdig=$(dig -"${protocol}" "${testurl}" @localhost +short); then log_write "${localdig}" else log_write "Failed to resolve ${testurl} on Pi-hole" @@ -287,8 +288,7 @@ testResolver() { log_write "" log_write "Resolution of ${testurl} from Pi-hole (direct IP):" - - if piholedig=$(dig "${testurl}" @"${IPV4_ADDRESS%/*}" +short); then + if piholedig=$(dig -"${protocol}" "${testurl}" @"${IP}" +short); then log_write "${piholedig}" else log_write "Failed to resolve ${testurl} on Pi-hole" @@ -297,8 +297,7 @@ testResolver() { log_write "Resolution of ${testurl} from 8.8.8.8:" - remotedig=$(dig "${testurl}" @8.8.8.8 +short) - if [[ $? = 0 ]]; then + if remotedig=$(dig -"${protocol}" "${testurl}" @8.8.8.8 +short); then log_write "${remotedig:-NXDOMAIN}" else log_write "Failed to resolve ${testurl} on 8.8.8.8" @@ -417,7 +416,7 @@ daemon_check lighttpd http daemon_check dnsmasq domain daemon_check pihole-FTL 4711 checkProcesses -testResolver +testResolver 4 "${IPV4_ADDRESS%/*}" debugLighttpd files_check "${DNSMASQFILE}" From 086f0790fc90ac1e1953b6507e3db0d1dd46c051 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 4 Mar 2017 22:31:18 +0100 Subject: [PATCH 069/165] Add Google's IPv6 address for potential IPv6 resolver tests --- advanced/Scripts/piholeDebug.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 484cb737b5..df03da560c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -273,6 +273,12 @@ testResolver() { local piholedig local remotedig + if [[ ${protocol} == "6" ]]; then + g_addr="2001:4860:4860::8888" + else + g_addr="8.8.8.8" + fi + # Find a blocked url that has not been whitelisted. url=$(shuf -n 1 "${GRAVITYFILE}" | awk -F ' ' '{ print $2 }') @@ -296,11 +302,11 @@ testResolver() { log_write "" - log_write "Resolution of ${testurl} from 8.8.8.8:" - if remotedig=$(dig -"${protocol}" "${testurl}" @8.8.8.8 +short); then + log_write "Resolution of ${testurl} from ${g_addr}:" + if remotedig=$(dig -"${protocol}" "${testurl}" @${g_addr} +short); then log_write "${remotedig:-NXDOMAIN}" else - log_write "Failed to resolve ${testurl} on 8.8.8.8" + log_write "Failed to resolve ${testurl} on ${g_addr}" fi log_write "" From 9f4ef66f416495ecafa1480b70a853dccccab98b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 4 Mar 2017 22:38:52 +0100 Subject: [PATCH 070/165] Add IPv6 resolver test --- advanced/Scripts/piholeDebug.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index df03da560c..e45debabd2 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -264,9 +264,11 @@ daemon_check() { } testResolver() { - header_write "Resolver Functions Check" local protocol="${1}" + header_write "Resolver Functions Check (IPv${protocol})" local IP="${2}" + local g_addr + local l_addr local url local testurl local localdig @@ -275,8 +277,10 @@ testResolver() { if [[ ${protocol} == "6" ]]; then g_addr="2001:4860:4860::8888" + l_addr="::1" else g_addr="8.8.8.8" + l_addr="127.0.0.1" fi # Find a blocked url that has not been whitelisted. @@ -285,19 +289,19 @@ testResolver() { testurl="${url:-doubleclick.com}" - log_write "Resolution of ${testurl} from Pi-hole (localhost):" - if localdig=$(dig -"${protocol}" "${testurl}" @localhost +short); then + log_write "Resolution of ${testurl} from Pi-hole (${l_addr}):" + if localdig=$(dig -"${protocol}" "${testurl}" @${l_addr} +short); then log_write "${localdig}" else - log_write "Failed to resolve ${testurl} on Pi-hole" + log_write "Failed to resolve ${testurl} on Pi-hole (${l_addr})" fi log_write "" - log_write "Resolution of ${testurl} from Pi-hole (direct IP):" + log_write "Resolution of ${testurl} from Pi-hole (${IP}):" if piholedig=$(dig -"${protocol}" "${testurl}" @"${IP}" +short); then log_write "${piholedig}" else - log_write "Failed to resolve ${testurl} on Pi-hole" + log_write "Failed to resolve ${testurl} on Pi-hole (${IP})" fi log_write "" @@ -306,7 +310,7 @@ testResolver() { if remotedig=$(dig -"${protocol}" "${testurl}" @${g_addr} +short); then log_write "${remotedig:-NXDOMAIN}" else - log_write "Failed to resolve ${testurl} on ${g_addr}" + log_write "Failed to resolve ${testurl} on upstream server ${g_addr}" fi log_write "" @@ -423,6 +427,7 @@ daemon_check dnsmasq domain daemon_check pihole-FTL 4711 checkProcesses testResolver 4 "${IPV4_ADDRESS%/*}" +testResolver 6 "${IPV6_ADDRESS%/*}" debugLighttpd files_check "${DNSMASQFILE}" From 112ddb3c778c9ee1b0382071b5e9bf7068ee85ed Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 4 Mar 2017 22:57:37 +0100 Subject: [PATCH 071/165] Require 4 approvals instead of five for merging into master --- .pullapprove.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pullapprove.yml b/.pullapprove.yml index c02b5486ec..39566b345f 100644 --- a/.pullapprove.yml +++ b/.pullapprove.yml @@ -33,6 +33,6 @@ groups: conditions: branches: - master - required: -1 + required: 4 teams: - - admin \ No newline at end of file + - admin From 2547cc4c8d7e13982722acbc7bcf8181585bdd9a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 15:06:34 -0800 Subject: [PATCH 072/165] Only run IPv6 if enabled, split out Chaos TXT checks. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e45debabd2..e76c5f936a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -313,6 +313,10 @@ testResolver() { log_write "Failed to resolve ${testurl} on upstream server ${g_addr}" fi log_write "" +} + +testChaos(){ + # Check Pi-hole specific records log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" @@ -320,8 +324,8 @@ testResolver() { log_write "Upstream Servers:" dig +short chaos txt servers.bind >> ${DEBUG_LOG} log_write "" -} +} checkProcesses() { header_write "Processes Check" @@ -426,8 +430,16 @@ daemon_check lighttpd http daemon_check dnsmasq domain daemon_check pihole-FTL 4711 checkProcesses + +# Check local/IP/Google for IPv4 Resolution testResolver 4 "${IPV4_ADDRESS%/*}" -testResolver 6 "${IPV6_ADDRESS%/*}" +# If IPv6 enabled, check resolution +if [[ "${IPV6_ADDRESS}" ]]; then + testResolver 6 "${IPV6_ADDRESS%/*}" +fi +# Poll dnsmasq Pi-hole specific queries +testChaos + debugLighttpd files_check "${DNSMASQFILE}" From 6f2fb57c08e45046d16d2249ace69c6716b308b5 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 15:16:33 -0800 Subject: [PATCH 073/165] Protocol specific records checks. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e76c5f936a..32f48e87d4 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -278,9 +278,11 @@ testResolver() { if [[ ${protocol} == "6" ]]; then g_addr="2001:4860:4860::8888" l_addr="::1" + r_type="AAAA" else g_addr="8.8.8.8" l_addr="127.0.0.1" + r_type="A" fi # Find a blocked url that has not been whitelisted. @@ -290,7 +292,7 @@ testResolver() { log_write "Resolution of ${testurl} from Pi-hole (${l_addr}):" - if localdig=$(dig -"${protocol}" "${testurl}" @${l_addr} +short); then + if localdig=$(dig -"${protocol}" "${testurl}" @${l_addr} +short "${r_type}"); then log_write "${localdig}" else log_write "Failed to resolve ${testurl} on Pi-hole (${l_addr})" @@ -298,7 +300,7 @@ testResolver() { log_write "" log_write "Resolution of ${testurl} from Pi-hole (${IP}):" - if piholedig=$(dig -"${protocol}" "${testurl}" @"${IP}" +short); then + if piholedig=$(dig -"${protocol}" "${testurl}" @"${IP}" +short "${r_type}"); then log_write "${piholedig}" else log_write "Failed to resolve ${testurl} on Pi-hole (${IP})" @@ -307,7 +309,7 @@ testResolver() { log_write "Resolution of ${testurl} from ${g_addr}:" - if remotedig=$(dig -"${protocol}" "${testurl}" @${g_addr} +short); then + if remotedig=$(dig -"${protocol}" "${testurl}" @${g_addr} +short "${r_type}"); then log_write "${remotedig:-NXDOMAIN}" else log_write "Failed to resolve ${testurl} on upstream server ${g_addr}" From dc44fc9e27fb7f95c599e87c52116a49e567a349 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 17:54:38 -0800 Subject: [PATCH 074/165] Version check amalgamation and removal of && || logic. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 56 ++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index a671a49f26..45b5a4b32f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -24,6 +24,8 @@ WHITELISTFILE="/etc/pihole/whitelist.txt" BLACKLISTFILE="/etc/pihole/blacklist.txt" ADLISTFILE="/etc/pihole/adlists.list" PIHOLELOG="/var/log/pihole.log" +PIHOLEGITDIR="/etc/.pihole/" +ADMINGITDIR="/var/www/html/admin/" WHITELISTMATCHES="/tmp/whitelistmatches.list" TIMEOUT=60 @@ -111,22 +113,48 @@ version_check() { header_write "Detecting Installed Package Versions:" local error_found + local pi_hole_ver + local pi_hole_branch + local pi_hole_commit + local admin_ver + local admin_branch + local admin_commit + local light_ver + local php_ver error_found=0 - local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ - && log_echo -r "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) - local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ - && log_echo -r "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) - local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ - && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) - local php_ver="$(php -v |& head -n1)" \ - && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) - - (local pi_hole_branch="$(cd /etc/.pihole/ && git rev-parse --abbrev-ref HEAD)" && log_echo -r "Pi-hole branch: ${pi_hole_branch}") || log_echo "Unable to obtain Pi-hole branch" - (local pi_hole_rev="$(cd /etc/.pihole/ && git describe --long --dirty --tags)" && log_echo -r "Pi-hole rev: ${pi_hole_rev}") || log_echo "Unable to obtain Pi-hole revision" - - (local admin_branch="$(cd /var/www/html/admin && git rev-parse --abbrev-ref HEAD)" && log_echo -r "AdminLTE branch: ${admin_branch}") || log_echo "Unable to obtain AdminLTE branch" - (local admin_rev="$(cd /var/www/html/admin && git describe --long --dirty --tags)" && log_echo -r "AdminLTE rev: ${admin_rev}") || log_echo "Unable to obtain AdminLTE revision" + if [[ -d "${PIHOLEGITDIR}" ]]; then + cd "${PIHOLEGITDIR}" + pi_hole_ver=$(git describe --tags --abbrev=0) + pi_hole_branch=$(git rev-parse --abbrev-ref HEAD) + pi_hole_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole: ${pi_hole_ver:-Untagged} (${pi_hole_branch:-Detached}:${pi_hole_commit})" + else + log_echo "Pi-hole git repository not detected." + error_found=1 + fi + if [[ -d "${ADMINGITDIR}" ]]; then + cd "${ADMINGITDIR}" + admin_ver=$(git describe --tags --abbrev=0) + admin_branch=$(git rev-parse --abbrev-ref HEAD) + admin_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Web Dashboard: ${admin_ver:-Untagged} (${admin_branch:-Detached}:${admin_commit})" + else + log_echo "Pi-hole Admin Pages git repository not detected." + error_found=1 + fi + if light_ver=$(lighttpd -v |& head -n1 | cut -d " " -f1); then + log_echo -r "${light_ver}" + else + log_echo "lighttpd not installed." + error_found=1 + fi + if php_ver=$(php -v |& head -n1); then + log_echo -r "${php_ver}" + else + log_echo "PHP not installed." + error_found=1 + fi return "${error_found}" } From 512c65044126a6987a8d405dbd6cc8f6cc60ecb2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 4 Mar 2017 19:05:32 -0800 Subject: [PATCH 075/165] Shellchecking. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 53 ++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 45b5a4b32f..608d3ef10d 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -121,28 +121,41 @@ version_check() { local admin_commit local light_ver local php_ver + local status error_found=0 - if [[ -d "${PIHOLEGITDIR}" ]]; then - cd "${PIHOLEGITDIR}" - pi_hole_ver=$(git describe --tags --abbrev=0) - pi_hole_branch=$(git rev-parse --abbrev-ref HEAD) - pi_hole_commit=$(git describe --long --dirty --tags --always) - log_echo -r "Pi-hole: ${pi_hole_ver:-Untagged} (${pi_hole_branch:-Detached}:${pi_hole_commit})" - else - log_echo "Pi-hole git repository not detected." - error_found=1 - fi - if [[ -d "${ADMINGITDIR}" ]]; then - cd "${ADMINGITDIR}" - admin_ver=$(git describe --tags --abbrev=0) - admin_branch=$(git rev-parse --abbrev-ref HEAD) - admin_commit=$(git describe --long --dirty --tags --always) - log_echo -r "Web Dashboard: ${admin_ver:-Untagged} (${admin_branch:-Detached}:${admin_commit})" - else - log_echo "Pi-hole Admin Pages git repository not detected." - error_found=1 - fi + cd "${PIHOLEGITDIR}" &> /dev/null || \ + { status="Pi-hole git directory not found."; error_found=1; } + if git status &> /dev/null; then + pi_hole_ver=$(git describe --tags --abbrev=0) + pi_hole_branch=$(git rev-parse --abbrev-ref HEAD) + pi_hole_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole: ${pi_hole_ver:-Untagged} (${pi_hole_branch:-Detached}:${pi_hole_commit})" + else + status=${status:-"Pi-hole repository damaged."} + error_found=1 + fi + if [[ "${status}" ]]; then + log_echo "${status}" + unset status + fi + + cd "${ADMINGITDIR}" || \ + { status="Pi-hole Dashboard git directory not found."; error_found=1; } + if git status &> /dev/null; then + admin_ver=$(git describe --tags --abbrev=0) + admin_branch=$(git rev-parse --abbrev-ref HEAD) + admin_commit=$(git describe --long --dirty --tags --always) + log_echo -r "Pi-hole Dashboard: ${admin_ver:-Untagged} (${admin_branch:-Detached}:${admin_commit})" + else + status=${status:-"Pi-hole Dashboard repository damaged."} + error_found=1 + fi + if [[ "${status}" ]]; then + log_echo "${status}" + unset status + fi + if light_ver=$(lighttpd -v |& head -n1 | cut -d " " -f1); then log_echo -r "${light_ver}" else From eb763d2dc2da197c2a42a9440e86dd632b7d177a Mon Sep 17 00:00:00 2001 From: raincoats Date: Sun, 5 Mar 2017 16:58:21 +1100 Subject: [PATCH 076/165] Redirect to admin panel when accessing 'http://pi.hole/' If someone tries to access 'http://pi.hole/', it will take them to the "Website blocked" page. Very confusing if you don't know to go to 'http://pi.hole/admin/'. This just redirects them to the admin panel. --- advanced/index.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/advanced/index.php b/advanced/index.php index c076f92d63..05b0811f0a 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -4,6 +4,14 @@ $uri = escapeshellcmd($_SERVER['REQUEST_URI']); $serverName = escapeshellcmd($_SERVER['SERVER_NAME']); +// If the server name is 'pi.hole', it's likely a user trying to get to the admin panel. +// Let's be nice and redirect them. +if ($serverName === 'pi.hole') +{ + header('HTTP/1.1 302 Found'); + header("Location: /admin/"); +} + // Retrieve server URI extension (EG: jpg, exe, php) $uriExt = pathinfo($uri, PATHINFO_EXTENSION); From baefec86f230488c845a846648eb246d4115644f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 5 Mar 2017 14:08:44 +0100 Subject: [PATCH 077/165] Add CLI teleporter feature --- advanced/Scripts/webpage.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index a21300ad35..bc7364b99b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -410,6 +410,12 @@ SetListeningMode(){ } +Teleporter() +{ + local datetimestamp=$(date "+%Y-%m-%d_%H-%M-%S") + php /var/www/html/admin/scripts/pi-hole/php/teleporter.php > "pi-hole-teleporter_${datetimestamp}.zip" +} + main() { args=("$@") @@ -435,6 +441,7 @@ main() { "removestaticdhcp" ) RemoveDHCPStaticAddress;; "hostrecord" ) SetHostRecord;; "-i" | "interface" ) SetListeningMode;; + "-t" | "teleporter" ) Teleporter;; * ) helpFunc;; esac From a69fcbb91ecf730e34428dbbc9c8577a26565998 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 13:44:13 +0100 Subject: [PATCH 078/165] Bugfix for when deleting host-record --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index bc7364b99b..684fbd0116 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -134,7 +134,7 @@ trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE3 delete_dnsmasq_setting "host-record" - if [ ! -z "${HOSTRECORD+x}" ]; then + if [ "${HOSTRECORD}" ]; then add_dnsmasq_setting "host-record" "${HOSTRECORD}" fi From 47a6786e8f8268dbdee34082a90af78cad1e33bb Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 14:02:56 +0100 Subject: [PATCH 079/165] Use proper test syntax --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 684fbd0116..9637cc6ffe 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -134,7 +134,7 @@ trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE3 delete_dnsmasq_setting "host-record" - if [ "${HOSTRECORD}" ]; then + if [ ! -z "${HOSTRECORD}" ]; then add_dnsmasq_setting "host-record" "${HOSTRECORD}" fi From cf315612672f0598b86f13410b12aa3832169f24 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 16:24:12 +0100 Subject: [PATCH 080/165] Remove wildcard entry when adding the very same domain either the white- or blacklist --- advanced/Scripts/list.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 90d1b7f0d5..2ac1e805f6 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,6 +84,7 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" + RemoveDomain "${dom}" "${wildcardlist}" else RemoveDomain "${dom}" "${listMain}" fi From dce3e50a007cecd790a18fe0be1b6c79e43db23c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 6 Mar 2017 16:44:56 +0100 Subject: [PATCH 081/165] Check for existence of wildcard blocking list before trying to acces it --- pihole | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 41946f3523..324c03c99b 100755 --- a/pihole +++ b/pihole @@ -128,17 +128,19 @@ queryFunc() { done # Scan for possible wildcard matches - local wildcards=($(processWildcards "${domain}")) - for domain in ${wildcards[@]}; do - result=$(scanList "\/${domain}\/" ${wildcardlist}) - # Remove empty lines before couting number of results - count=$(sed '/^\s*$/d' <<< "$result" | wc -l) - if [[ ${count} > 0 ]]; then - echo "::: Wildcard blocking ${domain} (${count} results)" - echo "${result}" - echo "" - fi - done + if [ -e "${wildcardlist}" ]; then + local wildcards=($(processWildcards "${domain}")) + for domain in ${wildcards[@]}; do + result=$(scanList "\/${domain}\/" ${wildcardlist}) + # Remove empty lines before couting number of results + count=$(sed '/^\s*$/d' <<< "$result" | wc -l) + if [[ ${count} > 0 ]]; then + echo "::: Wildcard blocking ${domain} (${count} results)" + echo "${result}" + echo "" + fi + done + fi exit 0 } From 6dea00668ef8becad51db543548347f5ed09450f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Mar 2017 13:07:34 +0100 Subject: [PATCH 082/165] Don't try to obtain version of web interface it it is not installed. Fixes #1303 --- advanced/Scripts/version.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index fd74c2de93..7f96e29ae1 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -81,16 +81,22 @@ getRemoteVersion(){ normalOutput() { echo "::: Pi-hole version is $(getLocalVersion "${PHGITDIR}") (Latest version is $(getRemoteVersion pi-hole))" - echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" + if [ -d "${WEBGITDIR}" ]; then + echo "::: Web-Admin version is $(getLocalVersion "${WEBGITDIR}") (Latest version is $(getRemoteVersion AdminLTE))" + fi } webOutput() { - case "${1}" in - "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; - "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; - "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; - * ) echo "::: Invalid Option!"; exit 1; - esac + if [ -d "${WEBGITDIR}" ]; then + case "${1}" in + "-l" | "--latest" ) echo $(getRemoteVersion AdminLTE);; + "-c" | "--current" ) echo $(getLocalVersion "${WEBGITDIR}");; + "-h" | "--hash" ) echo $(getLocalHash "${WEBGITDIR}");; + * ) echo "::: Invalid Option!"; exit 1; + esac + else + echo "::: Web interface not installed!"; exit 1; + fi } coreOutput() { From b1a9793d94d314baebc77c34050326a3338a9cc2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Mar 2017 17:53:36 +0100 Subject: [PATCH 083/165] Let Chronometer query all data from FTL (no need for having the API). Fixes #1305 --- advanced/Scripts/chronometer.sh | 68 +++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index cad8e90853..40ae1c85c0 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -8,30 +8,49 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - - #Functions############################################################################################################## piLog="/var/log/pihole.log" gravity="/etc/pihole/gravity.list" . /etc/pihole/setupVars.conf -# Borrowed/modified from https://gist.github.com/cjus/1047794 -function GetJSONValue { - retVal=$(echo $1 | sed 's/\\\\\//\//g' | \ - sed 's/[{}]//g' | \ - awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | \ - sed 's/\"\:/\|/g' | \ - sed 's/[\,]/ /g' | \ - sed 's/\"//g' | \ - grep -w $2) - echo ${retVal##*|} +function GetFTLData { + # Open connection to FTL + exec 3<>/dev/tcp/localhost/"$(cat /var/run/pihole-FTL.port)" + + # Test if connection is open + if { >&3; } 2> /dev/null; then + # Send command to FTL + echo -e ">$1" >&3 + + # Read input + read -r -t 1 LINE <&3 + until [ ! $? ] || [[ "$LINE" == *"EOM"* ]]; do + echo "$LINE" >&1 + read -r -t 1 LINE <&3 + done + + # Close connection + exec 3>&- + exec 3<&- + fi } outputJSON() { - json=$(curl -s -X GET http://127.0.0.1/admin/api.php?summaryRaw) - echo ${json} + get_summary_data + echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}" +} + +get_summary_data() { + local summary=$(GetFTLData "stats") + domains_being_blocked_raw=$(grep "domains_being_blocked" <<< "${summary}" | grep -Eo "[0-9]+$") + domains_being_blocked=$(printf "%'.f" ${domains_being_blocked_raw}) + dns_queries_today_raw=$(grep "dns_queries_today" <<< "$summary" | grep -Eo "[0-9]+$") + dns_queries_today=$(printf "%'.f" ${dns_queries_today_raw}) + ads_blocked_today_raw=$(grep "ads_blocked_today" <<< "$summary" | grep -Eo "[0-9]+$") + ads_blocked_today=$(printf "%'.f" ${ads_blocked_today_raw}) + ads_percentage_today_raw=$(grep "ads_percentage_today" <<< "$summary" | grep -Eo "[0-9.]+$") + LC_NUMERIC=C ads_percentage_today=$(printf "%'.f" ${ads_percentage_today_raw}) } normalChrono() { @@ -49,23 +68,14 @@ normalChrono() { #uptime -p #Doesn't work on all versions of uptime uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' echo "-------------------------------" - domain=$(curl -s -X GET http://127.0.0.1/admin/api.php?recentBlocked) + domain=$(GetFTLData recentBlocked) echo "Recently blocked:" echo " $domain" - # Uncomment to continually read the log file and display the current domain being blocked - #tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}' - - json=$(curl -s -X GET http://127.0.0.1/admin/api.php?summaryRaw) - - domains=$(printf "%'.f" $(GetJSONValue ${json} "domains_being_blocked")) #add commas in - queries=$(printf "%'.f" $(GetJSONValue ${json} "dns_queries_today")) - blocked=$(printf "%'.f" $(GetJSONValue ${json} "ads_blocked_today")) - LC_NUMERIC=C percentage=$(printf "%0.2f\n" $(GetJSONValue ${json} "ads_percentage_today")) #2 decimal places - - echo "Blocking: ${domains}" - echo "Queries: ${queries}" - echo "Pi-holed: ${blocked} (${percentage}%)" + get_summary_data + echo "Blocking: ${domains_being_blocked}" + echo "Queries: ${dns_queries_today}" + echo "Pi-holed: ${ads_blocked_today} (${ads_percentage_today}%)" sleep 5 done From 4e25e0dc5c3a2d87e3e5d4bc0c7a6c389633bd8e Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Mar 2017 17:57:57 +0100 Subject: [PATCH 084/165] Add missing } to JSON output --- advanced/Scripts/chronometer.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 40ae1c85c0..d5778a73e9 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -38,7 +38,7 @@ function GetFTLData { outputJSON() { get_summary_data - echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}" + echo "{\"domains_being_blocked\":${domains_being_blocked_raw},\"dns_queries_today\":${dns_queries_today_raw},\"ads_blocked_today\":${ads_blocked_today_raw},\"ads_percentage_today\":${ads_percentage_today_raw}}" } get_summary_data() { From 10bc8414b9508d8752f8b56dc9d80d865378e0a1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 7 Mar 2017 18:10:05 +0100 Subject: [PATCH 085/165] Move FTL querying before clearing the terminal to avoid flashing on Pi B+ --- advanced/Scripts/chronometer.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index d5778a73e9..bd514a8037 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -55,6 +55,8 @@ get_summary_data() { normalChrono() { for (( ; ; )); do + get_summary_data + domain=$(GetFTLData recentBlocked) clear # Displays a colorful Pi-hole logo echo " ___ _ _ _" @@ -72,7 +74,6 @@ normalChrono() { echo "Recently blocked:" echo " $domain" - get_summary_data echo "Blocking: ${domains_being_blocked}" echo "Queries: ${dns_queries_today}" echo "Pi-holed: ${ads_blocked_today} (${ads_percentage_today}%)" From 8235b18854800908d9106d6274bd5155079f28ed Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 8 Mar 2017 12:09:34 +0100 Subject: [PATCH 086/165] Remove duplicated line --- advanced/Scripts/chronometer.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index bd514a8037..67ff495beb 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -70,7 +70,6 @@ normalChrono() { #uptime -p #Doesn't work on all versions of uptime uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}' echo "-------------------------------" - domain=$(GetFTLData recentBlocked) echo "Recently blocked:" echo " $domain" From 8a14a63d5d81a9bfbab049a6568596c55cfa692b Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 8 Mar 2017 13:16:40 +0100 Subject: [PATCH 087/165] Pi-hole checkout feature --- advanced/Scripts/piholeCheckout.sh | 163 +++++++++++++++++++++++++++++ advanced/bash-completion/pihole | 2 +- pihole | 10 +- 3 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 advanced/Scripts/piholeCheckout.sh diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh new file mode 100644 index 0000000000..7d1df415c0 --- /dev/null +++ b/advanced/Scripts/piholeCheckout.sh @@ -0,0 +1,163 @@ +#!/usr/bin/env bash +# Pi-hole: A black hole for Internet advertisements +# (c) 2017 Pi-hole, LLC (https://pi-hole.net) +# Network-wide ad blocking via your own hardware. +# +# Checkout other branches than master +# +# This file is copyright under the latest version of the EUPL. +# Please see LICENSE file for your rights under this license. + +readonly WEB_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git" +readonly WEB_INTERFACE_DIR="/var/www/html/admin" +readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" +readonly PI_HOLE_FILES_DIR="/etc/.pihole" + +is_repo() { + # Use git to check if directory is currently under VCS, return the value + local directory="${1}" + local curdir + local rc + + curdir="${PWD}" + cd "${directory}" || return 1 + # Capture any possible output + git status --short &> /dev/null + rc=$? + cd "${curdir}" || return 1 + return $rc +} + +fully_fetch_repo() { + # Add upstream branches to shallow clone + local directory="${1}" + local curdir + local rc + + curdir="${PWD}" + cd "${directory}" || return 1 + git remote set-branches origin '*' || return 1 + git fetch --quiet || return 1 + cd "${curdir}" || return 1 + return +} + +get_available_branches(){ + # Return available branches + local directory="${1}" + local curdir + + curdir="${PWD}" + cd "${directory}" || return 1 + # Get reachable remote branches + git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g' + cd "${curdir}" || return 1 + return +} + +checkout_pull_branch() { + # Check out specified branch + local directory="${1}" + local branch="${2}" + local curdir + + curdir="${PWD}" + cd "${directory}" || return 1 + git checkout "${branch}" + git pull + cd "${curdir}" || return 1 + return +} + +warning1() { + echo "::: Note that changing the branch is a severe change of your Pi-hole system." + echo "::: This is not supported unless one of the developers explicitly asks you to do this!" + read -r -p "::: Have you read and understood this? [y/N] " response + case ${response} in + [yY][eE][sS]|[yY]) + echo "::: Continuing." + return 0 + ;; + *) + echo "::: Aborting." + return 1 + ;; + esac +} + +checkout() +{ + local corebranches + local webbranches + + # Avoid globbing + set -f + + #This is unlikely + if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${WEB_INTERFACE_DIR}" ; then + echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!" + echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole" + exit 1 + fi + + if ! warning1 ; then + exit 1 + fi + + echo -n "::: Fetching remote branches for Pi-hole core from ${PI_HOLE_GIT_URL} ... " + if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Fetching all branches for Pi-hole core repo failed!" + exit 1 + fi + corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) + echo " done!" + echo "::: ${#corebranches[@]} branches available" + echo ":::" + + echo -n "::: Fetching remote branches for the web interface from ${WEB_INTERFACE_GIT_URL} ... " + if ! fully_fetch_repo "${WEB_INTERFACE_DIR}" ; then + echo "::: Fetching all branches for Pi-hole web interface repo failed!" + exit 1 + fi + webbranches=($(get_available_branches "${WEB_INTERFACE_DIR}")) + echo " done!" + echo "::: ${#webbranches[@]} branches available" + echo ":::" + + if [[ "${2}" == "dev" ]] ; then + # Shortcut to check out development version + echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." + echo "::: Pi-hole core" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" + echo "::: Web interface" + checkout_pull_branch "${WEB_INTERFACE_DIR}" "devel" + echo "::: done!" + elif [[ "${2}" == "core" ]] ; then + # Have to user chosing the branch he wants + if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then + echo "::: Requested branch \"${3}\" is not available!" + echo "::: Available branches for core are:" + for e in "${corebranches[@]}"; do echo "::: $e"; done + exit 1 + fi + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${3}" + elif [[ "${2}" == "web" ]] ; then + # Have to user chosing the branch he wants + if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then + echo "::: Requested branch \"${3}\" is not available!" + echo "::: Available branches for web are:" + for e in "${webbranches[@]}"; do echo "::: $e"; done + exit 1 + fi + checkout_pull_branch "${WEB_INTERFACE_DIR}" "${3}" + else + echo "::: Requested option \"${2}\" is not available!" + exit 1 + fi + + # Force updating everything + echo "::: Running installer to upgrade your installation" + /etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 + + exit 0 +} diff --git a/advanced/bash-completion/pihole b/advanced/bash-completion/pihole index 05baa820b0..fc8f2162ab 100644 --- a/advanced/bash-completion/pihole +++ b/advanced/bash-completion/pihole @@ -3,7 +3,7 @@ _pihole() { COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" - opts="admin blacklist chronometer debug disable enable flush help logging query reconfigure restartdns setupLCD status tail uninstall updateGravity updatePihole version whitelist" + opts="admin blacklist chronometer debug disable enable flush help logging query reconfigure restartdns setupLCD status tail uninstall updateGravity updatePihole version whitelist checkout" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 diff --git a/pihole b/pihole index 324c03c99b..38c7160f1c 100755 --- a/pihole +++ b/pihole @@ -8,9 +8,8 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" - -PI_HOLE_SCRIPT_DIR="/opt/pihole" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then @@ -280,6 +279,11 @@ tailFunc() { exit 0 } +piholeCheckoutFunc() { + source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh + checkout "$@" +} + helpFunc() { cat << EOM ::: Control all PiHole specific functions! @@ -313,6 +317,7 @@ helpFunc() { ::: Blocking can also be disabled only temporarily, e.g., ::: 'pihole disable 5m' - will disable blocking for 5 minutes ::: restartdns Restart dnsmasq +::: checkout Check out different branches EOM exit 0 } @@ -343,5 +348,6 @@ case "${1}" in "restartdns" ) restartDNS;; "-a" | "admin" ) webpageFunc "$@";; "-t" | "tail" ) tailFunc;; + "checkout" ) piholeCheckoutFunc "$@";; * ) helpFunc;; esac From d2ab0694b7ce31b1a8fca6d1d6b06102b90f68b2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 8 Mar 2017 13:18:34 +0100 Subject: [PATCH 088/165] Add "master" shortcut --- advanced/Scripts/piholeCheckout.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 7d1df415c0..e32c8e0670 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -125,13 +125,21 @@ checkout() echo ":::" if [[ "${2}" == "dev" ]] ; then - # Shortcut to check out development version + # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" echo "::: Web interface" checkout_pull_branch "${WEB_INTERFACE_DIR}" "devel" echo "::: done!" + elif [[ "${2}" == "master" ]] ; then + # Shortcut to check out master branches + echo "::: Shortcut \"master\" detected - checking out master branches ..." + echo "::: Pi-hole core" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" + echo "::: Web interface" + checkout_pull_branch "${WEB_INTERFACE_DIR}" "master" + echo "::: done!" elif [[ "${2}" == "core" ]] ; then # Have to user chosing the branch he wants if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then From 56e17d1010c8bc4f25816fa986cbacd8ed175caf Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 13:27:48 -0800 Subject: [PATCH 089/165] Source functions and variables from basic-install.sh Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index e32c8e0670..4133facbc3 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -8,25 +8,15 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +readonly PI_HOLE_FILES_DIR="/etc/.pihole" +PH_TEST=true source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh + readonly WEB_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git" readonly WEB_INTERFACE_DIR="/var/www/html/admin" readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" -readonly PI_HOLE_FILES_DIR="/etc/.pihole" -is_repo() { - # Use git to check if directory is currently under VCS, return the value - local directory="${1}" - local curdir - local rc - curdir="${PWD}" - cd "${directory}" || return 1 - # Capture any possible output - git status --short &> /dev/null - rc=$? - cd "${curdir}" || return 1 - return $rc -} +# is_repo() sourced from basic-install.sh fully_fetch_repo() { # Add upstream branches to shallow clone From 89ff99322d598027eb615c02779466afd08b5303 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 13:30:08 -0800 Subject: [PATCH 090/165] Don't need to remember `pwd` inside a function, calling function doesn't change directories. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 4133facbc3..732434a19c 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -21,15 +21,10 @@ readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" fully_fetch_repo() { # Add upstream branches to shallow clone local directory="${1}" - local curdir - local rc - curdir="${PWD}" cd "${directory}" || return 1 - git remote set-branches origin '*' || return 1 - git fetch --quiet || return 1 - cd "${curdir}" || return 1 - return + git fetch --quiet --unshallow || return 1 + return 0 } get_available_branches(){ From b522d8eaf6fa897529dfe1eef5f04d3cf1257f7d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 13:41:11 -0800 Subject: [PATCH 091/165] Source and reuse existing variables, centralize code. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 732434a19c..1c6711f4cd 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -11,11 +11,9 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole" PH_TEST=true source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh -readonly WEB_INTERFACE_GIT_URL="https://github.com/pi-hole/AdminLTE.git" -readonly WEB_INTERFACE_DIR="/var/www/html/admin" -readonly PI_HOLE_GIT_URL="https://github.com/pi-hole/pi-hole.git" - - +# webInterfaceGitUrl set in basic-install.sh +# webInterfaceDir set in basic-install.sh +# piholeGitURL set in basic-install.sh # is_repo() sourced from basic-install.sh fully_fetch_repo() { @@ -79,7 +77,7 @@ checkout() set -f #This is unlikely - if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${WEB_INTERFACE_DIR}" ; then + if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${webInterfaceDir}" ; then echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!" echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole" exit 1 @@ -89,7 +87,7 @@ checkout() exit 1 fi - echo -n "::: Fetching remote branches for Pi-hole core from ${PI_HOLE_GIT_URL} ... " + echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then echo "::: Fetching all branches for Pi-hole core repo failed!" exit 1 @@ -99,12 +97,12 @@ checkout() echo "::: ${#corebranches[@]} branches available" echo ":::" - echo -n "::: Fetching remote branches for the web interface from ${WEB_INTERFACE_GIT_URL} ... " - if ! fully_fetch_repo "${WEB_INTERFACE_DIR}" ; then + echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " + if ! fully_fetch_repo "${webInterfaceDir}" ; then echo "::: Fetching all branches for Pi-hole web interface repo failed!" exit 1 fi - webbranches=($(get_available_branches "${WEB_INTERFACE_DIR}")) + webbranches=($(get_available_branches "${webInterfaceDir}")) echo " done!" echo "::: ${#webbranches[@]} branches available" echo ":::" @@ -115,7 +113,7 @@ checkout() echo "::: Pi-hole core" checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" echo "::: Web interface" - checkout_pull_branch "${WEB_INTERFACE_DIR}" "devel" + checkout_pull_branch "${webInterfaceDir}" "devel" echo "::: done!" elif [[ "${2}" == "master" ]] ; then # Shortcut to check out master branches @@ -123,7 +121,7 @@ checkout() echo "::: Pi-hole core" checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" echo "::: Web interface" - checkout_pull_branch "${WEB_INTERFACE_DIR}" "master" + checkout_pull_branch "${webInterfaceDir}" "master" echo "::: done!" elif [[ "${2}" == "core" ]] ; then # Have to user chosing the branch he wants @@ -142,7 +140,7 @@ checkout() for e in "${webbranches[@]}"; do echo "::: $e"; done exit 1 fi - checkout_pull_branch "${WEB_INTERFACE_DIR}" "${3}" + checkout_pull_branch "${webInterfaceDir}" "${3}" else echo "::: Requested option \"${2}\" is not available!" exit 1 @@ -150,7 +148,7 @@ checkout() # Force updating everything echo "::: Running installer to upgrade your installation" - /etc/.pihole/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 + ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 exit 0 } From b8f1eadb7f2bd82d552deaab6086230bca634420 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 13:57:35 -0800 Subject: [PATCH 092/165] Shift off `checkout` from being passed to script from `pihole` Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 17 +++++++++++------ pihole | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 1c6711f4cd..94ae5a1662 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,7 +9,7 @@ # Please see LICENSE file for your rights under this license. readonly PI_HOLE_FILES_DIR="/etc/.pihole" -PH_TEST=true source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh +PH_TEST="true" source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh # webInterfaceGitUrl set in basic-install.sh # webInterfaceDir set in basic-install.sh @@ -21,7 +21,11 @@ fully_fetch_repo() { local directory="${1}" cd "${directory}" || return 1 - git fetch --quiet --unshallow || return 1 + if is_repo "${directory}"; then + git fetch --quiet --unshallow &> /dev/null || true # Deep repo's cause errors but are valid repos. + else + return 1 + fi return 0 } @@ -107,7 +111,7 @@ checkout() echo "::: ${#webbranches[@]} branches available" echo ":::" - if [[ "${2}" == "dev" ]] ; then + if [[ "${1}" == "dev" ]] ; then # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" @@ -115,7 +119,7 @@ checkout() echo "::: Web interface" checkout_pull_branch "${webInterfaceDir}" "devel" echo "::: done!" - elif [[ "${2}" == "master" ]] ; then + elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" @@ -123,7 +127,7 @@ checkout() echo "::: Web interface" checkout_pull_branch "${webInterfaceDir}" "master" echo "::: done!" - elif [[ "${2}" == "core" ]] ; then + elif [[ "${1}" == "core" ]] ; then # Have to user chosing the branch he wants if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then echo "::: Requested branch \"${3}\" is not available!" @@ -132,7 +136,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${3}" - elif [[ "${2}" == "web" ]] ; then + elif [[ "${1}" == "web" ]] ; then # Have to user chosing the branch he wants if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then echo "::: Requested branch \"${3}\" is not available!" @@ -152,3 +156,4 @@ checkout() exit 0 } + diff --git a/pihole b/pihole index 38c7160f1c..dda6d7500b 100755 --- a/pihole +++ b/pihole @@ -281,6 +281,7 @@ tailFunc() { piholeCheckoutFunc() { source "${PI_HOLE_SCRIPT_DIR}"/piholeCheckout.sh + shift checkout "$@" } From 87da40068ccfb09118927b7ebf9c471d519c28e8 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 14:17:20 -0800 Subject: [PATCH 093/165] Always `exit`ed with value 1, now exits with proper value. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 94ae5a1662..cabafc047f 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -152,8 +152,11 @@ checkout() # Force updating everything echo "::: Running installer to upgrade your installation" - ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended || echo "Unable to complete update, contact Pi-hole" && exit 1 - - exit 0 + if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then + exit 0 + else + echo "Unable to complete update, contact Pi-hole" + exit 1 + fi } From a9b52518bf44eb47f2c9dc9e7b53b0803ea546eb Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 14:29:51 -0800 Subject: [PATCH 094/165] Shift numbers for argument identifiers, functions are called after `shift` Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index cabafc047f..c1eacd6dad 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -129,24 +129,24 @@ checkout() echo "::: done!" elif [[ "${1}" == "core" ]] ; then # Have to user chosing the branch he wants - if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then - echo "::: Requested branch \"${3}\" is not available!" + if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then + echo "::: Requested branch \"${2}\" is not available!" echo "::: Available branches for core are:" for e in "${corebranches[@]}"; do echo "::: $e"; done exit 1 fi - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${3}" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" elif [[ "${1}" == "web" ]] ; then # Have to user chosing the branch he wants - if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${3}" ]] && exit 0; done); then - echo "::: Requested branch \"${3}\" is not available!" + if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then + echo "::: Requested branch \"${2}\" is not available!" echo "::: Available branches for web are:" for e in "${webbranches[@]}"; do echo "::: $e"; done exit 1 fi checkout_pull_branch "${webInterfaceDir}" "${3}" else - echo "::: Requested option \"${2}\" is not available!" + echo "::: Requested option \"${1}\" is not available!" exit 1 fi From fd310c6445e63d1a86dbde5c385d0eb89e9d1993 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Mar 2017 00:28:02 +0100 Subject: [PATCH 095/165] Back to how we had it before, because --unshallow does not work at all --- advanced/Scripts/piholeCheckout.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index c1eacd6dad..c0ac62e1f9 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -22,7 +22,8 @@ fully_fetch_repo() { cd "${directory}" || return 1 if is_repo "${directory}"; then - git fetch --quiet --unshallow &> /dev/null || true # Deep repo's cause errors but are valid repos. + git remote set-branches origin '*' || return 1 + git fetch --quiet || return 1 else return 1 fi From 81a1057cac768bc592f2b2676ecfb16a8921a6cf Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 9 Mar 2017 00:30:36 +0100 Subject: [PATCH 096/165] Fix something Dan has overlooked --- 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 c0ac62e1f9..86ea9a2b1d 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -145,7 +145,7 @@ checkout() for e in "${webbranches[@]}"; do echo "::: $e"; done exit 1 fi - checkout_pull_branch "${webInterfaceDir}" "${3}" + checkout_pull_branch "${webInterfaceDir}" "${2}" else echo "::: Requested option \"${1}\" is not available!" exit 1 From 273728b481c131d1010f662f533278e4903d91d2 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 8 Mar 2017 15:32:06 -0800 Subject: [PATCH 097/165] One more argument to shift. Signed-off-by: Dan Schaper --- 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 c1eacd6dad..fa835c00a5 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -144,7 +144,7 @@ checkout() for e in "${webbranches[@]}"; do echo "::: $e"; done exit 1 fi - checkout_pull_branch "${webInterfaceDir}" "${3}" + checkout_pull_branch "${webInterfaceDir}" "${2}" else echo "::: Requested option \"${1}\" is not available!" exit 1 From 5e16487ef62be49ba97262de0cffb041f4da4695 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Wed, 8 Mar 2017 21:14:21 -0600 Subject: [PATCH 098/165] add ascii berry to beginning of installer --- automated install/basic-install.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 87701ce1be..7c9a83d507 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -54,6 +54,32 @@ skipSpaceCheck=false reconfigure=false runUnattended=false +show_ascii_berry() { + echo " + .;;,. + .ccccc:,. + :cccclll:. ..,, + :ccccclll. ;ooodc + 'ccll:;ll .oooodc + .;cll.;;looo:. + .. ','. + .',,,,,,'. + .',,,,,,,,,,. + .',,,,,,,,,,,,.... + ....''',,,,,,,'....... + ......... .... ......... + .......... .......... + .......... .......... + ......... .... ......... + ........,,,,,,,'...... + ....',,,,,,,,,,,,. + .',,,,,,,,,'. + .',,,,,,'. + ..'''. +" +} + + # Compatibility distro_check() { if command -v apt-get &> /dev/null; then @@ -1262,6 +1288,7 @@ main() { ######## FIRST CHECK ######## # Must be root to install + show_ascii_berry echo ":::" if [[ ${EUID} -eq 0 ]]; then echo "::: You are root." From 1590a179fa37fb8157f5a89639c776034322f13f Mon Sep 17 00:00:00 2001 From: raincoats Date: Thu, 9 Mar 2017 17:38:56 +1100 Subject: [PATCH 099/165] Change 302 redirect to 301 Change "302 Found" response to "301 Moved Permanently", as "302 Found" is meant for temporary redirects. Was asked to do so in this comment: https://github.com/pi-hole/pi-hole/pull/1297#issuecomment-284335421 --- advanced/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 05b0811f0a..99f8c1f833 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -8,7 +8,7 @@ // Let's be nice and redirect them. if ($serverName === 'pi.hole') { - header('HTTP/1.1 302 Found'); + header('HTTP/1.1 301 Moved Permanently'); header("Location: /admin/"); } From 0a0d25dff49dcb1815e8b1868d57a9210caa469f Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 10:57:46 -0800 Subject: [PATCH 100/165] Script runs in subshell, no need to cd back to pwd. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 86ea9a2b1d..0da8dd02e2 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -33,13 +33,10 @@ fully_fetch_repo() { get_available_branches(){ # Return available branches local directory="${1}" - local curdir - curdir="${PWD}" cd "${directory}" || return 1 # Get reachable remote branches git remote show origin | grep 'tracked' | sed 's/tracked//;s/ //g' - cd "${curdir}" || return 1 return } @@ -47,14 +44,11 @@ checkout_pull_branch() { # Check out specified branch local directory="${1}" local branch="${2}" - local curdir - curdir="${PWD}" cd "${directory}" || return 1 - git checkout "${branch}" - git pull - cd "${curdir}" || return 1 - return + git checkout "${branch}" || return 1 + git pull || return 1 + return 0 } warning1() { From 20fd61468df87d84d42e5260c0d794bc2285857c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 11:04:37 -0800 Subject: [PATCH 101/165] Require branch to check out Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 0da8dd02e2..08684bb90e 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -82,6 +82,13 @@ checkout() exit 1 fi + if [[ -z "${1}" ]]; then + echo "::: No option detected. Please use 'pihole checkout '." + echo "::: Or enter the repository and branch you would like to check out:" + echo "::: 'pihole checkout '" + exit 1 + fi + if ! warning1 ; then exit 1 fi From d5b88e0df8144b71245fb5ea8345c7a1fefa3710 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 11:07:58 -0800 Subject: [PATCH 102/165] Get the right name for the options. Signed-off-by: Dan Schaper --- 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 08684bb90e..b97d9680b1 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -83,7 +83,7 @@ checkout() fi if [[ -z "${1}" ]]; then - echo "::: No option detected. Please use 'pihole checkout '." + echo "::: No option detected. Please use 'pihole checkout '." echo "::: Or enter the repository and branch you would like to check out:" echo "::: 'pihole checkout '" exit 1 From 41e1e4cb683ea2b742fb38b50376ac75b535b9d4 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 10 Mar 2017 11:25:35 -0800 Subject: [PATCH 103/165] Rearrange pull logic, some optimization. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index b97d9680b1..437dbc390b 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -93,43 +93,32 @@ checkout() exit 1 fi - echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " - if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then - echo "::: Fetching all branches for Pi-hole core repo failed!" - exit 1 - fi - corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) - echo " done!" - echo "::: ${#corebranches[@]} branches available" - echo ":::" - - echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " - if ! fully_fetch_repo "${webInterfaceDir}" ; then - echo "::: Fetching all branches for Pi-hole web interface repo failed!" - exit 1 - fi - webbranches=($(get_available_branches "${webInterfaceDir}")) - echo " done!" - echo "::: ${#webbranches[@]} branches available" - echo ":::" - if [[ "${1}" == "dev" ]] ; then # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "devel" + checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" + checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "master" + checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "core" ]] ; then + echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " + if ! fully_fetch_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Fetching all branches for Pi-hole core repo failed!" + exit 1 + fi + corebranches=($(get_available_branches "${PI_HOLE_FILES_DIR}")) + echo " done!" + echo "::: ${#corebranches[@]} branches available" + echo ":::" # Have to user chosing the branch he wants if ! (for e in "${corebranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -139,6 +128,15 @@ checkout() fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" elif [[ "${1}" == "web" ]] ; then + echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " + if ! fully_fetch_repo "${webInterfaceDir}" ; then + echo "::: Fetching all branches for Pi-hole web interface repo failed!" + exit 1 + fi + webbranches=($(get_available_branches "${webInterfaceDir}")) + echo " done!" + echo "::: ${#webbranches[@]} branches available" + echo ":::" # Have to user chosing the branch he wants if ! (for e in "${webbranches[@]}"; do [[ "$e" == "${2}" ]] && exit 0; done); then echo "::: Requested branch \"${2}\" is not available!" @@ -153,12 +151,14 @@ checkout() fi # Force updating everything - echo "::: Running installer to upgrade your installation" - if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then - exit 0 - else - echo "Unable to complete update, contact Pi-hole" - exit 1 + if [[ ! "${1}" == "web" ]]; then + echo "::: Running installer to upgrade your installation" + if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then + exit 0 + else + echo "Unable to complete update, contact Pi-hole" + exit 1 + fi fi } From 1d60b62e7a13ca6603fba8909d8ae1c3f3f9208c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:11:23 +0100 Subject: [PATCH 104/165] Testing alternative way of fetching/checking out of a single branch --- advanced/Scripts/piholeCheckout.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 437dbc390b..381de1c356 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -40,6 +40,24 @@ get_available_branches(){ return } + +fetch_checkout_pull_branch() { + # Check out specified branch + local directory="${1}" + local branch="${2}" + + # Check if branch exists locally + if git rev-parse --quiet --verify development &> /dev/null; then + # Branch exists locally, we can check it out and pull it + checkout_pull_branch "${directory}" "${branch}" || return 1 + else + # Branch does not exist locally, we set the reference for it, fetch, check it put and pull it + git remote set-branches origin "${branch}" || return 1 + git fetch --quiet || return 1 + checkout_pull_branch "${directory}" "${branch}" || return 1 + fi +} + checkout_pull_branch() { # Check out specified branch local directory="${1}" @@ -97,17 +115,17 @@ checkout() # Shortcut to check out development branches echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" - checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } + fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } echo "::: Web interface" - checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } echo "::: done!" elif [[ "${1}" == "core" ]] ; then echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " From febdb4a1905f5580b0bb66b7682051514ccd886d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:24:13 +0100 Subject: [PATCH 105/165] Use git diff to determine if code has changed (no need to run the installer if it hasn't changed at all) --- advanced/Scripts/piholeCheckout.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 381de1c356..112c8ab889 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,13 +9,15 @@ # Please see LICENSE file for your rights under this license. readonly PI_HOLE_FILES_DIR="/etc/.pihole" -PH_TEST="true" source ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh +PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh" # webInterfaceGitUrl set in basic-install.sh # webInterfaceDir set in basic-install.sh # piholeGitURL set in basic-install.sh # is_repo() sourced from basic-install.sh +update=false + fully_fetch_repo() { # Add upstream branches to shallow clone local directory="${1}" @@ -64,6 +66,10 @@ checkout_pull_branch() { local branch="${2}" cd "${directory}" || return 1 + if [ "$(git diff "${branch}" | grep -c "^")" -gt "0" ]; then + update=true + fi + git checkout "${branch}" || return 1 git pull || return 1 return 0 @@ -169,9 +175,9 @@ checkout() fi # Force updating everything - if [[ ! "${1}" == "web" ]]; then + if [[ ! "${1}" == "web" && ${update} ]]; then echo "::: Running installer to upgrade your installation" - if ${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh --unattended; then + if "${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh" --unattended; then exit 0 else echo "Unable to complete update, contact Pi-hole" From b961b13d60bde6072bf0e90ea219885c08f1d542 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:27:00 +0100 Subject: [PATCH 106/165] Small bugfix --- 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 112c8ab889..307d3d48aa 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -49,7 +49,7 @@ fetch_checkout_pull_branch() { local branch="${2}" # Check if branch exists locally - if git rev-parse --quiet --verify development &> /dev/null; then + if git rev-parse --quiet --verify "${branch}" &> /dev/null; then # Branch exists locally, we can check it out and pull it checkout_pull_branch "${directory}" "${branch}" || return 1 else From 140ac192aa603b373634b6f1b70d1940b24f6f47 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:30:58 +0100 Subject: [PATCH 107/165] The web repo might actually be missing and this is n error (not installed because the user didn't want it) --- advanced/Scripts/piholeCheckout.sh | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 307d3d48aa..8278cbc998 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -100,10 +100,17 @@ checkout() set -f #This is unlikely - if ! is_repo "${PI_HOLE_FILES_DIR}" || ! is_repo "${webInterfaceDir}" ; then - echo "::: Critical Error: One or more Pi-Hole repos are missing from your system!" - echo "::: Please re-run the install script from https://github.com/pi-hole/pi-hole" - exit 1 + if ! is_repo "${PI_HOLE_FILES_DIR}" ; then + echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi + if [[ ${INSTALL_WEB} ]]; then + if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then + echo "::: Critical Error: Web Admin repo is missing from system!" + echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" + exit 1; + fi fi if [[ -z "${1}" ]]; then @@ -122,16 +129,20 @@ checkout() echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } - echo "::: Web interface" - fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + if [[ ${INSTALL_WEB} ]]; then + echo "::: Web interface" + fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } + fi echo "::: done!" elif [[ "${1}" == "master" ]] ; then # Shortcut to check out master branches echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } - echo "::: Web interface" - fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + if [[ ${INSTALL_WEB} ]]; then + echo "::: Web interface" + fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } + fi echo "::: done!" elif [[ "${1}" == "core" ]] ; then echo -n "::: Fetching remote branches for Pi-hole core from ${piholeGitUrl} ... " @@ -151,7 +162,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" ]] ; then + elif [[ "${1}" == "web" && ${INSTALL_WEB} ]] ; then echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " if ! fully_fetch_repo "${webInterfaceDir}" ; then echo "::: Fetching all branches for Pi-hole web interface repo failed!" From 8cb66544d224fb4b392fa18a53895aa4d6fa4248 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:36:54 +0100 Subject: [PATCH 108/165] Remove "\ " --- advanced/Scripts/piholeCheckout.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 8278cbc998..2b4687db19 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -9,7 +9,7 @@ # Please see LICENSE file for your rights under this license. readonly PI_HOLE_FILES_DIR="/etc/.pihole" -PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh" +PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # webInterfaceGitUrl set in basic-install.sh # webInterfaceDir set in basic-install.sh @@ -188,7 +188,7 @@ checkout() # Force updating everything if [[ ! "${1}" == "web" && ${update} ]]; then echo "::: Running installer to upgrade your installation" - if "${PI_HOLE_FILES_DIR}/automated\ install/basic-install.sh" --unattended; then + if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0 else echo "Unable to complete update, contact Pi-hole" From d4a49d192f17413b5f5c02bda0545f0579dfc742 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:38:28 +0100 Subject: [PATCH 109/165] Correct variable name --- 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 2b4687db19..6fd46fab21 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -106,7 +106,7 @@ checkout() exit 1; fi if [[ ${INSTALL_WEB} ]]; then - if ! is_repo "${ADMIN_INTERFACE_DIR}" ; then + if ! is_repo "${webInterfaceDir}" ; then echo "::: Critical Error: Web Admin repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; From 1b9e7fbf2e4d649ff512259f3949c39186434368 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:40:10 +0100 Subject: [PATCH 110/165] Test if branch is locally available is not reliable because of possible ambiguities --- advanced/Scripts/piholeCheckout.sh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 6fd46fab21..c255d8225e 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -48,16 +48,10 @@ fetch_checkout_pull_branch() { local directory="${1}" local branch="${2}" - # Check if branch exists locally - if git rev-parse --quiet --verify "${branch}" &> /dev/null; then - # Branch exists locally, we can check it out and pull it - checkout_pull_branch "${directory}" "${branch}" || return 1 - else - # Branch does not exist locally, we set the reference for it, fetch, check it put and pull it - git remote set-branches origin "${branch}" || return 1 - git fetch --quiet || return 1 - checkout_pull_branch "${directory}" "${branch}" || return 1 - fi + # Set the reference for the requested branch, fetch, check it put and pull it + git remote set-branches origin "${branch}" || return 1 + git fetch --quiet || return 1 + checkout_pull_branch "${directory}" "${branch}" || return 1 } checkout_pull_branch() { From bd2d81f691e6b0bba3dd31da21d9b451b36ee881 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:46:52 +0100 Subject: [PATCH 111/165] source setupVars.conf to see if INSTALL_WEB is true or not --- advanced/Scripts/piholeCheckout.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index c255d8225e..fb5f0fd9cb 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -15,6 +15,9 @@ PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # webInterfaceDir set in basic-install.sh # piholeGitURL set in basic-install.sh # is_repo() sourced from basic-install.sh +# setupVars set in basic-install.sh + +source "${setupVars}" update=false From 9a9d9007cd66980ff97b7341303019a42b2883d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:49:47 +0100 Subject: [PATCH 112/165] Add missing "== true" --- advanced/Scripts/piholeCheckout.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index fb5f0fd9cb..a3398daa41 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -102,7 +102,7 @@ checkout() echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi - if [[ ${INSTALL_WEB} ]]; then + if [[ ${INSTALL_WEB} == true ]]; then if ! is_repo "${webInterfaceDir}" ; then echo "::: Critical Error: Web Admin repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" @@ -126,7 +126,7 @@ checkout() echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } - if [[ ${INSTALL_WEB} ]]; then + if [[ ${INSTALL_WEB} == true ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } fi @@ -136,7 +136,7 @@ checkout() echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } - if [[ ${INSTALL_WEB} ]]; then + if [[ ${INSTALL_WEB} == true ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } fi @@ -159,7 +159,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" && ${INSTALL_WEB} ]] ; then + elif [[ "${1}" == "web" && ${INSTALL_WEB} == true ]] ; then echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " if ! fully_fetch_repo "${webInterfaceDir}" ; then echo "::: Fetching all branches for Pi-hole web interface repo failed!" From 38547ced7a83d87c4cb0acc2234dd4ad2f61cac9 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 11 Mar 2017 16:55:37 +0100 Subject: [PATCH 113/165] Can only diff once upstream branch is tracked --- advanced/Scripts/piholeCheckout.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index a3398daa41..258747443c 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -63,11 +63,15 @@ checkout_pull_branch() { local branch="${2}" cd "${directory}" || return 1 - if [ "$(git diff "${branch}" | grep -c "^")" -gt "0" ]; then + + local oldbranch="$(git symbolic-ref HEAD)" + + git checkout "${branch}" || return 1 + + if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then update=true fi - git checkout "${branch}" || return 1 git pull || return 1 return 0 } From a2404f104a2ab430c20ea4841cd935e9ec25f3d0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 11 Mar 2017 12:21:15 -0800 Subject: [PATCH 114/165] Just some style and linting. And a `cd` in `fetch_checkout_pull_branch` Signed-off-by: Dan Schaper --- advanced/Scripts/piholeCheckout.sh | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 258747443c..fe46d41376 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -19,7 +19,7 @@ PH_TEST="true" source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" source "${setupVars}" -update=false +update="false" fully_fetch_repo() { # Add upstream branches to shallow clone @@ -52,6 +52,7 @@ fetch_checkout_pull_branch() { local branch="${2}" # Set the reference for the requested branch, fetch, check it put and pull it + cd "${directory}" git remote set-branches origin "${branch}" || return 1 git fetch --quiet || return 1 checkout_pull_branch "${directory}" "${branch}" || return 1 @@ -61,15 +62,16 @@ checkout_pull_branch() { # Check out specified branch local directory="${1}" local branch="${2}" + local oldbranch cd "${directory}" || return 1 - local oldbranch="$(git symbolic-ref HEAD)" + oldbranch="$(git symbolic-ref HEAD)" git checkout "${branch}" || return 1 if [ "$(git diff "${oldbranch}" | grep -c "^")" -gt "0" ]; then - update=true + update="true" fi git pull || return 1 @@ -106,7 +108,7 @@ checkout() echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi - if [[ ${INSTALL_WEB} == true ]]; then + if [[ ${INSTALL_WEB} == "true" ]]; then if ! is_repo "${webInterfaceDir}" ; then echo "::: Critical Error: Web Admin repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" @@ -130,7 +132,7 @@ checkout() echo "::: Shortcut \"dev\" detected - checking out development / devel branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "development" || { echo "Unable to pull Core developement branch"; exit 1; } - if [[ ${INSTALL_WEB} == true ]]; then + if [[ ${INSTALL_WEB} == "true" ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "devel" || { echo "Unable to pull Web development branch"; exit 1; } fi @@ -140,7 +142,7 @@ checkout() echo "::: Shortcut \"master\" detected - checking out master branches ..." echo "::: Pi-hole core" fetch_checkout_pull_branch "${PI_HOLE_FILES_DIR}" "master" || { echo "Unable to pull Core master branch"; exit 1; } - if [[ ${INSTALL_WEB} == true ]]; then + if [[ ${INSTALL_WEB} == "true" ]]; then echo "::: Web interface" fetch_checkout_pull_branch "${webInterfaceDir}" "master" || { echo "Unable to pull web master branch"; exit 1; } fi @@ -163,7 +165,7 @@ checkout() exit 1 fi checkout_pull_branch "${PI_HOLE_FILES_DIR}" "${2}" - elif [[ "${1}" == "web" && ${INSTALL_WEB} == true ]] ; then + elif [[ "${1}" == "web" && "${INSTALL_WEB}" == "true" ]] ; then echo -n "::: Fetching remote branches for the web interface from ${webInterfaceGitUrl} ... " if ! fully_fetch_repo "${webInterfaceDir}" ; then echo "::: Fetching all branches for Pi-hole web interface repo failed!" @@ -187,7 +189,7 @@ checkout() fi # Force updating everything - if [[ ! "${1}" == "web" && ${update} ]]; then + if [[ ! "${1}" == "web" && "${update}" ]]; then echo "::: Running installer to upgrade your installation" if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0 From b0ae954f1eae4d21ce976020d69d3d10022ff095 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 11 Mar 2017 12:37:36 -0800 Subject: [PATCH 115/165] Only update when `update` flag is set to "true" Signed-off-by: Dan Schaper --- 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 fe46d41376..3b7abbef0f 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -189,7 +189,7 @@ checkout() fi # Force updating everything - if [[ ! "${1}" == "web" && "${update}" ]]; then + if [[ ! "${1}" == "web" && "${update}" == "true" ]]; then echo "::: Running installer to upgrade your installation" if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then exit 0 From d7b5870ba63c23cb873f541b394d43d669372262 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 12 Mar 2017 23:15:23 +0100 Subject: [PATCH 116/165] Use absolute path for pihole command in gravity.sh. Fixes #1318 --- gravity.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 085902519f..7441dd877f 100755 --- a/gravity.sh +++ b/gravity.sh @@ -26,10 +26,11 @@ EOM exit 0 } +PIHOLE_COMMAND="/usr/local/bin/pihole" adListFile=/etc/pihole/adlists.list adListDefault=/etc/pihole/adlists.default -whitelistScript="pihole -w" +whitelistScript="${PIHOLE_COMMAND} -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" @@ -385,7 +386,7 @@ gravity_reload() { #Now replace the line in dnsmasq file # sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf - pihole restartdns + "${PIHOLE_COMMAND}" restartdns echo " done!" } @@ -423,4 +424,4 @@ gravity_hostFormat gravity_blackbody gravity_reload -pihole status +"${PIHOLE_COMMAND}" status From e45559da206978c2a6b89eadf876180034a0c768 Mon Sep 17 00:00:00 2001 From: georou Date: Tue, 14 Mar 2017 01:13:23 +1100 Subject: [PATCH 117/165] Use Firewalld services instead of ports --- 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 7c9a83d507..b9e38befc0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -965,7 +965,7 @@ configureFirewall() { whiptail --title "Firewall in use" --yesno "We have detected a running firewall\n\nPi-hole currently requires HTTP and DNS port access.\n\n\n\nInstall Pi-hole default firewall rules?" ${r} ${c} || \ { echo -e ":::\n::: Not installing firewall rulesets."; return 0; } echo -e ":::\n:::\n Configuring FirewallD for httpd and dnsmasq." - firewall-cmd --permanent --add-port=80/tcp --add-port=53/tcp --add-port=53/udp + firewall-cmd --permanent --add-service={http,dns} firewall-cmd --reload return 0 # Check for proper kernel modules to prevent failure From 6b862dd9e959a312984b00014d42a938376e4243 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 13 Mar 2017 20:32:23 +0000 Subject: [PATCH 118/165] Only remove from wildcard list if domain is being added to whitelist or blacklist --- advanced/Scripts/list.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/list.sh b/advanced/Scripts/list.sh index 2ac1e805f6..537ebac382 100755 --- a/advanced/Scripts/list.sh +++ b/advanced/Scripts/list.sh @@ -84,7 +84,9 @@ PoplistFile() { if ${addmode}; then AddDomain "${dom}" "${listMain}" RemoveDomain "${dom}" "${listAlt}" - RemoveDomain "${dom}" "${wildcardlist}" + if [[ "${listMain}" == "${whitelist}" || "${listMain}" == "${blacklist}" ]]; then + RemoveDomain "${dom}" "${wildcardlist}" + fi else RemoveDomain "${dom}" "${listMain}" fi From 76bd53ef1fd6dadbc206efda5282bd2742213840 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Mon, 13 Mar 2017 20:24:04 -0400 Subject: [PATCH 119/165] replace instances of "/etc/.pihole" with ${PI_HOLE_LOCAL_REPO} --- automated install/basic-install.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f168675e60..dce52a3db1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -582,8 +582,8 @@ version_check_dnsmasq() { local dnsmasq_conf="/etc/dnsmasq.conf" local dnsmasq_conf_orig="/etc/dnsmasq.conf.orig" local dnsmasq_pihole_id_string="addn-hosts=/etc/pihole/gravity.list" - local dnsmasq_original_config="/etc/.pihole/advanced/dnsmasq.conf.original" - local dnsmasq_pihole_01_snippet="/etc/.pihole/advanced/01-pihole.conf" + local dnsmasq_original_config="${PI_HOLE_LOCAL_REPO}/advanced/dnsmasq.conf.original" + local dnsmasq_pihole_01_snippet="${PI_HOLE_LOCAL_REPO}/advanced/01-pihole.conf" local dnsmasq_pihole_01_location="/etc/dnsmasq.d/01-pihole.conf" if [ -f ${dnsmasq_conf} ]; then @@ -669,7 +669,7 @@ installScripts() { } installConfigs() { - # Install the configs from /etc/.pihole to their various locations + # Install the configs from ${PI_HOLE_LOCAL_REPO} to their various locations echo ":::" echo "::: Installing configs..." version_check_dnsmasq @@ -682,7 +682,7 @@ installConfigs() { elif [ -f "/etc/lighttpd/lighttpd.conf" ]; then mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi - cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf + cp ${PI_HOLE_LOCAL_REPO}/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf mkdir -p /var/run/lighttpd chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd mkdir -p /var/cache/lighttpd/compress @@ -835,7 +835,7 @@ installPiholeWeb() { echo "::: Existing index.php detected, not overwriting" else echo -n "::: index.php missing, replacing... " - cp /etc/.pihole/advanced/index.php /var/www/html/pihole/ + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.php /var/www/html/pihole/ echo " done!" fi @@ -843,7 +843,7 @@ installPiholeWeb() { echo "::: Existing index.js detected, not overwriting" else echo -n "::: index.js missing, replacing... " - cp /etc/.pihole/advanced/index.js /var/www/html/pihole/ + cp ${PI_HOLE_LOCAL_REPO}/advanced/index.js /var/www/html/pihole/ echo " done!" fi @@ -851,14 +851,14 @@ installPiholeWeb() { echo "::: Existing blockingpage.css detected, not overwriting" else echo -n "::: blockingpage.css missing, replacing... " - cp /etc/.pihole/advanced/blockingpage.css /var/www/html/pihole + cp ${PI_HOLE_LOCAL_REPO}/advanced/blockingpage.css /var/www/html/pihole echo " done!" fi else echo "::: Creating directory for blocking page" install -d /var/www/html/pihole - install -D /etc/.pihole/advanced/{index,blockingpage}.* /var/www/html/pihole/ + install -D ${PI_HOLE_LOCAL_REPO}/advanced/{index,blockingpage}.* /var/www/html/pihole/ if [ -f /var/www/html/index.lighttpd.html ]; then mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig else @@ -871,7 +871,7 @@ installPiholeWeb() { echo ":::" echo -n "::: Installing sudoer file..." mkdir -p /etc/sudoers.d/ - cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole + cp ${PI_HOLE_LOCAL_REPO}/advanced/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 @@ -889,7 +889,7 @@ installCron() { # Install the cron job echo ":::" echo -n "::: Installing latest Cron script..." - cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole + cp ${PI_HOLE_LOCAL_REPO}/advanced/pihole.cron /etc/cron.d/pihole echo " done!" } @@ -903,7 +903,7 @@ runGravity() { fi # Test if /etc/pihole/adlists.default exists if [[ ! -e /etc/pihole/adlists.default ]]; then - cp /etc/.pihole/adlists.default /etc/pihole/adlists.default + cp ${PI_HOLE_LOCAL_REPO}/adlists.default /etc/pihole/adlists.default fi echo "::: Running gravity.sh" { /opt/pihole/gravity.sh; } @@ -978,7 +978,7 @@ finalExports() { # Look for DNS server settings which would have to be reapplied source "${setupVars}" - source "/etc/.pihole/advanced/Scripts/webpage.sh" + source "${PI_HOLE_LOCAL_REPO}/advanced/Scripts/webpage.sh" if [[ "${DNS_FQDN_REQUIRED}" != "" ]] ; then ProcessDNSSettings @@ -993,7 +993,7 @@ installLogrotate() { # Install the logrotate script echo ":::" echo -n "::: Installing latest logrotate script..." - cp /etc/.pihole/advanced/logrotate /etc/pihole/logrotate + cp ${PI_HOLE_LOCAL_REPO}/advanced/logrotate /etc/pihole/logrotate # Different operating systems have different user / group # settings for logrotate that makes it impossible to create # a static logrotate file that will work with e.g. From c4b43f92ce1a7534c935e6ae0c45b2105dba206b Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 14 Mar 2017 13:19:43 -0400 Subject: [PATCH 120/165] Fix help text bug Fixes #1325 --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index dda6d7500b..d2f87b711b 100755 --- a/pihole +++ b/pihole @@ -297,7 +297,7 @@ helpFunc() { ::: -b, blacklist Blacklist domain(s) (exact match) ::: -wild, wildcard Blacklist whole domain(s) (wildcard) ::: -d, debug Start a debugging session -::: Automated debugging can be enabled with `-a`. +::: Automated debugging can be enabled with '-a'. ::: 'pihole -d -a' ::: -f, flush Flush the 'pihole.log' file ::: -t, tail Output the last lines of the 'pihole.log' file. Lines are appended as the file grows From cfaf1ac67c6a99735954737dc4c527722a520021 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 15 Mar 2017 18:59:41 +0000 Subject: [PATCH 121/165] add check on file_parse to not include WEBPASSWORD= in the debug log --- 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 df9ed4f0e0..4f8565469c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -84,7 +84,7 @@ header_write() { file_parse() { while read -r line; do if [ ! -z "${line}" ]; then - [[ "${line}" =~ ^#.*$ || ! "${line}" ]] && continue + [[ "${line}" =~ ^#.*$ || ! "${line}" || "${line}" == "WEBPASSWORD="* ]] && continue log_write "${line}" fi done < "${1}" From 83662c9e5006361f52a8ad36bb447518c358d62e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 15 Mar 2017 19:50:22 +0000 Subject: [PATCH 122/165] additional requested changes --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d22f84191e..dce04e0283 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -706,9 +706,9 @@ installScripts() { } installConfigs() { - # Install the configs from ${PI_HOLE_LOCAL_REPO} to their various locations + # Install the configs from PI_HOLE_LOCAL_REPO to their various locations echo ":::" - echo "::: Installing configs..." + echo "::: Installing configs from ${PI_HOLE_LOCAL_REPO}..." version_check_dnsmasq #Only mess with lighttpd configs if user has chosen to install web interface From ab2af11775ab52bc28d0e2258467e69ad9a6cc43 Mon Sep 17 00:00:00 2001 From: Wandmalfarbe Date: Wed, 15 Mar 2017 20:58:41 +0100 Subject: [PATCH 123/165] Fixed minor spelling mistakes in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a5f7f4c63..3369d7e22d 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ The [gravity.sh](https://github.com/pi-hole/pi-hole/blob/master/gravity.sh) does #### Other Operating Systems -The automated install is only for a clean install of a Debian family or Fedora based system, such as the Raspberry Pi. However, this script will work for most UNIX-like systems, some with some slight **modifications** that we can help you work through. If you can install `dnsmasq` and a Webserver, it should work OK. If there are other platforms you'd like supported, let us know. +The automated install is only for a clean install of a Debian family or Fedora based system, such as the Raspberry Pi. However, this script will work for most UNIX-like systems, some with some slight **modifications** that we can help you work through. If you can install `dnsmasq` and a web server, it should work OK. If there are other platforms you'd like supported, let us know. ### Web Interface @@ -144,7 +144,7 @@ You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my- - [Get LED alerts for each blocked ad](http://thetimmy.silvernight.org/pages/endisbutton/) - [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) - [Docker Pi-hole container (x86 and ARM)](https://hub.docker.com/r/diginc/pi-hole/) -- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/) +- [Splunk: Pi-hole Visualiser](https://splunkbase.splunk.com/app/3023/) - [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension)) - [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037) - [Sky-Hole](http://dlaa.me/blog/post/skyhole) From 0d794226ab9ac7c598b7fc7371dbc68a5a2777ba Mon Sep 17 00:00:00 2001 From: georou Date: Thu, 16 Mar 2017 09:29:33 +1100 Subject: [PATCH 124/165] Removed unsupported POSIX brace expansion --- 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 b9e38befc0..3373a41cb0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -965,7 +965,7 @@ configureFirewall() { whiptail --title "Firewall in use" --yesno "We have detected a running firewall\n\nPi-hole currently requires HTTP and DNS port access.\n\n\n\nInstall Pi-hole default firewall rules?" ${r} ${c} || \ { echo -e ":::\n::: Not installing firewall rulesets."; return 0; } echo -e ":::\n:::\n Configuring FirewallD for httpd and dnsmasq." - firewall-cmd --permanent --add-service={http,dns} + firewall-cmd --permanent --add-service=http --add-service=dns firewall-cmd --reload return 0 # Check for proper kernel modules to prevent failure From 6c5666540328d36806a63c12303d467ac092822e Mon Sep 17 00:00:00 2001 From: georou Date: Thu, 16 Mar 2017 10:26:51 +1100 Subject: [PATCH 125/165] updated travis for new firewalld add service --- test/test_automated_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 19c662c69c..8e36fc965a 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -78,7 +78,7 @@ def test_configureFirewall_firewalld_running_no_errors(Pihole): assert expected_stdout in configureFirewall.stdout firewall_calls = Pihole.run('cat /var/log/firewall-cmd').stdout assert 'firewall-cmd --state' in firewall_calls - assert 'firewall-cmd --permanent --add-port=80/tcp --add-port=53/tcp --add-port=53/udp' in firewall_calls + assert 'firewall-cmd --permanent --add-service=http --add-service=dns' in firewall_calls assert 'firewall-cmd --reload' in firewall_calls def test_configureFirewall_firewalld_disabled_no_errors(Pihole): From 2834f2ccc290b89b043dc0c05d5fd9d95747cf49 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 22:05:48 -0700 Subject: [PATCH 126/165] Let `ip` determine which links are candidates. Signed-off-by: Dan Schaper --- 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 7c9a83d507..b1ee90d6a4 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -233,7 +233,7 @@ find_IPv4_information() { get_available_interfaces() { # Get available UP interfaces. - availableInterfaces=$(ip -o link | grep -v "state DOWN\|lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) + availableInterfaces=$(ip --oneline link show up | grep -v "lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1) } welcomeDialogs() { From e9f1ca338ffe1a626eb868693f138430ff1ac67a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 22:49:47 -0700 Subject: [PATCH 127/165] Create temp files for working storage, log to working storage temps. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index df9ed4f0e0..3ecc3f4b08 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -52,7 +52,7 @@ source ${VARSFILE} ### Private functions exist here ### log_write() { - echo "${1}" >> "${DEBUG_LOG}" + printf "%b" "${@}" >&3 } log_echo() { @@ -417,7 +417,7 @@ dumpPiHoleLog() { if [ -e "${PIHOLELOG}" ]; then # Dummy process to use for flagging down tail to terminate countdown & - tail -n0 -f --pid=$! "${PIHOLELOG}" >> ${DEBUG_LOG} + tail -n0 -f --pid=$! "${PIHOLELOG}" >&4 else log_write "No pihole.log file found!" printf ":::\tNo pihole.log file found!\n" @@ -456,6 +456,17 @@ finalWork() { } ### END FUNCTIONS ### +# Create temporary file for log +TEMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX) +# Open handle 3 for templog +exec 3>"$TEMPLOG" +# Delete templog, but allow for addressing via file handle. +rm "$TEMPLOG" + +# Create temporary file for logdump using file handle 4 +DUMPLOG=$(mktemp /tmp/pihole_temp.XXXXXX) +exec 4>"$DUMPLOG" +rm "$DUMPLOG" # Gather version of required packages / repositories version_check || echo "REQUIRED FILES MISSING" From 0a0c3a2fb76fdee1c6d01d32d0e18786e8df29f7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:20:12 -0700 Subject: [PATCH 128/165] Copy working temp to final location. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3ecc3f4b08..8649bb901d 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -43,16 +43,11 @@ cat << EOM ::: Please read and note any issues, and follow any directions advised during this process. EOM -# Ensure the file exists, create if not, clear if exists. -truncate --size=0 "${DEBUG_LOG}" -chmod 644 ${DEBUG_LOG} -chown "$USER":pihole ${DEBUG_LOG} - source ${VARSFILE} ### Private functions exist here ### log_write() { - printf "%b" "${@}" >&3 + echo "${@}" >&3 } log_echo() { @@ -363,9 +358,9 @@ testChaos(){ log_write "Pi-hole dnsmasq specific records lookups" log_write "Cache Size:" - dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} + log_write $(dig +short chaos txt cachesize.bind) log_write "Upstream Servers:" - dig +short chaos txt servers.bind >> ${DEBUG_LOG} + log_write $(dig +short chaos txt servers.bind) log_write "" } @@ -378,7 +373,7 @@ checkProcesses() { log_write "" log_write "${i}" log_write " processes status:" - systemctl -l status "${i}" >> "${DEBUG_LOG}" + log_write $(systemctl -l status "${i}") done log_write "" } @@ -428,6 +423,14 @@ dumpPiHoleLog() { finalWork() { local tricorder echo "::: Finshed debugging!" + + # Ensure the file exists, create if not, clear if exists. + truncate --size=0 "${DEBUG_LOG}" + chmod 644 ${DEBUG_LOG} + chown "$USER":pihole ${DEBUG_LOG} + # copy working temp file to final log location + cp /proc/$$/fd/3 "$DEBUG_LOG" + echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." if [[ "${AUTOMATED}" ]]; then echo "::: Debug script running in automated mode, uploading log to tricorder..." From 160030b75f3ad6124001fe97cd8ba5468106c5e9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:27:18 -0700 Subject: [PATCH 129/165] Quiet systemctl output to just the current daemon status. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8649bb901d..136d92d1b8 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -72,7 +72,7 @@ log_echo() { header_write() { log_echo "" - log_echo "${1}" + log_echo "---= ${1}" log_write "" } @@ -370,10 +370,8 @@ checkProcesses() { echo "::: Logging status of lighttpd, dnsmasq and pihole-FTL..." PROCESSES=( lighttpd dnsmasq pihole-FTL ) for i in "${PROCESSES[@]}"; do - log_write "" - log_write "${i}" - log_write " processes status:" - log_write $(systemctl -l status "${i}") + log_write "Status for ${i} daemon:" + log_write $(systemctl is-active "${i}") done log_write "" } From 77378da70ad49f6467ac008e8e3f06dc3c543f8c Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:43:41 -0700 Subject: [PATCH 130/165] Cat out temp files to final log. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 136d92d1b8..d3c85d3a82 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -427,7 +427,9 @@ finalWork() { chmod 644 ${DEBUG_LOG} chown "$USER":pihole ${DEBUG_LOG} # copy working temp file to final log location - cp /proc/$$/fd/3 "$DEBUG_LOG" + cat /proc/$$/fd/3 >> "${DEBUG_LOG}" + # Straight dump of tailing the logs, can sanitize later if needed. + cat /proc/$$/fd/4 >> "${DEBUG_LOG}" echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." if [[ "${AUTOMATED}" ]]; then From b1f769b671bfdfd424172b754ef2f6cc6cb31aee Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 15 Mar 2017 23:50:29 -0700 Subject: [PATCH 131/165] Output cleaning, IP stack check headers. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d3c85d3a82..6274e04eb0 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -226,6 +226,7 @@ ipv6_check() { ip_check() { local protocol=${1} local gravity=${2} + header_write "Checking IPv${protocol} Stack" local ip_addr_list="$(ip -${protocol} addr show dev ${PIHOLE_INTERFACE} | awk -F ' ' '{ for(i=1;i<=NF;i++) if ($i ~ '/^inet/') print $(i+1) }')" if [[ -n ${ip_addr_list} ]]; then From fd584dd03baa7ee15b57590b35113c600e8c986d Mon Sep 17 00:00:00 2001 From: Anthony Giorgio Date: Sat, 18 Mar 2017 20:47:13 -0400 Subject: [PATCH 132/165] Formatting cleanup. Convert backticks to quotes to fix error message. Make Pi-hole capitalization consistent. Make Pi-hole capitalization consistent. --- pihole | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pihole b/pihole index d2f87b711b..83e130007d 100755 --- a/pihole +++ b/pihole @@ -287,10 +287,10 @@ piholeCheckoutFunc() { helpFunc() { cat << EOM -::: Control all PiHole specific functions! +::: Control all Pi-hole specific functions ::: ::: Usage: pihole [options] -::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -a (admin) for more information on usage +::: Add -h after -w (whitelist), -b (blacklist), -c (chronometer), or -a (admin) for more information on usage ::: ::: Options: ::: -w, whitelist Whitelist domain(s) @@ -306,15 +306,15 @@ helpFunc() { ::: -g, updateGravity Update the list of ad-serving domains ::: -c, chronometer Calculates stats and displays to an LCD ::: -h, help Show this help dialog -::: -v, version Show installed versions of Pi-Hole and Web-Admin +::: -v, version Show installed versions of Pi-hole and Web-Admin ::: -q, query Query the adlists for a specific domain ::: 'pihole -q domain -exact' shows exact matches only ::: -l, logging Enable or Disable logging (pass 'on' or 'off') ::: -a, admin Admin webpage options -::: uninstall Uninstall Pi-Hole from your system :(! -::: status Is Pi-Hole Enabled or Disabled -::: enable Enable Pi-Hole DNS Blocking -::: disable Disable Pi-Hole DNS Blocking +::: uninstall Uninstall Pi-hole from your system! :( +::: status Display if Pi-hole is Enabled or Disabled +::: enable Enable Pi-hole DNS Blocking +::: disable Disable Pi-hole DNS Blocking ::: Blocking can also be disabled only temporarily, e.g., ::: 'pihole disable 5m' - will disable blocking for 5 minutes ::: restartdns Restart dnsmasq From 48c19ade8e449c439341ee12fc6541d6ac7998c1 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sun, 19 Mar 2017 15:36:22 -0500 Subject: [PATCH 133/165] add trademarks to Pi-hole name in signifigant places --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3369d7e22d..0bfd66145a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ## The multi-platform, network-wide ad blocker -Block ads for **all** your devices _without_ the need to install client-side software. The Pi-hole blocks ads at the DNS-level, so all your devices are protected. +Block ads for **all** your devices _without_ the need to install client-side software. The Pi-hole™ blocks ads at the DNS-level, so all your devices are protected. - Web Browsers - Cell Phones @@ -53,9 +53,9 @@ wget -O basic-install.sh https://install.pi-hole.net bash basic-install.sh ``` -Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to use Pi-hole as their DNS server. +Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to use Pi-hole™ as their DNS server. -## What is Pi-hole and how do I install it? +## What is Pi-hole™ and how do I install it?

@@ -73,7 +73,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei ## Technical Details -The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. +The Pi-hole™ is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. ### Gravity @@ -102,7 +102,7 @@ Domains can be whitelisted and blacklisted using either the web interface or the ### Settings -The settings page lets you control and configure your Pi-hole. You can do things like: +The settings page lets you control and configure your Pi-hole™. You can do things like: - enable Pi-hole's built-in DHCP server - exclude domains from the graphs @@ -113,7 +113,7 @@ The settings page lets you control and configure your Pi-hole. You can do thing #### Built-in DHCP Server -Pi-hole ships with a built-in DHCP server. This allows you to let your network devices use Pi-hole as their DNS server if your router does not let you adjust the DHCP options. +Pi-hole™ ships with a built-in DHCP server. This allows you to let your network devices use Pi-hole™ as their DNS server if your router does not let you adjust the DHCP options.

@@ -137,7 +137,7 @@ The same output can be achieved on the CLI by running `chronometer.sh -j` You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my-pi-holes-stats-over-ssh-or-on-an-lcd-using-chronometer/240) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) -## Pi-hole Projects +## Pi-hole™ Projects - [An ad blocking Magic Mirror](https://zonksec.com/blog/magic-mirror-dns-filtering/#dnssoftware) - [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) From 1cd4710718fee3247184ddbb0661e304e79c036d Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sun, 19 Mar 2017 15:41:16 -0500 Subject: [PATCH 134/165] replace logo with TM logo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bfd66145a..456eea2f1f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

- +

## The multi-platform, network-wide ad blocker From af1d1bd9c21e26b4700f8a2853cbdfb9ba4aa9a6 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 21 Mar 2017 05:04:58 -0700 Subject: [PATCH 135/165] One more change Signed-off-by: Dan Schaper --- 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 dce04e0283..2a1498c3e0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1221,7 +1221,7 @@ FTLinstall() { stop_service pihole-FTL &> /dev/null install -T -m 0755 /tmp/${binary} /usr/bin/pihole-FTL cd "${orig_dir}" - install -T -m 0755 "/etc/.pihole/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" + install -T -m 0755 "${PI_HOLE_LOCAL_REPO}/advanced/pihole-FTL.service" "/etc/init.d/pihole-FTL" echo "done." return 0 else From fb3e6ee35c6789574fd4165736bef7bce3075a32 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 21 Mar 2017 18:01:51 -0400 Subject: [PATCH 136/165] Source setupVars before attempting to use it Fixes #1347 --- advanced/Scripts/update.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 4a2e404542..115e2d8cf5 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -90,6 +90,7 @@ FTLcheckUpdate() { main() { local pihole_version_current local web_version_current + source "${setupVars}" #This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then From 598a7b3cc0427cc62bd5e3203fff43b1bd6796ac Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 22 Mar 2017 13:44:04 -0700 Subject: [PATCH 137/165] Add .editorconfig Signed-off-by: Dan Schaper --- .editorconfig | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..325648fc3a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,38 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = tab +tab_width = 2 +charset = utf-8 +trim_trailing_whitespace = true + +# Matches multiple files with brace expansion notation +# Set default charset +[*.{js,py}] +charset = utf-8 + +# 4 space indentation +[*.py] +indent_style = space +indent_size = 4 + +# Tab indentation (no size specified) +[Makefile] +indent_style = tab + +# Indentation override for all JS under lib directory +[lib/**.js] +indent_style = space +indent_size = 2 + +# Matches the exact files either package.json or .travis.yml +[{package.json,.travis.yml}] +indent_style = space +indent_size = 2 From ee296f36c199bcf26b3d944fb3a4cc7b04fe8cc4 Mon Sep 17 00:00:00 2001 From: Patrick O'Brien Date: Thu, 23 Mar 2017 18:47:30 -0400 Subject: [PATCH 138/165] mask password input on command line --- advanced/Scripts/webpage.sh | 14 ++++++++------ automated install/basic-install.sh | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9637cc6ffe..55ae3d96f6 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -81,19 +81,21 @@ SetWebPassword(){ exit 1 fi - # Set password only if there is one to be set - if (( ${#args[2]} > 0 )) ; then + read -s -p "Enter New Password: " PASSWORD + echo "" + read -s -p "Confirm Password: " CONFIRM + echo "" + if [ "${PASSWORD}" == "${CONFIRM}" ] ; then # Compute password hash twice to avoid rainbow table vulnerability - hash=$(echo -n ${args[2]} | sha256sum | sed 's/\s.*$//') + hash=$(echo -n ${PASSWORD} | sha256sum | sed 's/\s.*$//') hash=$(echo -n ${hash} | sha256sum | sed 's/\s.*$//') # Save hash to file change_setting "WEBPASSWORD" "${hash}" echo "New password set" else - change_setting "WEBPASSWORD" "" - echo "Password removed" + echo "Passwords don't match. Your password has not been changed" + exit 1 fi - } ProcessDNSSettings() { diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index b1ee90d6a4..bf083adbc6 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1460,7 +1460,7 @@ main() { echo "::: ${pw}" echo ":::" echo "::: You can always change it using" - echo "::: pihole -a -p new_password" + echo "::: pihole -a -p" fi fi From 6eb9192cd196c91dacfbfb9378727fe47000fe2f Mon Sep 17 00:00:00 2001 From: Flo Date: Sat, 25 Mar 2017 16:11:37 +0100 Subject: [PATCH 139/165] Complete site The start -tag was missing. --- advanced/index.php | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/index.php b/advanced/index.php index c076f92d63..4cce2857b2 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -48,6 +48,7 @@ ?> + Website Blocked From a463250ecf3658fa2b1084261ef7979faf76bdba Mon Sep 17 00:00:00 2001 From: Patrick O'Brien Date: Mon, 27 Mar 2017 13:37:19 -0400 Subject: [PATCH 140/165] don't hash an empty password --- .gitignore | 2 ++ advanced/Scripts/webpage.sh | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 91014dcdcb..e7ebe0b6c0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ __pycache__ .cache .pullapprove.yml +Vagrantfile +.vagrant/ diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 55ae3d96f6..c6717cf118 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -81,8 +81,15 @@ SetWebPassword(){ exit 1 fi - read -s -p "Enter New Password: " PASSWORD + read -s -p "Enter New Password (Blank for no password): " PASSWORD echo "" + + if [ "${PASSWORD}" == "" ]; then + change_setting "WEBPASSWORD" "" + echo "Password Removed" + exit 0 + fi + read -s -p "Confirm Password: " CONFIRM echo "" if [ "${PASSWORD}" == "${CONFIRM}" ] ; then From f09c1663508aceca758a39a1912c549fa6339042 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 28 Mar 2017 23:02:00 +0100 Subject: [PATCH 141/165] Improve Error 404 page behavior --- advanced/index.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/advanced/index.php b/advanced/index.php index 4cce2857b2..830ff4f507 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -1,15 +1,31 @@ Date: Fri, 31 Mar 2017 18:55:07 +0100 Subject: [PATCH 142/165] trim down default adlist --- adlists.default | 55 +++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/adlists.default b/adlists.default index 4a5bca3c7d..94c75beb81 100644 --- a/adlists.default +++ b/adlists.default @@ -1,53 +1,22 @@ -## Pi-hole ad-list default sources. Updated 29/10/2016 ######################### -# # -# To make changes to this file: # -# 1. run `cp /etc/pihole/adlists.default /etc/pihole/adlists.list` # -# 2. run `nano /etc/pihole/adlists.list` # -# 3. Uncomment or comment any of the below lists # -# # -# Know of any other lists? Feel free to let us know about them, or add them # -# to this file! # -################################################################################ - # The below list amalgamates several lists we used previously. # See `https://github.com/StevenBlack/hosts` for details +##StevenBlack's list https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -# Other lists we consider safe: +##MalwareDomains https://mirror1.malwaredomains.com/files/justdomains -http://sysctl.org/cameleon/hosts -https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist -https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt -https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt - -# hosts-file.net list. Updated frequently, but has been known to block legitimate sites. -https://hosts-file.net/ad_servers.txt -# Mahakala list. Has been known to block legitimate domains including the entire .com range. -# Warning: Due to the sheer size of this list, the web admin console will be unresponsive. -#https://adblock.mahakala.is/ - -# ADZHOSTS list. Has been known to block legitimate domains -#http://pilotfiber.dl.sourceforge.net/project/adzhosts/HOSTS.txt - -# Windows 10 telemetry list -#https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/win10/spy.txt +##Cameleon +http://sysctl.org/cameleon/hosts -# Securemecca.com list - Also blocks "adult" sites (pornography/gambling etc) -#http://securemecca.com/Downloads/hosts.txt +##Zeustracker +https://zeustracker.abuse.ch/blocklist.php?download=domainblocklist -# Quidsup's tracker list -#https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt +##Disconnect.me Tracking +https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt -# Block the BBC News website Breaking News banner -#https://raw.githubusercontent.com/BreakingTheNews/BreakingTheNews.github.io/master/hosts +##Disconnect.me Ads +https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt -# Untested Lists: -#https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt -#https://raw.githubusercontent.com/Dawsey21/Lists/master/main-blacklist.txt -#http://malwaredomains.lehigh.edu/files/domains.txt -# Following two lists should be used simultaneously: (readme https://github.com/notracking/hosts-blocklists/) -#https://raw.github.com/notracking/hosts-blocklists/master/hostnames.txt -#https://raw.github.com/notracking/hosts-blocklists/master/domains.txt -# Combination of several host files on the internet (warning some facebook domains are also blocked but you can go to facebook.com). See https://github.com/mat1th/Dns-add-block for more information. -#https://raw.githubusercontent.com/mat1th/Dns-add-block/master/hosts +##Hosts-file.net +https://hosts-file.net/ad_servers.txt \ No newline at end of file From ce97896ffd9f9cfd7650804c84524978705403eb Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:00:04 +0100 Subject: [PATCH 143/165] account for new `adlists.custom` file --- gravity.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7441dd877f..af6c859903 100755 --- a/gravity.sh +++ b/gravity.sh @@ -30,6 +30,7 @@ PIHOLE_COMMAND="/usr/local/bin/pihole" adListFile=/etc/pihole/adlists.list adListDefault=/etc/pihole/adlists.default +adListCustom=/etc/pihole/adlists.custom whitelistScript="${PIHOLE_COMMAND} -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt @@ -75,8 +76,8 @@ gravity_collapse() { echo ":::" #Decide if we're using a custom ad block list, or defaults. if [ -f ${adListFile} ]; then - #custom file found, use this instead of default - echo -n "::: Custom adList file detected. Reading..." + #User has disabled one or more default lists + echo -n "::: Changes to default list detected. Reading adlists.list..." sources=() while IFS= read -r line || [[ -n "$line" ]]; do #Do not read commented out or blank lines @@ -88,8 +89,8 @@ gravity_collapse() { done < ${adListFile} echo " done!" else - #no custom file found, use defaults! - echo -n "::: No custom adlist file detected, reading from default file..." + # + echo -n "::: No changes to default list detected. Reading adlists.default..." sources=() while IFS= read -r line || [[ -n "$line" ]]; do #Do not read commented out or blank lines @@ -101,6 +102,19 @@ gravity_collapse() { done < ${adListDefault} echo " done!" fi + + if [ -f ${adListCustom} ]; then + echo -n "Custom additional lists detected. Reading adlists.custom..." + while IFS= read -r line || [[ -n "$line" ]]; do + #Do not read commented out or blank lines + if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then + echo "" > /dev/null + else + sources+=(${line}) + fi + done < ${adListCustom} + echo " done!" + fi } # patternCheck - check to see if curl downloaded any new files. From e720de401d1a8dbe17006c94addb150ec1f782d6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:16:09 +0100 Subject: [PATCH 144/165] One file to rule them all, same functionality (made changes and want to go back to default? Delete your adlists.list) --- gravity.sh | 72 ++++++++++++++++++++++-------------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/gravity.sh b/gravity.sh index af6c859903..17166a8507 100755 --- a/gravity.sh +++ b/gravity.sh @@ -29,8 +29,8 @@ EOM PIHOLE_COMMAND="/usr/local/bin/pihole" adListFile=/etc/pihole/adlists.list -adListDefault=/etc/pihole/adlists.default -adListCustom=/etc/pihole/adlists.custom +adListDefault=/etc/pihole/adlists.default #being deprecated +adListRepoDefault=/etc/.pihole/adlists.default whitelistScript="${PIHOLE_COMMAND} -w" whitelistFile=/etc/pihole/whitelist.txt blacklistFile=/etc/pihole/blacklist.txt @@ -72,49 +72,35 @@ fi ########################### # collapse - begin formation of pihole gravity_collapse() { + + #New Logic: + # Does /etc/pihole/adlists.list exist? If so leave it alone + # If not, cp /etc/.pihole/adlists.default /etc/pihole/adlists.list + # Read from adlists.list + + #The following two blocks will sort out any missing adlists in the /etc/pihole directory, and remove legacy adlists.default + if [ -f ${adListDefault} ] && [ -f ${adListFile} ]; then + rm ${adListDefault} + fi + + if [ ! -f ${adListFile} ]; then + cp ${adListRepoDefault} ${adListFile} + fi + echo "::: Neutrino emissions detected..." echo ":::" - #Decide if we're using a custom ad block list, or defaults. - if [ -f ${adListFile} ]; then - #User has disabled one or more default lists - echo -n "::: Changes to default list detected. Reading adlists.list..." - sources=() - while IFS= read -r line || [[ -n "$line" ]]; do - #Do not read commented out or blank lines - if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then - echo "" > /dev/null - else - sources+=(${line}) - fi - done < ${adListFile} - echo " done!" - else - # - echo -n "::: No changes to default list detected. Reading adlists.default..." - sources=() - while IFS= read -r line || [[ -n "$line" ]]; do - #Do not read commented out or blank lines - if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then - echo "" > /dev/null - else - sources+=(${line}) - fi - done < ${adListDefault} - echo " done!" - fi - - if [ -f ${adListCustom} ]; then - echo -n "Custom additional lists detected. Reading adlists.custom..." - while IFS= read -r line || [[ -n "$line" ]]; do - #Do not read commented out or blank lines - if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then - echo "" > /dev/null - else - sources+=(${line}) - fi - done < ${adListCustom} - echo " done!" - fi + #User has disabled one or more default lists + echo -n "::: Pulling source lists into range..." + sources=() + while IFS= read -r line || [[ -n "$line" ]]; do + #Do not read commented out or blank lines + if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then + echo "" > /dev/null + else + sources+=(${line}) + fi + done < ${adListFile} + echo " done!" } # patternCheck - check to see if curl downloaded any new files. From bdc6bd41358680937c7d904fa51f5ae86a4239ad Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:18:28 +0100 Subject: [PATCH 145/165] Don't need this comment anymore --- gravity.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 17166a8507..05593d1e92 100755 --- a/gravity.sh +++ b/gravity.sh @@ -89,7 +89,6 @@ gravity_collapse() { echo "::: Neutrino emissions detected..." echo ":::" - #User has disabled one or more default lists echo -n "::: Pulling source lists into range..." sources=() while IFS= read -r line || [[ -n "$line" ]]; do From 02040cd25d4d4035fa0ae4b18ca63ad51ed34a9b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:23:26 +0100 Subject: [PATCH 146/165] We no longer need to do this, either --- gravity.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 05593d1e92..34e03ca243 100755 --- a/gravity.sh +++ b/gravity.sh @@ -403,8 +403,6 @@ if [[ "${forceGrav}" == true ]]; then echo " done!" fi -#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list -cp /etc/.pihole/adlists.default /etc/pihole/adlists.default gravity_collapse gravity_spinup if [[ "${skipDownload}" == false ]]; then From b4bc90fb8519fec1e1c5b9585aa14996e5b84c13 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 19:35:52 +0100 Subject: [PATCH 147/165] add in CustomizeAdlists function --- advanced/Scripts/webpage.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 9637cc6ffe..b15daf8899 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -319,6 +319,22 @@ SetWebUILayout(){ } +CustomizeAdLists() { + + list = "/etc/pihole/adlists.list" + + if [[ "${args[2]}" == "enable" ]] ; then + sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" + elif [[ "${args[2]}" == "disable" ]] ; then + sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" + elif [[ "${args[2]}" == "add" && "${args[3]}" == "user" ]] ; then + echo "${args[3]}" >> /etc/pihole/adlists.user + else + echo "Not permitted" + return 1 + fi +} + SetPrivacyMode(){ if [[ "${args[2]}" == "true" ]] ; then From 3a3dde629896ba8a02c110e195bec08b19482bf0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:03:56 +0100 Subject: [PATCH 148/165] add adlist argument redirector --- advanced/Scripts/webpage.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index b15daf8899..025681340d 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -458,6 +458,7 @@ main() { "hostrecord" ) SetHostRecord;; "-i" | "interface" ) SetListeningMode;; "-t" | "teleporter" ) Teleporter;; + "adlist" ) CustomizeAdLists;; * ) helpFunc;; esac From 5435b93df2764f7d6e67749e8eac29d180abba27 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:05:45 +0100 Subject: [PATCH 149/165] remove spaces --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 025681340d..887b8f34cb 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -321,7 +321,7 @@ SetWebUILayout(){ CustomizeAdLists() { - list = "/etc/pihole/adlists.list" + list="/etc/pihole/adlists.list" if [[ "${args[2]}" == "enable" ]] ; then sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" From af2cff5177be159ad224b0dd2cb3403c375b3b02 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:13:04 +0100 Subject: [PATCH 150/165] remove call to user list --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 887b8f34cb..974dbdb56b 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -327,8 +327,8 @@ CustomizeAdLists() { sed -i "\\@${args[3]}@s/^#http/http/g" "${list}" elif [[ "${args[2]}" == "disable" ]] ; then sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" - elif [[ "${args[2]}" == "add" && "${args[3]}" == "user" ]] ; then - echo "${args[3]}" >> /etc/pihole/adlists.user + elif [[ "${args[2]}" == "add" ]] ; then + echo "${args[3]}" >> ${list} else echo "Not permitted" return 1 From 42393123a0341e8e00eadbdd14ff9dfeb7250489 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 20:15:13 +0100 Subject: [PATCH 151/165] add newline to adlists.default --- adlists.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adlists.default b/adlists.default index 94c75beb81..f91d7020a9 100644 --- a/adlists.default +++ b/adlists.default @@ -19,4 +19,4 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt ##Hosts-file.net -https://hosts-file.net/ad_servers.txt \ No newline at end of file +https://hosts-file.net/ad_servers.txt From 1f74b1e2fdff929ec280573210aa914d7554b03f Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 21:12:17 +0100 Subject: [PATCH 152/165] newline --- adlists.default | 1 + 1 file changed, 1 insertion(+) diff --git a/adlists.default b/adlists.default index f91d7020a9..cbc1bfb370 100644 --- a/adlists.default +++ b/adlists.default @@ -20,3 +20,4 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt ##Hosts-file.net https://hosts-file.net/ad_servers.txt + From 153031482f77c8ee4757093c8c5b94b3f8afc6f6 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 22:51:10 +0100 Subject: [PATCH 153/165] Add delete mode to adlist command. Might be abetter way to do this --- advanced/Scripts/webpage.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 974dbdb56b..f604a00fab 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -329,6 +329,9 @@ CustomizeAdLists() { sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" elif [[ "${args[2]}" == "add" ]] ; then echo "${args[3]}" >> ${list} + elif [[ "${args[2]}" == "del" ]] ; then + var=$(echo "${args[3]}" | sed 's/\//\\\//g') + sed -i "/${var}/Id" "${list}" else echo "Not permitted" return 1 From 3cf9942465d51a94035bedef72349e9889e22da2 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 31 Mar 2017 23:00:56 +0100 Subject: [PATCH 154/165] spacing fixed --- advanced/Scripts/webpage.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f604a00fab..5b121b44ed 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -329,9 +329,9 @@ CustomizeAdLists() { sed -i "\\@${args[3]}@s/^http/#http/g" "${list}" elif [[ "${args[2]}" == "add" ]] ; then echo "${args[3]}" >> ${list} - elif [[ "${args[2]}" == "del" ]] ; then - var=$(echo "${args[3]}" | sed 's/\//\\\//g') - sed -i "/${var}/Id" "${list}" + elif [[ "${args[2]}" == "del" ]] ; then + var=$(echo "${args[3]}" | sed 's/\//\\\//g') + sed -i "/${var}/Id" "${list}" else echo "Not permitted" return 1 From ce86205df0fbd0499e1770b6d69c7311beaa1d50 Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sun, 2 Apr 2017 12:44:00 -0400 Subject: [PATCH 155/165] Use correct agent when downloading adaway.org list See https://discourse.pi-hole.net/t/2278 --- gravity.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7441dd877f..c1794c33aa 100755 --- a/gravity.sh +++ b/gravity.sh @@ -189,17 +189,21 @@ gravity_spinup() { # Use a case statement to download lists that need special cURL commands # to complete properly and reset the user agent when required case "${domain}" in - "adblock.mahakala.is") + "adblock.mahakala.is") agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' cmd_ext="-e http://forum.xda-developers.com/" ;; + + "adaway.org") + agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' + ;; "pgl.yoyo.org") cmd_ext="-d mimetype=plaintext -d hostformat=hosts" ;; - # Default is a simple request - *) cmd_ext="" + # Default is a simple request + *) cmd_ext="" esac if [[ "${skipDownload}" == false ]]; then echo -n "::: Getting $domain list..." From ad9575ce18ddd7c5262c9af7540e7bcc8e9893d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 3 Apr 2017 16:28:18 +0200 Subject: [PATCH 156/165] Recognize more host names --- advanced/index.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/advanced/index.php b/advanced/index.php index 830ff4f507..0ff847353f 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -19,8 +19,19 @@ function validIP($address){ // Define which URL extensions get rendered as "Website Blocked" $webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml'); +$AUTHORIZED_HOSTNAMES = array( + $ipv4, + $ipv6, + str_replace(array("[","]"), array("",""), $_SERVER["SERVER_NAME"]), + "pi.hole", + "localhost"); +// Allow user set virtual hostnames +$virtual_host = getenv('VIRTUAL_HOST'); +if (! empty($virtual_host)) + array_push($AUTHORIZED_HOSTNAMES, $virtual_host); + // Immediately quit since we didn't block this page (the IP address or pi.hole is explicitly requested) -if(validIP($serverName) || $serverName === "pi.hole") +if(validIP($serverName) || in_array($serverName,$AUTHORIZED_HOSTNAMES)) { http_response_code(404); die(); From 7e0aa822b6df4d464b8d270381be62270806aaaf Mon Sep 17 00:00:00 2001 From: Flo Date: Mon, 3 Apr 2017 17:29:57 +0200 Subject: [PATCH 157/165] Match the Pi-hole brand (#1358) * Update README.md * Update index.php * Update basic-install.sh * Update piholeCheckout.sh * Update update.sh * Update CONTRIBUTING.md * Update the Pi-hole brand tip in CONTRIBUTING.md Use a better formulation. * Update README.md 2 --- CONTRIBUTING.md | 1 + README.md | 2 +- advanced/Scripts/piholeCheckout.sh | 2 +- advanced/Scripts/update.sh | 2 +- advanced/index.php | 4 ++-- automated install/basic-install.sh | 10 +++++----- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d342a8b52b..8cb7ccb903 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -35,4 +35,5 @@ When requesting or submitting new features, first consider whether it might be u - Before Submitting your Pull Request, merge `development` with your new branch and fix any conflicts. (Make sure you don't break anything in development!) - Please use the [Google Style Guide for Shell](https://google.github.io/styleguide/shell.xml) for your code submission styles. - Commit Unix line endings. +- Please use the Pi-hole brand: **Pi-hole** (Take a special look at the capitalized 'P' and a low 'h' with a hyphen) - (Optional fun) keep to the theme of Star Trek/black holes/gravity. diff --git a/README.md b/README.md index 3369d7e22d..c0d6cb8462 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ You can view [real-time stats](https://discourse.pi-hole.net/t/how-do-i-view-my- - [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) - [Windows Tray Stat Application](https://github.com/goldbattle/copernicus) - [Let your blink1 device blink when Pi-hole filters ads](https://gist.github.com/elpatron68/ec0b4c582e5abf604885ac1e068d233f) -- [Pi-Hole Prometheus exporter](https://github.com/nlamirault/pihole_exporter) : a [Prometheus](https://prometheus.io/) exporter for Pi-Hole +- [Pi-hole Prometheus exporter](https://github.com/nlamirault/pihole_exporter): a [Prometheus](https://prometheus.io/) exporter for Pi-hole - [Pi-hole Droid - open source Android client](https://github.com/friimaind/pi-hole-droid) ## Coverage diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 3b7abbef0f..09f20d6b78 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -104,7 +104,7 @@ checkout() #This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then - echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Critical Error: Core Pi-hole repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 115e2d8cf5..4fceb931ed 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -94,7 +94,7 @@ main() { #This is unlikely if ! is_repo "${PI_HOLE_FILES_DIR}" ; then - echo "::: Critical Error: Core Pi-Hole repo is missing from system!" + echo "::: Critical Error: Core Pi-hole repo is missing from system!" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" exit 1; fi diff --git a/advanced/index.php b/advanced/index.php index 0ff847353f..eb44ad4485 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -1,5 +1,5 @@ Date: Mon, 3 Apr 2017 15:15:44 -0400 Subject: [PATCH 158/165] remove vagrant from gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index e7ebe0b6c0..91014dcdcb 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,3 @@ __pycache__ .cache .pullapprove.yml -Vagrantfile -.vagrant/ From a832dd7f672340c96e1dfe6a9bad28e8f571b026 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 6 Apr 2017 14:55:21 -0700 Subject: [PATCH 159/165] Update .editorconfig Set path for JS source. --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index 325648fc3a..e5626a07f4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -28,7 +28,7 @@ indent_size = 4 indent_style = tab # Indentation override for all JS under lib directory -[lib/**.js] +[scripts/**.js] indent_style = space indent_size = 2 From 3eacfa9831507a7fa04ee06ca404b77ba7546328 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 12 Apr 2017 23:13:18 +0200 Subject: [PATCH 160/165] Improve FTL's service script --- advanced/pihole-FTL.service | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index da04738bda..a2cbbab1fa 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -17,7 +17,7 @@ get_pid() { } is_running() { - [ -f "$PIDFILE" ] && ps $(get_pid) > /dev/null 2>&1 + [ -f "$PIDFILE" ] && ps "$(get_pid)" > /dev/null 2>&1 } # Start the service @@ -36,8 +36,8 @@ start() { # Stop the service stop() { if is_running; then - kill $(get_pid) - for i in {1..10}; do + kill "$(get_pid)" + for i in {1..5}; do if ! is_running; then break fi @@ -48,7 +48,8 @@ stop() { echo if is_running; then - echo "Not stopped; may still be shutting down or shutdown may have failed" + echo "Not stopped; may still be shutting down or shutdown may have failed, killing now" + kill -9 "$(get_pid)" exit 1 else echo "Stopped" @@ -61,16 +62,13 @@ stop() { ### main logic ### case "$1" in - start) - start - ;; stop) stop ;; status) status pihole-FTL ;; - restart|reload|condrestart) + start|restart|reload|condrestart) stop start ;; From fcd92d27f706cf2a0fd2049e75960fa1c6deb116 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 12 Apr 2017 19:34:13 +0200 Subject: [PATCH 161/165] Don't use PID file but rather "pidof pihole-FTL" for detecting if another process is already running --- advanced/pihole-FTL.service | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/pihole-FTL.service b/advanced/pihole-FTL.service index a2cbbab1fa..30cd140fbf 100644 --- a/advanced/pihole-FTL.service +++ b/advanced/pihole-FTL.service @@ -13,11 +13,11 @@ FTLUSER=pihole PIDFILE=/var/run/pihole-FTL.pid get_pid() { - cat "$PIDFILE" + pidof "pihole-FTL" } is_running() { - [ -f "$PIDFILE" ] && ps "$(get_pid)" > /dev/null 2>&1 + ps "$(get_pid)" > /dev/null 2>&1 } # Start the service From 519cb7102234531f1ef17dc63a964138f93d3e7f Mon Sep 17 00:00:00 2001 From: Technicalpyro Date: Wed, 12 Apr 2017 16:05:21 -0400 Subject: [PATCH 162/165] Grammar Fix ] --- .github/ISSUE_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index c985b97221..3014625b3e 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -2,7 +2,7 @@ - [] I have read and understood the [contributors guide](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md). - [] The issue I am reporting can be *replicated* -- [] The issue I'm reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)). +- [] The issue I am reporting isn't a duplicate (see [FAQs](https://github.com/pi-hole/pi-hole/wiki/FAQs), [closed issues](https://github.com/pi-hole/pi-hole/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), and [open issues](https://github.com/pi-hole/pi-hole/issues)). **How familiar are you with the codebase?:** From 320c06e0a4d3f75a0452baab81ebf93c39e3880d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 17 Apr 2017 21:25:15 +0200 Subject: [PATCH 163/165] Flush twice to move data out-of-sight of FTL --- advanced/Scripts/piholeLogFlush.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 63754db2b4..fd66b255dc 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -3,18 +3,22 @@ # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. # -# Flushes /var/log/pihole.log +# Flushes Pi-hole's log file # # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. - - echo -n "::: Flushing /var/log/pihole.log ..." # Test if logrotate is available on this system if command -v /usr/sbin/logrotate &> /dev/null; then + # Flush twice to move all data out of sight of FTL + /usr/sbin/logrotate --force /etc/pihole/logrotate /usr/sbin/logrotate --force /etc/pihole/logrotate else + # Flush both pihole.log and pihole.log.1 (if existing) echo " " > /var/log/pihole.log + if [ -f /var/log/pihole.log.1 ]; then + echo " " > /var/log/pihole.log.1 + fi fi echo "... done!" From 5e308dbd51051177708c1557bfb132f7f5905f8c Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Tue, 18 Apr 2017 20:35:06 -0400 Subject: [PATCH 164/165] Delete the temp files created by gravity --- gravity.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 0dc1e678c9..0dccd77b8c 100755 --- a/gravity.sh +++ b/gravity.sh @@ -167,7 +167,11 @@ gravity_transport() { # Process result gravity_patternCheck "${patternBuffer}" ${success} "${err}" - + + # Delete temp file if it hasn't been moved + if [[ -f "${patternBuffer}" ]]; then + rm "${patternBuffer}" + fi } # spinup - main gravity function From f1f70133dc8e61753ffa3515d5afb50a5ea08d93 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 20 Apr 2017 13:52:54 +0200 Subject: [PATCH 165/165] Populate $ipv4 and $ipv6 + fix small error that prevented blocking page from coming up at all. Fixes #1396 --- advanced/index.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index eb44ad4485..30bd131c78 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -19,15 +19,20 @@ function validIP($address){ // Define which URL extensions get rendered as "Website Blocked" $webExt = array('asp', 'htm', 'html', 'php', 'rss', 'xml'); +// Get IPv4 and IPv6 addresses from setupVars.conf (if available) +$setupVars = parse_ini_file("/etc/pihole/setupVars.conf"); +$ipv4 = isset($setupVars["IPV4_ADDRESS"]) ? explode("/", $setupVars["IPV4_ADDRESS"])[0] : $_SERVER['SERVER_ADDR']; +$ipv6 = isset($setupVars["IPV6_ADDRESS"]) ? explode("/", $setupVars["IPV6_ADDRESS"])[0] : $_SERVER['SERVER_ADDR']; + $AUTHORIZED_HOSTNAMES = array( $ipv4, $ipv6, - str_replace(array("[","]"), array("",""), $_SERVER["SERVER_NAME"]), + str_replace(array("[","]"), array("",""), $_SERVER["SERVER_ADDR"]), "pi.hole", "localhost"); // Allow user set virtual hostnames $virtual_host = getenv('VIRTUAL_HOST'); -if (! empty($virtual_host)) +if (!empty($virtual_host)) array_push($AUTHORIZED_HOSTNAMES, $virtual_host); // Immediately quit since we didn't block this page (the IP address or pi.hole is explicitly requested)