From 937fd1cad47e7804a50ca135291446db9e36ae6e Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Thu, 26 Mar 2026 15:44:58 +0100 Subject: [PATCH] Improve apt mirror logging and error messages Standardize and clarify apt mirror diagnostics in misc/build.func and misc/install.func: update warning phrasing when apt-get update fails; change per-mirror failure messages from "Mirror X: " to "Mirror X failed ()"; change success messages to "CDN set to : tests passed"; and add informational logs like "Attempting mirror: " when trying alternate mirrors. These changes improve visibility into mirror selection and failure reasons during package update/installation. --- misc/build.func | 15 +++++++++------ misc/install.func | 13 ++++++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/misc/build.func b/misc/build.func index fcb77ca66..66f54321c 100644 --- a/misc/build.func +++ b/misc/build.func @@ -4603,7 +4603,7 @@ EOF' pct exec "$CTID" -- bash -c "apt-get update >/dev/null 2>&1 && apt-get install -y sudo curl mc gnupg2 jq >/dev/null 2>&1" || { local failed_mirror failed_mirror=$(pct exec "$CTID" -- bash -c "grep -m1 -oP '(?<=URIs: https?://)[^/]+' /etc/apt/sources.list.d/debian.sources 2>/dev/null || grep -m1 -oP '(?<=deb https?://)[^/]+' /etc/apt/sources.list 2>/dev/null" 2>/dev/null || echo "unknown") - msg_warn "apt-get update failed on ${failed_mirror}, trying alternate mirrors..." + msg_warn "apt-get update failed (${failed_mirror}), trying alternate mirrors..." local mirror_exit=0 pct exec "$CTID" -- bash -c ' APT_BASE="sudo curl mc gnupg2 jq" @@ -4629,19 +4629,19 @@ EOF' APT_OUT=$(apt-get update 2>&1) APT_RC=$? if echo "$APT_OUT" | grep -qi "hashsum\|hash sum"; then - echo " Mirror $1: hash mismatch" + echo " Mirror $1 failed (hash mismatch)" return 1 elif echo "$APT_OUT" | grep -qi "SSL\|certificate"; then - echo " Mirror $1: SSL/certificate error" + echo " Mirror $1 failed (SSL/certificate error)" return 1 elif [ $APT_RC -ne 0 ]; then - echo " Mirror $1: apt-get update failed" + echo " Mirror $1 failed (apt-get update error)" return 1 elif apt-get install -y $APT_BASE >/dev/null 2>&1; then - echo " Using mirror: $1" + echo " CDN set to $1: tests passed" return 0 else - echo " Mirror $1: package install failed" + echo " Mirror $1 failed (package install error)" return 1 fi } @@ -4661,11 +4661,13 @@ EOF' OTHERS_PICK=$(printf "%s\n" $OTHERS_OK | shuf | head -3 | xargs) for mirror in $OTHERS_PICK; do + echo " Attempting mirror: $mirror" try_mirrors "$mirror" && exit 0 done # Phase 2: Try ftp.debian.org if timeout 2 bash -c "echo >/dev/tcp/ftp.debian.org/80" 2>/dev/null; then + echo " Attempting mirror: ftp.debian.org" try_mirrors "ftp.debian.org" && exit 0 fi @@ -4674,6 +4676,7 @@ EOF' REGIONAL_PICK=$(printf "%s\n" $REGIONAL_OK | shuf | head -3 | xargs) for mirror in $REGIONAL_PICK; do + echo " Attempting mirror: $mirror" try_mirrors "$mirror" && exit 0 done diff --git a/misc/install.func b/misc/install.func index ddd177afc..b48357c8e 100644 --- a/misc/install.func +++ b/misc/install.func @@ -203,7 +203,7 @@ pkg_update() { if ! $STD apt-get update; then local failed_mirror failed_mirror=$(grep -m1 -oP '(?<=URIs: https?://)[^/]+' /etc/apt/sources.list.d/debian.sources 2>/dev/null || grep -m1 -oP '(?<=deb https?://)[^/]+' /etc/apt/sources.list 2>/dev/null || echo "unknown") - msg_warn "apt-get update failed on ${failed_mirror}, trying alternate mirrors..." + msg_warn "apt-get update failed (${failed_mirror}), trying alternate mirrors..." local eu_mirrors="ftp.de.debian.org ftp.fr.debian.org ftp.nl.debian.org ftp.uk.debian.org ftp.ch.debian.org ftp.se.debian.org ftp.it.debian.org ftp.fau.de ftp.halifax.rwth-aachen.de debian.mirror.lrz.de mirror.init7.net debian.ethz.ch mirrors.dotsrc.org debian.mirrors.ovh.net" local us_mirrors="ftp.us.debian.org ftp.ca.debian.org debian.csail.mit.edu mirrors.ocf.berkeley.edu mirrors.wikimedia.org debian.osuosl.org mirror.cogentco.com" local ap_mirrors="ftp.au.debian.org ftp.jp.debian.org ftp.tw.debian.org ftp.kr.debian.org ftp.hk.debian.org ftp.sg.debian.org mirror.aarnet.edu.au mirror.nitc.ac.in" @@ -240,16 +240,16 @@ pkg_update() { local out out=$(apt-get update 2>&1) if echo "$out" | grep -qi "hashsum\|hash sum"; then - msg_warn "Mirror ${m}: hash mismatch, trying next..." + msg_warn "Mirror ${m} failed (hash mismatch)" return 1 elif echo "$out" | grep -qi "SSL\|certificate"; then - msg_warn "Mirror ${m}: SSL/certificate error, trying next..." + msg_warn "Mirror ${m} failed (SSL/certificate error)" return 1 elif echo "$out" | grep -q "^E:"; then - msg_warn "Mirror ${m}: apt-get update failed, trying next..." + msg_warn "Mirror ${m} failed (apt-get update error)" return 1 else - msg_ok "Using mirror: ${m}" + msg_ok "CDN set to ${m}: tests passed" return 0 fi } @@ -273,6 +273,7 @@ pkg_update() { others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs) for mirror in $others_pick; do + msg_info "Attempting mirror: ${mirror}" if _try_apt_mirror "$mirror"; then apt_ok=true break @@ -282,6 +283,7 @@ pkg_update() { # Phase 2: Try ftp.debian.org if [[ "$apt_ok" != true ]]; then if timeout 2 bash -c "echo >/dev/tcp/ftp.debian.org/80" 2>/dev/null; then + msg_info "Attempting mirror: ftp.debian.org" if _try_apt_mirror "ftp.debian.org"; then apt_ok=true fi @@ -296,6 +298,7 @@ pkg_update() { regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs) for mirror in $regional_pick; do + msg_info "Attempting mirror: ${mirror}" if _try_apt_mirror "$mirror"; then apt_ok=true break