mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-25 15:43:19 +00:00
Add checking for availability of ftl.pi-hole.net when using FTL from a custom branch. If the server is down (or the user is offline, cannot resolve the domain, etc.), we fail early and hard instead of possibly corrupting the installation
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
9a3affd81e
commit
31a8f150b2
3 changed files with 51 additions and 19 deletions
|
@ -164,7 +164,9 @@ checkout() {
|
|||
path="${2}/${binary}"
|
||||
oldbranch="$(pihole-FTL -b)"
|
||||
|
||||
if check_download_exists "$path"; then
|
||||
check_download_exists "$path"
|
||||
local ret=$?
|
||||
if [ $ret -eq 0 ]; then
|
||||
echo " ${TICK} Branch ${2} exists"
|
||||
echo "${2}" > /etc/pihole/ftlbranch
|
||||
chmod 644 /etc/pihole/ftlbranch
|
||||
|
@ -175,11 +177,19 @@ checkout() {
|
|||
# Update local and remote versions via updatechecker
|
||||
/opt/pihole/updatecheck.sh
|
||||
else
|
||||
if [[ $ret -eq 1 ]]; then
|
||||
echo " ${CROSS} Requested branch \"${2}\" is not available"
|
||||
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') )
|
||||
echo -e " ${INFO} Available branches for FTL are:"
|
||||
for e in "${ftlbranches[@]}"; do echo " - $e"; done
|
||||
exit 1
|
||||
elif [[ $ret -eq 2 ]]; then
|
||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||
exit 1
|
||||
else
|
||||
printf " %b Unknown error. Please contact Pi-hole Support\\n" "${CROSS}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
else
|
||||
|
|
|
@ -144,7 +144,7 @@ main() {
|
|||
local binary
|
||||
binary="pihole-FTL${funcOutput##*pihole-FTL}" #binary name will be the last line of the output of get_binary_name (it always begins with pihole-FTL)
|
||||
|
||||
if FTLcheckUpdate "${binary}" > /dev/null; then
|
||||
if FTLcheckUpdate "${binary}"; then
|
||||
FTL_update=true
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_YELLOW}update available${COL_NC}"
|
||||
else
|
||||
|
@ -155,8 +155,13 @@ main() {
|
|||
2)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_RED}Branch is not available.${COL_NC}\\n\\t\\t\\tUse ${COL_LIGHT_GREEN}pihole checkout ftl [branchname]${COL_NC} to switch to a valid branch."
|
||||
;;
|
||||
3)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_RED}Something has gone wrong, cannot reach download server${COL_NC}"
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
echo -e " ${INFO} FTL:\\t\\t${COL_LIGHT_RED}Something has gone wrong, contact support${COL_NC}"
|
||||
exit 1
|
||||
esac
|
||||
FTL_update=false
|
||||
fi
|
||||
|
|
|
@ -1687,12 +1687,19 @@ update_dialogs() {
|
|||
}
|
||||
|
||||
check_download_exists() {
|
||||
# Check if the download exists and we can reach the server
|
||||
status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
||||
if grep -q "404" <<< "$status"; then
|
||||
return 1
|
||||
else
|
||||
|
||||
# Check the status code
|
||||
if grep -q "200" <<< "$status"; then
|
||||
return 0
|
||||
elif grep -q "404" <<< "$status"; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Other error or no status code at all, e.g., no Internet, server not
|
||||
# available/reachable, ...
|
||||
return 2
|
||||
}
|
||||
|
||||
fully_fetch_repo() {
|
||||
|
@ -1959,8 +1966,6 @@ get_binary_name() {
|
|||
FTLcheckUpdate() {
|
||||
# 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
|
||||
printf " %b Checking for existing FTL binary...\\n" "${INFO}"
|
||||
|
||||
local ftlLoc
|
||||
ftlLoc=$(command -v pihole-FTL 2>/dev/null)
|
||||
|
||||
|
@ -1983,10 +1988,20 @@ FTLcheckUpdate() {
|
|||
local path
|
||||
path="${ftlBranch}/${binary}"
|
||||
# shellcheck disable=SC1090
|
||||
if ! check_download_exists "$path"; then
|
||||
check_download_exists "$path"
|
||||
local ret=$?
|
||||
if [ $ret -ne 0 ]; then
|
||||
if [[ $ret -eq 1 ]]; then
|
||||
printf " %b Branch \"%s\" is not available.\\n" "${INFO}" "${ftlBranch}"
|
||||
printf " %b Use %bpihole checkout ftl [branchname]%b to switch to a valid branch.\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
return 2
|
||||
elif [[ $ret -eq 2 ]]; then
|
||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||
return 3
|
||||
else
|
||||
printf " %b Unknown error. Please contact Pi-hole Support\\n" "${CROSS}"
|
||||
return 4
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ${ftlLoc} ]]; then
|
||||
|
@ -2011,12 +2026,14 @@ FTLcheckUpdate() {
|
|||
FTLversion=$(/usr/bin/pihole-FTL tag)
|
||||
local FTLlatesttag
|
||||
|
||||
# Get the latest version from the GitHub API
|
||||
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
|
||||
# There was an issue while retrieving the latest version
|
||||
printf " %b Failed to retrieve latest FTL release metadata" "${CROSS}"
|
||||
return 3
|
||||
fi
|
||||
|
||||
# Check if the installed version matches the latest version
|
||||
if [[ "${FTLversion}" != "${FTLlatesttag}" ]]; then
|
||||
return 0
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue