From e61dac332c6c578b9c58349c5f5c185844ebcbfe Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 30 Jan 2025 00:08:59 -0800 Subject: [PATCH 1/4] Add _check_internet() function. Resolves #1729 --- installers/raspbian.sh | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index fed89149..47067411 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -81,11 +81,13 @@ EOF set -eo pipefail function _main() { + _setup_colors + _check_internet + # set defaults repo="RaspAP/raspap-webgui" # override with -r, --repo option repo_common="$repo" _parse_params "$@" - _setup_colors _log_output _load_installer } @@ -271,6 +273,38 @@ function _install_status() { esac } +function _check_internet() { + _install_log "Checking internet connectivity..." + + # spinner frames + local spinner='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏' + local i=0 + + tput civis # hide cursor + + # run check in background + ( curl -Is --connect-timeout 3 --max-time 5 https://github.com | head -n 1 | grep "HTTP/2 200" >/dev/null ) & + local pid=$! + + # display spinner while curl runs + while kill -0 $pid 2>/dev/null; do + printf "\r%s" "${spinner:i++%${#spinner}:1}" + sleep 0.05 + done + printf "\r" + + # check exit status of curl + wait $pid || exit_code=$? + + tput cnorm # restore cursor + + if [[ $exit_code -ne 0 ]]; then + _install_status 1 "No internet connection or unable to reach GitHub" + exit 1 + fi + _install_status 0 +} + function _update_system_packages() { _install_log "Updating sources" sudo apt-get update || _install_status 1 "Unable to update package list" From 18114df2bd9b849b05ea2ae2a3c995b3a8cd924a Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 30 Jan 2025 00:39:16 -0800 Subject: [PATCH 2/4] Define component --- installers/raspbian.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 47067411..863c57e7 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -274,6 +274,7 @@ function _install_status() { } function _check_internet() { + component="Install" _install_log "Checking internet connectivity..." # spinner frames From a9804b2f9cbd756cc1502d1b8ab251403860a387 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 2 Feb 2025 03:08:35 -0800 Subject: [PATCH 3/4] Update _get_release() w/ API rate limit and undefined release var check --- installers/raspbian.sh | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 863c57e7..46129966 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -235,11 +235,25 @@ function _display_welcome() { # Fetch latest release from GitHub or RaspAP Installer API function _get_release() { - readonly RASPAP_LATEST=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")' ) + local response + local host="api.github.com" + response=$(curl -s "https://$host/repos/$repo/releases/latest") + + if echo "$response" | grep -q '"API rate limit exceeded"'; then + _install_status 1 "GitHub API rate limit exceeded. Try again later or use a GitHub token." + return 1 + fi + readonly RASPAP_LATEST=$(echo "$response" | grep -Po '"tag_name": "\K.*?(?=")') + + if [ -z "$RASPAP_LATEST" ]; then + _install_status 1 "Failed to fetch latest release. Check network connectivity." + return 1 + fi + if [ "$insiders" == 1 ]; then repo="RaspAP/raspap-insiders" repo_common="RaspAP/raspap-webgui" - readonly RASPAP_INSIDERS_LATEST=$(curl -s "https://api.raspap.com/repos/RaspAP/raspap-insiders/releases/latest/" | grep -Po '"tag_name": "\K.*?(?=")' ) + readonly RASPAP_INSIDERS_LATEST=$(curl -s "https://api.raspap.com/repos/RaspAP/raspap-insiders/releases/latest/" | grep -Po '"tag_name": "\K.*?(?=")') readonly RASPAP_RELEASE="${RASPAP_INSIDERS_LATEST} Insiders" else readonly RASPAP_RELEASE="${RASPAP_LATEST}" @@ -273,6 +287,7 @@ function _install_status() { esac } +# Checks connectivity to github.com function _check_internet() { component="Install" _install_log "Checking internet connectivity..." From 6b7b8ef8d0339db8a87f37ed3a74b1ba9b4d9d43 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 3 Feb 2025 00:20:03 -0800 Subject: [PATCH 4/4] Refine API response condition --- installers/raspbian.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installers/raspbian.sh b/installers/raspbian.sh index 46129966..66145ace 100755 --- a/installers/raspbian.sh +++ b/installers/raspbian.sh @@ -239,7 +239,7 @@ function _get_release() { local host="api.github.com" response=$(curl -s "https://$host/repos/$repo/releases/latest") - if echo "$response" | grep -q '"API rate limit exceeded"'; then + if echo "$response" | grep -q 'API rate limit exceeded'; then _install_status 1 "GitHub API rate limit exceeded. Try again later or use a GitHub token." return 1 fi