From 72d8d10e647599723ec21ccf827d3b0c098e3fad Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 16 Jan 2017 22:39:58 +0100 Subject: [PATCH 01/51] 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 93b0cbb1..92842afa 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 02/51] 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 92842afa..c52ae489 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 03/51] 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 c70dd393..5ce4898d 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 04/51] 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 5ce4898d..936c845b 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 05/51] 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 936c845b..37fe469d 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 06/51] Proper error handling --- automated install/basic-install.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 37fe469d..64a190e2 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 0 + 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 07/51] 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 64a190e2..d7e14420 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 08/51] 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 d7e14420..da69421e 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 09/51] 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 da69421e..23aeb4c3 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 10/51] 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 23aeb4c3..467a58c5 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 11/51] 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 467a58c5..b549e930 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 12/51] 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 b549e930..ae8b48f6 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 13/51] 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 ae8b48f6..4e69ef19 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 14/51] 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 4e69ef19..5de68734 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 15/51] 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 5de68734..5cc086c5 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 16/51] 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 89d9a0e0..5096e2b2 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 17/51] 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 5096e2b2..76fbe7ef 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 18/51] 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 76fbe7ef..4e84c147 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 19/51] 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 5096e2b2..449a1f31 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 - touch /lib/ld-linux-armhf.so.3 - ls -lach /lib/ ''') - expected_stdout = 'Detected ARM-hf architecture' + 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 + ''') + 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 20/51] 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 5cc086c5..dc302f48 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 97c8e503..a4488239 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 21/51] 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 f9d10062..00000000 --- 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 dc302f48..aead0583 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 "${binary}" || return 1 -FTLinstall() { - # Install FTL binary - echo ":::" - echo -n "::: Installing FTL ... " - - 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 a4488239..b0dded5c 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 22/51] 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 aead0583..98322cb7 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 931c0ba7..66436f1a 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 23/51] 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 98322cb7..7499336b 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 b0dded5c..40e0000b 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 24/51] 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 7499336b..bdc1cf25 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 25/51] 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 bdc1cf25..059f8f10 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 26/51] 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 059f8f10..4fefbc0f 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 27/51] 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 4fefbc0f..04febe57 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 28/51] Fix IDEA ignoring pullapprove. Signed-off-by: Dan Schaper --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index c4b497a0..d7bdfd37 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 29/51] Revert reversion. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d7bdfd37..91014dcd 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 30/51] 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 00000000..c02b5486 --- /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 31/51] 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 04febe57..129f88fd 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 32/51] 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 04febe57..f3249f9f 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 33/51] 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 f3249f9f..3ffdba2a 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 34/51] `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 3ffdba2a..5a0aae73 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 35/51] 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 5a0aae73..11ffbec2 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 36/51] 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 40e0000b..250accf7 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 37/51] 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 11ffbec2..715d6e95 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 250accf7..1fb1a20a 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 38/51] 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 1fb1a20a..b42262de 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 39/51] 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 00000000..1fcd9b01 --- /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 715d6e95..8a135e9b 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 40/51] 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 8a135e9b..fb9842c9 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 41/51] 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 b42262de..ac463d78 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 42/51] 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 1fcd9b01..c161e070 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 43/51] 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 c161e070..caffd00e 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 44/51] 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 caffd00e..6e1a9786 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 45/51] 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 6e1a9786..da04738b 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 46/51] 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 fb9842c9..a8bb014b 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 47/51] 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 74d2f05c..b6b71fb7 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 48/51] `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 a8bb014b..3f8122cd 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 49/51] 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 ac463d78..19c662c6 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 50/51] 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 10847ead..b5a7e1a4 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 3f8122cd..e784ab18 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 51/51] 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 b5a7e1a4..2a384217 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