Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions core/core.func
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ ensure_tput() {
if grep -qi 'alpine' /etc/os-release; then
apk add --no-cache ncurses >/dev/null 2>&1
elif command -v apt-get >/dev/null 2>&1; then
apt-get update -qq >/dev/null
apt-get update -qq >/dev/null 2>&1 || true
apt-get install -y -qq ncurses-bin >/dev/null 2>&1
fi
fi
Expand Down Expand Up @@ -2372,32 +2372,36 @@ function get_lxc_ip() {
# apt_update_safe()
#
# - Runs apt-get update without letting a partial failure abort the caller
# - Disarms errexit and the ERR trap for the duration, then restores them
# - Warns on a non-zero exit and hints at the enterprise-repo 401/403 case
# - Retries up to three times; a mirror hiccup is the usual cause
# - Leaves the caller's shell options and ERR trap untouched
# - Warns after the last attempt and hints at the enterprise-repo 401/403 case
# ------------------------------------------------------------------------------
apt_update_safe() {
local logfile
local logfile rc=0 attempt from
logfile="$(get_active_logfile)"

local _restore_errexit=false
[[ "$-" == *e* ]] && _restore_errexit=true

set +Eeuo pipefail
trap - ERR

apt-get update >>"$logfile" 2>&1
local rc=$?

if $_restore_errexit; then
set -Eeuo pipefail
trap 'error_handler' ERR
fi
# `|| rc=$?` is exempt from errexit and the ERR trap, so nothing here has to
# touch the caller's shell options.
for attempt in 1 2 3; do
from=$(($(wc -l <"$logfile" 2>/dev/null || echo 0) + 1))
rc=0
apt-get update >>"$logfile" 2>&1 || rc=$?
if [[ "${VERBOSE:-no}" == "yes" ]]; then
tail -n "+${from}" "$logfile" 2>/dev/null
fi
if ((rc == 0)); then
return 0
fi
if ((attempt < 3)); then
sleep $((attempt * 5))
fi
done

if [[ $rc -ne 0 ]]; then
msg_warn "apt-get update exited with code ${rc} — some repositories may have failed."
msg_warn "apt-get update exited with code ${rc} after 3 attempts — some repositories may have failed."

# Check log for common 401/403 enterprise repo issues
if grep -qiE '401\s*Unauthorized|403\s*Forbidden|enterprise\.proxmox\.com' "$logfile" 2>/dev/null; then
if tail -n "+${from}" "$logfile" 2>/dev/null | grep -qiE '401\s*Unauthorized|403\s*Forbidden|enterprise\.proxmox\.com'; then
echo -e "${TAB}${INFO} ${YWB}Hint: Proxmox enterprise repository returned an auth error.${CL}"
echo -e "${TAB} If you don't have a subscription, you can disable the enterprise"
echo -e "${TAB} repo and use the no-subscription repo instead."
Expand Down
4 changes: 2 additions & 2 deletions incus/tools.func
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ network_check() {

update_os() {
msg_info "Updating Container OS"
$STD apt update
apt_update_safe
$STD apt upgrade -y
msg_ok "Updated Container OS"
}
Expand Down Expand Up @@ -260,7 +260,7 @@ _bootstrap() {

if [[ "$need_bootstrap" -eq 1 ]]; then
msg_info "Installing Base Dependencies"
$STD apt update
apt_update_safe
$STD apt install -y "${base_pkgs[@]}"
msg_ok "Installed Base Dependencies"
fi
Expand Down
2 changes: 1 addition & 1 deletion lib/db.func
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ EOF
if ! install_packages_with_retry "mysql-community-server" "mysql-community-client"; then
msg_warn "MySQL 8.4 LTS installation failed – falling back to MariaDB"
cleanup_old_repo_files "mysql"
$STD apt update
apt_update_safe
install_packages_with_retry "mariadb-server" "mariadb-client" || {
msg_error "Failed to install database engine (MySQL/MariaDB fallback)"
return 100
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime.func
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ setup_nodejs() {

# Ensure jq is available for JSON parsing
if ! command -v jq &>/dev/null; then
$STD apt update
apt_update_safe
$STD apt install -y jq || {
msg_error "Failed to install jq"
return 100
Expand Down
2 changes: 1 addition & 1 deletion lib/system.func
Original file line number Diff line number Diff line change
Expand Up @@ -2481,6 +2481,6 @@ Suites: trixie-security
Components: main contrib non-free non-free-firmware
EOF
fi
$STD apt update
apt_update_safe
return 0
}
Loading