Standardize mirror messaging; simplify apt update

Replace inconsistent msg_info calls with msg_warn for mirror-list warnings and msg_custom for "Attempting mirror" lines to unify output formatting in misc/build.func and misc/install.func. Simplify tools/pve/update-lxcs-cron.sh by removing the long mirror-probing block and using a straightforward apt-get update + noninteractive dist-upgrade (and cleanup of EXTERNALLY-MANAGED) in containers to reduce complexity and improve maintainability.
This commit is contained in:
CanbiZ (MickLesk)
2026-03-26 16:32:25 +01:00
parent 6c35b9b978
commit 441158b195
3 changed files with 9 additions and 35 deletions

View File

@@ -4724,9 +4724,9 @@ EOF
if [[ $mirror_exit -eq 2 ]]; then if [[ $mirror_exit -eq 2 ]]; then
msg_warn "Multiple mirrors failed (possible CDN synchronization issue)." msg_warn "Multiple mirrors failed (possible CDN synchronization issue)."
if [[ "$var_os" == "ubuntu" ]]; then if [[ "$var_os" == "ubuntu" ]]; then
msg_info "Find Ubuntu mirrors at: https://launchpad.net/ubuntu/+archivemirrors" msg_warn "Find Ubuntu mirrors at: https://launchpad.net/ubuntu/+archivemirrors"
else else
msg_info "Find Debian mirrors at: https://www.debian.org/mirror/list" msg_warn "Find Debian mirrors at: https://www.debian.org/mirror/list"
fi fi
local custom_mirror="" local custom_mirror=""
while true; do while true; do

View File

@@ -283,7 +283,7 @@ pkg_update() {
others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs) others_pick=$(printf '%s\n' $others_ok | shuf | head -3 | xargs)
for mirror in $others_pick; do for mirror in $others_pick; do
msg_info "Attempting mirror: ${mirror}" msg_custom "${INFO}" "${YW}" "Attempting mirror: ${mirror}"
if _try_apt_mirror "$mirror"; then if _try_apt_mirror "$mirror"; then
apt_ok=true apt_ok=true
break break
@@ -299,7 +299,7 @@ pkg_update() {
primary="ftp.debian.org" primary="ftp.debian.org"
fi fi
if timeout 2 bash -c "echo >/dev/tcp/$primary/80" 2>/dev/null; then if timeout 2 bash -c "echo >/dev/tcp/$primary/80" 2>/dev/null; then
msg_info "Attempting mirror: ${primary}" msg_custom "${INFO}" "${YW}" "Attempting mirror: ${primary}"
if _try_apt_mirror "$primary"; then if _try_apt_mirror "$primary"; then
apt_ok=true apt_ok=true
fi fi
@@ -314,7 +314,7 @@ pkg_update() {
regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs) regional_pick=$(printf '%s\n' $regional_ok | shuf | head -3 | xargs)
for mirror in $regional_pick; do for mirror in $regional_pick; do
msg_info "Attempting mirror: ${mirror}" msg_custom "${INFO}" "${YW}" "Attempting mirror: ${mirror}"
if _try_apt_mirror "$mirror"; then if _try_apt_mirror "$mirror"; then
apt_ok=true apt_ok=true
break break
@@ -326,9 +326,9 @@ pkg_update() {
if [[ "$apt_ok" != true ]]; then if [[ "$apt_ok" != true ]]; then
msg_warn "Multiple mirrors failed (possible CDN synchronization issue)." msg_warn "Multiple mirrors failed (possible CDN synchronization issue)."
if [[ "$distro" == "ubuntu" ]]; then if [[ "$distro" == "ubuntu" ]]; then
msg_info "Find Ubuntu mirrors at: https://launchpad.net/ubuntu/+archivemirrors" msg_warn "Find Ubuntu mirrors at: https://launchpad.net/ubuntu/+archivemirrors"
else else
msg_info "Find Debian mirrors at: https://www.debian.org/mirror/list" msg_warn "Find Debian mirrors at: https://www.debian.org/mirror/list"
fi fi
while true; do while true; do
read -rp " Enter a mirror hostname (or 'skip' to abort): " custom_mirror </dev/tty read -rp " Enter a mirror hostname (or 'skip' to abort): " custom_mirror </dev/tty
@@ -359,7 +359,7 @@ pkg_update() {
local apk_ok=false local apk_ok=false
for m in $(printf '%s\n' $alpine_mirrors | shuf); do for m in $(printf '%s\n' $alpine_mirrors | shuf); do
if timeout 2 bash -c "echo >/dev/tcp/$m/80" 2>/dev/null; then if timeout 2 bash -c "echo >/dev/tcp/$m/80" 2>/dev/null; then
msg_info "Attempting mirror: ${m}" msg_custom "${INFO}" "${YW}" "Attempting mirror: ${m}"
cat <<EOF >/etc/apk/repositories cat <<EOF >/etc/apk/repositories
http://$m/alpine/latest-stable/main http://$m/alpine/latest-stable/main
http://$m/alpine/latest-stable/community http://$m/alpine/latest-stable/community

View File

@@ -35,33 +35,7 @@ function update_container() {
alpine) pct exec "$container" -- ash -c "apk -U upgrade" ;; alpine) pct exec "$container" -- ash -c "apk -U upgrade" ;;
archlinux) pct exec "$container" -- bash -c "pacman -Syyu --noconfirm" ;; archlinux) pct exec "$container" -- bash -c "pacman -Syyu --noconfirm" ;;
fedora | rocky | centos | alma) pct exec "$container" -- bash -c "dnf -y update && dnf -y upgrade" ;; fedora | rocky | centos | alma) pct exec "$container" -- bash -c "dnf -y update && dnf -y upgrade" ;;
ubuntu | debian | devuan) pct exec "$container" -- bash -c ' ubuntu | debian | devuan) pct exec "$container" -- bash -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::='--force-confold' dist-upgrade -y; rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED" ;;
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"
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"
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"
TZ=$(cat /etc/timezone 2>/dev/null || echo "UTC")
case "$TZ" in
Europe/*|Arctic/*) REGIONAL="$EU_MIRRORS"; OTHERS="$US_MIRRORS $AP_MIRRORS" ;;
America/*) REGIONAL="$US_MIRRORS"; OTHERS="$EU_MIRRORS $AP_MIRRORS" ;;
Asia/*|Australia/*|Pacific/*) REGIONAL="$AP_MIRRORS"; OTHERS="$EU_MIRRORS $US_MIRRORS" ;;
*) REGIONAL=""; OTHERS="$EU_MIRRORS $US_MIRRORS $AP_MIRRORS" ;;
esac
apt-get update || {
echo "Acquire::By-Hash \"no\";" >/etc/apt/apt.conf.d/99no-by-hash
ALL_MIRRORS="$(printf "%s\n" $OTHERS | shuf | head -3 | xargs) ftp.debian.org $(printf "%s\n" $REGIONAL | shuf | head -3 | xargs)"
for mirror in $ALL_MIRRORS; do
timeout 2 bash -c "echo >/dev/tcp/$mirror/80" 2>/dev/null || continue
for src in /etc/apt/sources.list.d/debian.sources /etc/apt/sources.list; do
[ -f "$src" ] && sed -i "s|URIs: http[s]*://[^/]*/|URIs: http://${mirror}/|g; s|deb http[s]*://[^/]*/|deb http://${mirror}/|g" "$src"
done
rm -rf /var/lib/apt/lists/*
if apt-get update; then echo " Using mirror: $mirror"; break; else echo " Mirror $mirror failed"; fi
done
}
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -y
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED' ;;
opensuse) pct exec "$container" -- bash -c "zypper ref && zypper --non-interactive dup" ;; opensuse) pct exec "$container" -- bash -c "zypper ref && zypper --non-interactive dup" ;;
*) echo " [Warn] Unknown OS type '$os' for container $container, skipping" ;; *) echo " [Warn] Unknown OS type '$os' for container $container, skipping" ;;
esac esac