diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a3c41b11..4330637d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1758,7 +1758,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 @@ -1771,6 +1771,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. @@ -1813,7 +1814,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 @@ -1876,8 +1877,37 @@ 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 + echo -e " ${INFO} Checking for existing FTL binary..." + + local ftlLoc=$(which pihole-FTL) + + 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 [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then + # 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) + + 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 + else + # Install FTL + FTLinstall "${binary}" || return 1 + fi + } 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