From e5840ce1bb766cfb9af045c6f60e7ee391bf6af9 Mon Sep 17 00:00:00 2001 From: rowanad Date: Wed, 31 Jan 2024 16:19:35 +1100 Subject: [PATCH] Added 'retry' option to the alpine-install.func internet check The function still allows the user to continue without internet or to abort the install, but this change adds a third option: retry internet connection. Before this change, I often ran into situations where I could quickly remedy my internet issue (eg firewall config on router) but then I would need to run the lxc install script again from the beginning. --- misc/alpine-install.func | 47 ++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 3820d637..21b42674 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -78,22 +78,51 @@ setting_up_container() { network_check() { set +e trap - ERR - if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then msg_ok "Internet Connected"; else - msg_error "Internet NOT Connected" - read -r -p "Would you like to continue anyway? " prompt - if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then - echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" + + while true; do + if ping -c 1 -W 1 1.1.1.1 &>/dev/null; then + msg_ok "Internet Connected" + break else - echo -e " 🖧 Check Network Settings" - exit 1 + msg_error "Internet NOT Connected" + echo "Choose an option:" + echo "1) Continue without internet" + echo "2) Retest for internet connection" + echo "3) Abort" + read -r -p "Enter your choice (1/2/3): " choice + + case $choice in + 1) + echo -e " ⚠️ ${RD}Expect Issues Without Internet${CL}" + break + ;; + 2) + echo "Retesting internet connection..." + continue + ;; + 3) + echo -e " 🖧 Check Network Settings" + exit 1 + ;; + *) + echo "Invalid option. Please enter 1, 2, or 3." + ;; + esac fi - fi + done + RESOLVEDIP=$(getent hosts github.com | awk '{ print $1 }') - if [[ -z "$RESOLVEDIP" ]]; then msg_error "DNS Lookup Failure"; else msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}"; fi + if [[ -z "$RESOLVEDIP" ]]; then + msg_error "DNS Lookup Failure" + else + msg_ok "DNS Resolved github.com to ${BL}$RESOLVEDIP${CL}" + fi + set -e trap 'error_handler $LINENO "$BASH_COMMAND"' ERR } + update_os() { msg_info "Updating Container OS" $STD apk update