From 6ac378b46449ad959abdc49f80fa52b986fe0a34 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Mon, 23 Mar 2026 15:21:15 +0100 Subject: [PATCH] Improve network connectivity and DNS checks Revamp network_check(): add an ipv4_connected flag and explicit ping tests against Cloudflare/Google/Quad9, show clearer msg_ok/msg_error output, and only prompt the user when no IPv4 connectivity is detected. Replace the single github.com resolution with DNS checks for multiple GitHub-related hosts (github.com, raw.githubusercontent.com, api.github.com, git.community-scripts.org), build a combined status string, and fatal out if any of those fail to resolve. Overall this tightens connectivity validation for installs that depend on GitHub resources and provides clearer user feedback. --- misc/alpine-install.func | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 23af25128..0b7d9708b 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -90,11 +90,18 @@ setting_up_container() { network_check() { set +e trap - ERR + ipv4_connected=false + + # Check IPv4 connectivity to Cloudflare, Google & Quad9 DNS servers if ping -c 1 -W 1 1.1.1.1 &>/dev/null || ping -c 1 -W 1 8.8.8.8 &>/dev/null || ping -c 1 -W 1 9.9.9.9 &>/dev/null; then - ipv4_status="${GN}✔${CL} IPv4" + msg_ok "IPv4 Internet Connected" + ipv4_connected=true else - ipv4_status="${RD}✖${CL} IPv4" - read -r -p "Internet NOT connected. Continue anyway? " prompt + msg_error "IPv4 Internet Not Connected" + fi + + if [[ $ipv4_connected == false ]]; then + read -r -p "No Internet detected, would you like to continue anyway? " prompt if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then echo -e "${INFO}${RD}Expect Issues Without Internet${CL}" else @@ -102,12 +109,28 @@ network_check() { exit 122 fi fi - RESOLVEDIP=$(getent hosts github.com | awk '{ print $1 }') - if [[ -z "$RESOLVEDIP" ]]; then - msg_error "Internet: ${ipv4_status} DNS Failed" + + # DNS resolution checks for GitHub-related domains + GIT_HOSTS=("github.com" "raw.githubusercontent.com" "api.github.com" "git.community-scripts.org") + GIT_STATUS="Git DNS:" + DNS_FAILED=false + + for HOST in "${GIT_HOSTS[@]}"; do + RESOLVEDIP=$(getent hosts "$HOST" | awk '{ print $1 }' | grep -E '(^([0-9]{1,3}\.){3}[0-9]{1,3}$)|(^[a-fA-F0-9:]+$)' | head -n1) + if [[ -z "$RESOLVEDIP" ]]; then + GIT_STATUS+="$HOST:($DNSFAIL)" + DNS_FAILED=true + else + GIT_STATUS+=" $HOST:($DNSOK)" + fi + done + + if [[ "$DNS_FAILED" == true ]]; then + fatal "$GIT_STATUS" else - msg_ok "Internet: ${ipv4_status} DNS: ${BL}${RESOLVEDIP}${CL}" + msg_ok "$GIT_STATUS" fi + set -e trap 'error_handler $LINENO "$BASH_COMMAND"' ERR }