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.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-26 13:33:58 +01:00
parent 6614b65bc1
commit 66cd1fb05a
2 changed files with 17 additions and 8 deletions

View File

@@ -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

View File

@@ -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)