From 66cd1fb05a863227b00f0fa2e3ca7ff0871e0754 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Thu, 26 Mar 2026 13:33:58 +0100 Subject: [PATCH] Add APT by-hash bypass and mirror fallback Improve APT retry logic to handle failures caused by by-hash/CDN issues. Both misc/build.func and misc/install.func now write an apt config to disable Acquire::By-Hash, remove /var/lib/apt/lists/* and retry apt-get update/install; if that still fails they substitute deb.debian.org with ftp.debian.org as a fallback. This makes container builds and package updates more robust against CDN/hash-related apt failures. --- misc/build.func | 7 ++++++- misc/install.func | 18 +++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/misc/build.func b/misc/build.func index 0af90274..8f92afa8 100644 --- a/misc/build.func +++ b/misc/build.func @@ -4601,8 +4601,13 @@ EOF' fi pct exec "$CTID" -- bash -c "apt-get update >/dev/null && apt-get install -y sudo curl mc gnupg2 jq >/dev/null" || { - msg_warn "apt-get base packages failed, retrying with CDN bypass..." + msg_warn "apt-get base packages failed, retrying with by-hash bypass and alternate mirror..." pct exec "$CTID" -- bash -c " + echo 'Acquire::By-Hash \"no\";' >/etc/apt/apt.conf.d/99no-by-hash + rm -rf /var/lib/apt/lists/* + if apt-get update >/dev/null 2>&1 && apt-get install -y sudo curl mc gnupg2 jq >/dev/null 2>&1; then + exit 0 + fi if [ -f /etc/apt/sources.list.d/debian.sources ]; then sed -i 's|deb.debian.org|ftp.debian.org|g' /etc/apt/sources.list.d/debian.sources elif [ -f /etc/apt/sources.list ]; then diff --git a/misc/install.func b/misc/install.func index 470ef3f7..6f8ae80e 100644 --- a/misc/install.func +++ b/misc/install.func @@ -201,14 +201,18 @@ pkg_update() { case "$PKG_MANAGER" in apt) if ! $STD apt-get update; then - msg_warn "apt-get update failed, retrying with CDN bypass..." - if [[ -f /etc/apt/sources.list.d/debian.sources ]]; then - sed -i 's|deb.debian.org|ftp.debian.org|g' /etc/apt/sources.list.d/debian.sources - elif [[ -f /etc/apt/sources.list ]]; then - sed -i 's|deb.debian.org|ftp.debian.org|g' /etc/apt/sources.list - fi + msg_warn "apt-get update failed, retrying with by-hash bypass and alternate mirror..." + echo 'Acquire::By-Hash "no";' >/etc/apt/apt.conf.d/99no-by-hash rm -rf /var/lib/apt/lists/* - $STD apt-get update + if ! $STD apt-get update; then + if [[ -f /etc/apt/sources.list.d/debian.sources ]]; then + sed -i 's|deb.debian.org|ftp.debian.org|g' /etc/apt/sources.list.d/debian.sources + elif [[ -f /etc/apt/sources.list ]]; then + sed -i 's|deb.debian.org|ftp.debian.org|g' /etc/apt/sources.list + fi + rm -rf /var/lib/apt/lists/* + $STD apt-get update + fi fi ;; apk)