Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds _check_internet() to install loader #1740

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion installers/raspbian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -271,6 +273,39 @@ function _install_status() {
esac
}

function _check_internet() {
component="Install"
_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"
Expand Down
Loading