Skip to content

Commit

Permalink
Change FTLcheckUpdate logic
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
rdwebdesign committed Mar 1, 2023
1 parent 2dd31ce commit 1f0eb73
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions automated install/basic-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1f0eb73

Please sign in to comment.