From 74b912a0b71c1fd2027f4cc0c194fdf636d07dbb Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 12 Jul 2017 22:02:07 +0100 Subject: [PATCH 1/4] Check if FTL is already installed, do not download if it is detected, and the sha1sum matches the remote This will probably break some tests. I'll work that out in a bit Signed-off-by: Adam Warner Signed-off-by: Adam Warner --- automated install/basic-install.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 74e2a61d..8c026442 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1761,7 +1761,7 @@ FTLinstall() { local binary="${1}" local latesttag local orig_dir - local str="Installing FTL" + local str="Downloading and Installing FTL" echo -ne " ${INFO} ${str}..." # Get the current working directory @@ -1774,6 +1774,7 @@ FTLinstall() { echo -e " ${COL_LIGHT_RED}Error: Unable to get latest release location from GitHub${COL_NC}" return 1 fi + # If the download worked, 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. @@ -1879,9 +1880,26 @@ FTLdetect() { binary="pihole-FTL-linux-x86_32" fi - # Install FTL - FTLinstall "${binary}" || return 1 - + #In the next section we check to see if FTL is already installed (in case of pihole -r). + #If the installed version matches the latest version, then check the installed sha1sum of the binary vs the remote sha1sum. If they do not match, then download + 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 + # Install FTL + FTLinstall "${binary}" || return 1 + else + local remoteSha1=$(curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1" | cut -d ' ' -f 1) + local localSha1=$(sha1sum "$(which pihole-FTL)" | cut -d ' ' -f 1) + + echo -e " ${INFO} Existing FTL Binary detected. Checking sha1sum..." + if [[ "${remoteSha1}" != "${localSha1}" ]]; then + echo -e " ${INFO} Corruption detected..." + FTLinstall "${binary}" || return 1 + else + echo -e " ${INFO} sha1sums match. No need to download!" + fi + fi } main() { From bf70c2c6605e15caf433bf5830a7e6a474b22f3a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Wed, 12 Jul 2017 22:52:03 +0100 Subject: [PATCH 2/4] initial changes to tests to take into account changes to strings Signed-off-by: Adam Warner --- automated install/basic-install.sh | 2 +- test/test_automated_install.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8c026442..3a53fca5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1817,7 +1817,7 @@ FTLinstall() { # Detect suitable FTL binary platform FTLdetect() { echo "" - echo -e " ${INFO} Downloading latest version of FTL..." + echo -e " ${INFO} FTL Checks..." # Local, named variables local machine diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 60b9dbb8..4a4f72aa 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -319,11 +319,11 @@ def test_FTL_detect_aarch64_no_errors(Pihole): source /opt/pihole/basic-install.sh FTLdetect ''') - expected_stdout = info_box + ' Downloading latest version of FTL...' + expected_stdout = info_box + ' FTL Checks...' assert expected_stdout in detectPlatform.stdout expected_stdout = tick_box + ' Detected ARM-aarch64 architecture' assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Installing FTL' + expected_stdout = tick_box + ' Downloading and Installing FTL' assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv6l_no_errors(Pihole): @@ -336,11 +336,11 @@ def test_FTL_detect_armv6l_no_errors(Pihole): source /opt/pihole/basic-install.sh FTLdetect ''') - expected_stdout = info_box + ' Downloading latest version of FTL...' + expected_stdout = info_box + ' FTL Checks...' assert expected_stdout in detectPlatform.stdout expected_stdout = tick_box + ' Detected ARM-hf architecture (armv6 or lower)' assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Installing FTL' + expected_stdout = tick_box + ' Downloading and Installing FTL' assert expected_stdout in detectPlatform.stdout def test_FTL_detect_armv7l_no_errors(Pihole): @@ -353,11 +353,11 @@ def test_FTL_detect_armv7l_no_errors(Pihole): source /opt/pihole/basic-install.sh FTLdetect ''') - expected_stdout = info_box + ' Downloading latest version of FTL...' + expected_stdout = info_box + ' FTL Checks...' assert expected_stdout in detectPlatform.stdout expected_stdout = tick_box + ' Detected ARM-hf architecture (armv7+)' assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Installing FTL' + expected_stdout = tick_box + ' Downloading and Installing FTL' assert expected_stdout in detectPlatform.stdout def test_FTL_detect_x86_64_no_errors(Pihole): @@ -366,11 +366,11 @@ def test_FTL_detect_x86_64_no_errors(Pihole): source /opt/pihole/basic-install.sh FTLdetect ''') - expected_stdout = info_box + ' Downloading latest version of FTL...' + expected_stdout = info_box + ' FTL Checks...' assert expected_stdout in detectPlatform.stdout expected_stdout = tick_box + ' Detected x86_64 architecture' assert expected_stdout in detectPlatform.stdout - expected_stdout = tick_box + ' Installing FTL' + expected_stdout = tick_box + ' Downloading and Installing FTL' assert expected_stdout in detectPlatform.stdout def test_FTL_detect_unknown_no_errors(Pihole): @@ -391,7 +391,7 @@ def test_FTL_download_aarch64_no_errors(Pihole): source /opt/pihole/basic-install.sh FTLinstall pihole-FTL-aarch64-linux-gnu ''') - expected_stdout = tick_box + ' Installing FTL' + expected_stdout = tick_box + ' Downloading and Installing FTL' assert expected_stdout in download_binary.stdout error = 'Error: Download of binary from Github failed' assert error not in download_binary.stdout @@ -405,7 +405,7 @@ def test_FTL_download_unknown_fails_no_errors(Pihole): source /opt/pihole/basic-install.sh FTLinstall pihole-FTL-mips ''') - expected_stdout = cross_box + ' Installing FTL' + expected_stdout = cross_box + ' Downloading and Installing FTL' assert expected_stdout in download_binary.stdout error = 'Error: URL not found' assert error in download_binary.stdout From 1c93868ae1b1bc673f26ae4c5a9d235897ca99aa Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 24 Jul 2017 23:22:04 +0100 Subject: [PATCH 3/4] Adjust wording of echos Signed-off-by: Adam Warner --- automated install/basic-install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3a53fca5..f0d6018f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1882,6 +1882,7 @@ FTLdetect() { #In the next section we check to see if FTL is already installed (in case of pihole -r). #If the installed version matches the latest version, then check the installed sha1sum of the binary vs the remote sha1sum. If they do not match, then download + echo -e " ${INFO} Checking for existing FTL binary..." 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') @@ -1889,15 +1890,16 @@ FTLdetect() { # Install FTL FTLinstall "${binary}" || return 1 else + echo -e " ${INFO} Latest FTL Binary already installed (${FTLlatesttag}). Confirming Checksum..." + local remoteSha1=$(curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1" | cut -d ' ' -f 1) local localSha1=$(sha1sum "$(which pihole-FTL)" | cut -d ' ' -f 1) - echo -e " ${INFO} Existing FTL Binary detected. Checking sha1sum..." if [[ "${remoteSha1}" != "${localSha1}" ]]; then echo -e " ${INFO} Corruption detected..." FTLinstall "${binary}" || return 1 else - echo -e " ${INFO} sha1sums match. No need to download!" + echo -e " ${INFO} Checksum correct. No need to download!" fi fi } From a293b5a3718f3381f9f9fd2cc955127d062e1a99 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 25 Jul 2017 22:49:06 +0100 Subject: [PATCH 4/4] prevent `./automated install/basic-install.sh: line 1886: /usr/bin/pihole-FTL: No such file or directory` on new install, or if pihole-FTL is missing for whatever reason. Signed-off-by: Adam Warner --- automated install/basic-install.sh | 38 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f0d6018f..170754f2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1883,25 +1883,35 @@ FTLdetect() { #In the next section we check to see if FTL is already installed (in case of pihole -r). #If the installed version matches the latest version, then check the installed sha1sum of the binary vs the remote sha1sum. If they do not match, then download echo -e " ${INFO} Checking for existing FTL binary..." - 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 - # Install FTL - FTLinstall "${binary}" || return 1 - else - echo -e " ${INFO} Latest FTL Binary already installed (${FTLlatesttag}). Confirming Checksum..." + local ftlLoc=$(which pihole-FTL) - local remoteSha1=$(curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1" | cut -d ' ' -f 1) - local localSha1=$(sha1sum "$(which pihole-FTL)" | cut -d ' ' -f 1) + if [[ ${ftlLoc} ]]; then + 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 [[ "${remoteSha1}" != "${localSha1}" ]]; then - echo -e " ${INFO} Corruption detected..." - FTLinstall "${binary}" || return 1 + if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then + # Install FTL + FTLinstall "${binary}" || return 1 else - echo -e " ${INFO} Checksum correct. No need to download!" + echo -e " ${INFO} Latest FTL Binary already installed (${FTLlatesttag}). Confirming Checksum..." + + local remoteSha1=$(curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1" | cut -d ' ' -f 1) + local localSha1=$(sha1sum "$(which pihole-FTL)" | cut -d ' ' -f 1) + + if [[ "${remoteSha1}" != "${localSha1}" ]]; then + echo -e " ${INFO} Corruption detected..." + FTLinstall "${binary}" || return 1 + else + echo -e " ${INFO} Checksum correct. No need to download!" + fi fi - fi + else + # Install FTL + FTLinstall "${binary}" || return 1 + fi + + } main() {