Reduce code-duplication

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2024-03-10 21:18:13 +01:00
parent 2fd0de4743
commit 82a83c497d
No known key found for this signature in database
GPG key ID: 00135ACBD90B28DD

View file

@ -2030,21 +2030,9 @@ FTLcheckUpdate() {
# Alt branches don't have a tagged version against them, so just # Alt branches don't have a tagged version against them, so just
# confirm the checksum of the local vs remote to decide whether we # confirm the checksum of the local vs remote to decide whether we
# download or not # download or not
remoteSha1=$(curl -sSL --fail "https://ftl.pi-hole.net/${ftlBranch}/${binary}.sha1" | cut -d ' ' -f 1) printf " %b FTL binary already installed. Confirming Checksum...\\n" "${INFO}"
localSha1=$(sha1sum "${ftlLoc}" | cut -d ' ' -f 1) checkSumFile="https://ftl.pi-hole.net/${ftlBranch}/${binary}.sha1"
# Continue further down...
# Check we downloaded a valid checksum (no 404 or other error like
# no DNS resolution)
if [[ ! "${remoteSha1}" =~ ^[a-f0-9]{40}$ ]]; then
printf " %b Remote checksum not available, trying to download binary from ftl.pi-hole.net.\\n" "${CROSS}"
return 0
elif [[ "${remoteSha1}" != "${localSha1}" ]]; then
printf " %b Checksums do not match, downloading from ftl.pi-hole.net.\\n" "${INFO}"
return 0
else
printf " %b Checksum of installed binary matches remote. No need to download!\\n" "${INFO}"
return 1
fi
else else
return 0 return 0
fi fi
@ -2066,34 +2054,39 @@ FTLcheckUpdate() {
# Check if the installed version matches the latest version # Check if the installed version matches the latest version
if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then
# If the installed version does not match the latest version, then download # If the installed version does not match the latest version,
# then download
return 0 return 0
else else
# If the installed version matches the latest version, then # If the installed version matches the latest version, then
# check the installed sha1sum of the binary vs the remote # check the installed sha1sum of the binary vs the remote
# sha1sum. If they do not match, then download # sha1sum. If they do not match, then download
printf " %b Latest FTL Binary already installed (%s). Confirming Checksum...\\n" "${INFO}" "${FTLlatesttag}" printf " %b Latest FTL binary already installed (%s). Confirming Checksum...\\n" "${INFO}" "${FTLlatesttag}"
checkSumFile="https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1"
remoteSha1=$(curl -sSL --fail "https://github.com/pi-hole/FTL/releases/download/${FTLversion%$'\r'}/${binary}.sha1" | cut -d ' ' -f 1) # Continue further down...
localSha1=$(sha1sum "${ftlLoc}" | cut -d ' ' -f 1)
# Check we downloaded a valid checksum (no 404 or other error like
# no DNS resolution)
if [[ ! "${remoteSha1}" =~ ^[a-f0-9]{40}$ ]]; then
printf " %b Remote checksum not available, trying to redownload binary...\\n" "${CROSS}"
return 0
elif [[ "${remoteSha1}" != "${localSha1}" ]]; then
printf " %b Corruption detected, redownloading binary...\\n" "${CROSS}"
return 0
else
printf " %b Checksum correct. No need to download!\\n" "${INFO}"
return 1
fi
fi fi
else else
return 0 return 0
fi fi
fi fi
# If we reach this point, we need to check the checksum of the local vs
# remote to decide whether we download or not
remoteSha1=$(curl -sSL --fail "${checkSumFile}" | cut -d ' ' -f 1)
localSha1=$(sha1sum "${ftlLoc}" | cut -d ' ' -f 1)
# Check we downloaded a valid checksum (no 404 or other error like
# no DNS resolution)
if [[ ! "${remoteSha1}" =~ ^[a-f0-9]{40}$ ]]; then
printf " %b Remote checksum not available, trying to redownload binary...\\n" "${CROSS}"
return 0
elif [[ "${remoteSha1}" != "${localSha1}" ]]; then
printf " %b Corruption detected, redownloading binary...\\n" "${CROSS}"
return 0
fi
printf " %b Checksum correct. No need to download!\\n" "${INFO}"
return 1
} }
# Detect suitable FTL binary platform # Detect suitable FTL binary platform