From 1f0eb734d9548c8dc6be221c7b8b49ddfd92b8d9 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 27 Feb 2023 23:01:16 -0300 Subject: [PATCH] Change FTLcheckUpdate logic - execute `curl` in a separate step - use api.github.com and `jq` to retrieve tag_name - check if current FTL version is less than latest - show error message if return is empty (curl failed) Signed-off-by: RD WebDesign --- automated install/basic-install.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ccb5eac7..4256fec5 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2442,15 +2442,23 @@ FTLcheckUpdate() { if [[ ${ftlLoc} ]]; then local FTLversion FTLversion=$(/usr/bin/pihole-FTL tag) + local FTLlatesttag + FTLlatesttag=$(curl -s https://api.github.com/repos/pi-hole/FTL/releases/latest | jq -sRr 'fromjson? | .tag_name | values') - if ! FTLlatesttag=$(curl -sI https://github.com/pi-hole/FTL/releases/latest | grep --color=never -i Location: | awk -F / '{print $NF}' | tr -d '[:cntrl:]'); then + if [ -z "${FTLlatesttag}" ]; then # There was an issue while retrieving the latest version printf " %b Failed to retrieve latest FTL release metadata" "${CROSS}" return 3 fi - if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then + # Convert version strings into numbers for comparison + local convertedFTLversion convertedFTLlatesttag + convertedFTLversion="$(VersionConverter "${FTLversion}")" + convertedFTLlatesttag="$(VersionConverter "${FTLlatesttag}")" + + if [[ "${convertedFTLversion}" -lt "${convertedFTLlatesttag}" ]]; then + # FTL is out of date return 0 else printf " %b Latest FTL Binary already installed (%s). Confirming Checksum...\\n" "${INFO}" "${FTLlatesttag}" @@ -2502,6 +2510,12 @@ copy_to_install_log() { chmod 644 "${installLogLoc}" } +# converts a given version string e.g. v3.7.1 to 3007001000 to allow for easier comparison of multi digit version numbers +# credits https://apple.stackexchange.com/a/123408 +VersionConverter() { + echo "$@" | tr -d '[:alpha:]' | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; +} + main() { ######## FIRST CHECK ######## # Must be root to install