mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-22 14:13:42 +00:00
FTL checkout: Check for availability of branches before trying to download from the webserver. Also, fix check_download_exists() possibly killing the script on non-availability of requested branches
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
a302d7b5d7
commit
9e9c985245
3 changed files with 39 additions and 23 deletions
|
@ -161,34 +161,52 @@ checkout() {
|
||||||
elif [[ "${1}" == "ftl" ]] ; then
|
elif [[ "${1}" == "ftl" ]] ; then
|
||||||
local path
|
local path
|
||||||
local oldbranch
|
local oldbranch
|
||||||
|
local existing=false
|
||||||
path="${2}/${binary}"
|
path="${2}/${binary}"
|
||||||
oldbranch="$(pihole-FTL -b)"
|
oldbranch="$(pihole-FTL -b)"
|
||||||
|
|
||||||
echo -e " ${INFO} Checking for branch ${COL_CYAN}${2}${COL_NC} on https://ftl.pi-hole.net"
|
# Check if requested branch is available
|
||||||
check_download_exists "$path"
|
echo -e " ${INFO} Checking for availability of branch ${COL_CYAN}${2}${COL_NC} on GitHub"
|
||||||
local ret=$?
|
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep "refs/heads" | cut -d'/' -f3- -) )
|
||||||
if [ $ret -eq 0 ]; then
|
# If returned array is empty -> connectivity issue
|
||||||
echo " ${TICK} Branch ${2} exists"
|
if [[ ${#ftlbranches[@]} -eq 0 ]]; then
|
||||||
|
echo -e " ${CROSS} Unable to fetch branches from GitHub. Please check your Internet connection and try again later."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for e in "${ftlbranches[@]}"; do [[ "$e" == "${2}" ]] && existing=true; done
|
||||||
|
if [[ "${existing}" == false ]]; then
|
||||||
|
echo -e " ${CROSS} Requested branch is not available\n"
|
||||||
|
echo -e " ${INFO} Available branches are:"
|
||||||
|
for e in "${ftlbranches[@]}"; do echo " - $e"; done
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo -e " ${TICK} Branch ${2} exists on GitHub"
|
||||||
|
|
||||||
|
echo -e " ${INFO} Checking for ${COL_YELLOW}${binary}${COL_NC} binary on https://ftl.pi-hole.net"
|
||||||
|
|
||||||
|
if check_download_exists "$path"; then
|
||||||
|
echo " ${TICK} Binary exists"
|
||||||
echo "${2}" > /etc/pihole/ftlbranch
|
echo "${2}" > /etc/pihole/ftlbranch
|
||||||
chmod 644 /etc/pihole/ftlbranch
|
chmod 644 /etc/pihole/ftlbranch
|
||||||
echo -e " ${INFO} Switching to branch: \"${2}\" from \"${oldbranch}\""
|
echo -e " ${INFO} Switching to branch: ${COL_CYAN}${2}${COL_NC} from ${COL_CYAN}${oldbranch}${COL_NC}"
|
||||||
FTLinstall "${binary}"
|
FTLinstall "${binary}"
|
||||||
restart_service pihole-FTL
|
restart_service pihole-FTL
|
||||||
enable_service pihole-FTL
|
enable_service pihole-FTL
|
||||||
# Update local and remote versions via updatechecker
|
# Update local and remote versions via updatechecker
|
||||||
/opt/pihole/updatecheck.sh
|
/opt/pihole/updatecheck.sh
|
||||||
else
|
else
|
||||||
if [[ $ret -eq 1 ]]; then
|
if [ $? -eq 1 ]; then
|
||||||
echo " ${CROSS} Requested branch \"${2}\" is not available"
|
# Binary for requested branch is not available, may still be
|
||||||
ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') )
|
# int he process of being built or CI build job failed
|
||||||
echo -e " ${INFO} Available branches for FTL are:"
|
printf " %b Binary for requested branch is not available, please try again later.\\n" ${CROSS}
|
||||||
for e in "${ftlbranches[@]}"; do echo " - $e"; done
|
printf " If the issue persists, please contact Pi-hole Support and ask them to re-generate the binary.\\n"
|
||||||
exit 1
|
exit 1
|
||||||
elif [[ $ret -eq 2 ]]; then
|
elif [ $? -eq 2 ]; then
|
||||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
printf " %b Unknown error. Please contact Pi-hole Support\\n" "${CROSS}"
|
printf " %b Unknown checkout error. Please contact Pi-hole Support\\n" "${CROSS}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -16,10 +16,9 @@
|
||||||
#
|
#
|
||||||
# curl -sSL https://install.pi-hole.net | bash
|
# curl -sSL https://install.pi-hole.net | bash
|
||||||
|
|
||||||
# -e option instructs bash to immediately exit if any command [1] has a non-zero
|
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
|
||||||
# exit status We do not want users to end up with a partially working install,
|
# We do not want users to end up with a partially working install, so we exit the script
|
||||||
# so we exit the script instead of continuing the installation with something
|
# instead of continuing the installation with something broken
|
||||||
# broken
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Append common folders to the PATH to ensure that all basic commands are available.
|
# Append common folders to the PATH to ensure that all basic commands are available.
|
||||||
|
@ -1694,7 +1693,7 @@ update_dialogs() {
|
||||||
|
|
||||||
check_download_exists() {
|
check_download_exists() {
|
||||||
# Check if the download exists and we can reach the server
|
# Check if the download exists and we can reach the server
|
||||||
status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
local status=$(curl --head --silent "https://ftl.pi-hole.net/${1}" | head -n 1)
|
||||||
|
|
||||||
# Check the status code
|
# Check the status code
|
||||||
if grep -q "200" <<<"$status"; then
|
if grep -q "200" <<<"$status"; then
|
||||||
|
@ -2012,14 +2011,12 @@ FTLcheckUpdate() {
|
||||||
|
|
||||||
# Check whether or not the binary for this FTL branch actually exists. If not, then there is no update!
|
# Check whether or not the binary for this FTL branch actually exists. If not, then there is no update!
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
check_download_exists "$path"
|
if ! check_download_exists "$path"; then
|
||||||
local ret=$?
|
if [ $? -eq 1 ]; then
|
||||||
if [ $ret -ne 0 ]; then
|
|
||||||
if [[ $ret -eq 1 ]]; then
|
|
||||||
printf " %b Branch \"%s\" is not available.\\n" "${INFO}" "${ftlBranch}"
|
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}"
|
printf " %b Use %bpihole checkout ftl [branchname]%b to switch to a valid branch.\\n" "${INFO}" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||||
return 2
|
return 2
|
||||||
elif [[ $ret -eq 2 ]]; then
|
elif [ $? -eq 2 ]; then
|
||||||
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
printf " %b Unable to download from ftl.pi-hole.net. Please check your Internet connection and try again later.\\n" "${CROSS}"
|
||||||
return 3
|
return 3
|
||||||
else
|
else
|
||||||
|
|
1
pihole
1
pihole
|
@ -411,6 +411,7 @@ piholeCheckoutFunc() {
|
||||||
echo "Switch Pi-hole subsystems to a different GitHub branch
|
echo "Switch Pi-hole subsystems to a different GitHub branch
|
||||||
Usage: ${COL_GREEN}pihole checkout${COL_NC} ${COL_YELLOW}shortcut${COL_NC}
|
Usage: ${COL_GREEN}pihole checkout${COL_NC} ${COL_YELLOW}shortcut${COL_NC}
|
||||||
or ${COL_GREEN}pihole checkout${COL_NC} ${COL_PURPLE}repo${COL_NC} ${COL_CYAN}branch${COL_NC}
|
or ${COL_GREEN}pihole checkout${COL_NC} ${COL_PURPLE}repo${COL_NC} ${COL_CYAN}branch${COL_NC}
|
||||||
|
|
||||||
Example: ${COL_GREEN}pihole checkout${COL_NC} ${COL_YELLOW}master${COL_NC}
|
Example: ${COL_GREEN}pihole checkout${COL_NC} ${COL_YELLOW}master${COL_NC}
|
||||||
or ${COL_GREEN}pihole checkout${COL_NC} ${COL_PURPLE}ftl ${COL_CYAN}development${COL_NC}
|
or ${COL_GREEN}pihole checkout${COL_NC} ${COL_PURPLE}ftl ${COL_CYAN}development${COL_NC}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue