From cd1c4128226e0877c35cc8ff7b140be68ebc96e3 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Thu, 26 Mar 2026 14:52:03 +0100 Subject: [PATCH] Try global mirrors first; add apt fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reorder mirror probing in misc/build.func and misc/install.func to scan global (OTHERS) mirrors first and fall back to regional mirrors—pick up to 3 random reachable mirrors and try them. Rename related variables accordingly and keep the fallback logic intact. Update tools/pve/update-lxcs-cron.sh to define region-specific Debian mirror lists, detect container timezone to pick regional vs other mirrors, and implement a fallback loop that checks mirror connectivity, rewrites APT URIs to use a working mirror, and retries apt-get update before proceeding with dist-upgrade. These changes improve resilience against local CDN/local-regional outages by preferring globally reachable mirrors first and providing an automated mirror-switch fallback. --- misc/build.func | 28 ++++++++++++++-------------- misc/install.func | 40 ++++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/misc/build.func b/misc/build.func index bde18e63..ebc1008a 100644 --- a/misc/build.func +++ b/misc/build.func @@ -4655,14 +4655,14 @@ EOF' echo "$result" | xargs } - # Phase 1: Scan regional mirrors, pick 3 random, try them - echo " [scan] Checking regional mirrors..." - REGIONAL_OK=$(scan_reachable "$REGIONAL") - REGIONAL_PICK=$(printf "%s\n" $REGIONAL_OK | shuf | head -3 | xargs) - R_COUNT=$(echo $REGIONAL_PICK | wc -w) - echo " [scan] $R_COUNT regional mirrors reachable (of $(echo $REGIONAL | wc -w))" + # Phase 1: Scan global mirrors first (independent of local CDN issues) + echo " [scan] Checking global mirrors..." + OTHERS_OK=$(scan_reachable "$OTHERS") + OTHERS_PICK=$(printf "%s\n" $OTHERS_OK | shuf | head -3 | xargs) + O_COUNT=$(echo $OTHERS_PICK | wc -w) + echo " [scan] $O_COUNT global mirrors reachable (of $(echo $OTHERS | wc -w))" - for mirror in $REGIONAL_PICK; do + for mirror in $OTHERS_PICK; do echo " [try] $mirror ..." try_mirrors "$mirror" && exit 0 done @@ -4673,14 +4673,14 @@ EOF' try_mirrors "ftp.debian.org" && exit 0 fi - # Phase 3: Scan rest-of-world mirrors, pick 3 random, try them - echo " [scan] Checking global mirrors..." - OTHERS_OK=$(scan_reachable "$OTHERS") - OTHERS_PICK=$(printf "%s\n" $OTHERS_OK | shuf | head -3 | xargs) - O_COUNT=$(echo $OTHERS_PICK | wc -w) - echo " [scan] $O_COUNT global mirrors reachable (of $(echo $OTHERS | wc -w))" + # Phase 3: Fall back to regional mirrors + echo " [scan] Checking regional mirrors..." + REGIONAL_OK=$(scan_reachable "$REGIONAL") + REGIONAL_PICK=$(printf "%s\n" $REGIONAL_OK | shuf | head -3 | xargs) + R_COUNT=$(echo $REGIONAL_PICK | wc -w) + echo " [scan] $R_COUNT regional mirrors reachable (of $(echo $REGIONAL | wc -w))" - for mirror in $OTHERS_PICK; do + for mirror in $REGIONAL_PICK; do echo " [try] $mirror ..." try_mirrors "$mirror" && exit 0 done diff --git a/misc/install.func b/misc/install.func index 6656b664..3317b650 100644 --- a/misc/install.func +++ b/misc/install.func @@ -265,17 +265,17 @@ pkg_update() { local apt_ok=false - # Phase 1: Scan regional mirrors, pick 3 random, try them - msg_info "Scanning regional mirrors..." - local regional_ok - regional_ok=$(_scan_reachable "$regional") - local regional_pick - regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs) - local r_count - r_count=$(echo "$regional_pick" | wc -w) - msg_info "Found ${r_count} regional mirrors to try" + # Phase 1: Scan global mirrors first (independent of local CDN issues) + msg_info "Scanning global mirrors..." + local others_ok + others_ok=$(_scan_reachable "$others") + local others_pick + others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs) + local o_count + o_count=$(echo "$others_pick" | wc -w) + msg_info "Found ${o_count} global mirrors to try" - for mirror in $regional_pick; do + for mirror in $others_pick; do msg_info "Trying mirror: ${mirror}" if _try_apt_mirror "$mirror"; then apt_ok=true @@ -293,18 +293,18 @@ pkg_update() { fi fi - # Phase 3: Scan rest-of-world mirrors, pick 3 random, try them + # Phase 3: Fall back to regional mirrors if [[ "$apt_ok" != true ]]; then - msg_info "Scanning global mirrors..." - local others_ok - others_ok=$(_scan_reachable "$others") - local others_pick - others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs) - local o_count - o_count=$(echo "$others_pick" | wc -w) - msg_info "Found ${o_count} global mirrors to try" + msg_info "Scanning regional mirrors..." + local regional_ok + regional_ok=$(_scan_reachable "$regional") + local regional_pick + regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs) + local r_count + r_count=$(echo "$regional_pick" | wc -w) + msg_info "Found ${r_count} regional mirrors to try" - for mirror in $others_pick; do + for mirror in $regional_pick; do msg_info "Trying mirror: ${mirror}" if _try_apt_mirror "$mirror"; then apt_ok=true