stage_env: update dpkg problem

This commit is contained in:
Andrei Smaliak 2026-04-02 18:34:34 +04:00
parent 355accac1d
commit ac0c1ec683
1 changed files with 71 additions and 13 deletions

View File

@ -117,6 +117,37 @@ apt_update_if_needed() {
fi
}
apt_repair_state() {
local rc=0
log "APT/DPKG repair preflight: start"
log "RUN: dpkg --audit || true"
dpkg --audit >>"$LOG" 2>&1 || true
if ! run_long "DPKG configure pending packages" 1800 \
/usr/bin/dpkg --configure -a; then
rc=1
fi
if ! run_long "APT repair (install -f)" 1800 \
/usr/bin/env DEBIAN_FRONTEND=noninteractive \
/usr/bin/apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
-f install; then
rc=1
fi
if ! run_long "APT check" 900 \
/usr/bin/apt-get check; then
rc=1
fi
log "APT/DPKG repair preflight: complete rc=$rc"
return "$rc"
}
apt_install_missing() {
local pkgs=("$@")
local missing=()
@ -133,15 +164,15 @@ apt_install_missing() {
return 0
fi
log "RUN: dpkg --configure -a || true"
dpkg --configure -a || true
soft_run "APT repair (install -f)" 900 \
/usr/bin/env DEBIAN_FRONTEND=noninteractive \
/usr/bin/apt-get -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
install -f
log "Missing packages: ${missing[*]}"
if ! apt_repair_state; then
log "APT/DPKG repair preflight reported issues; continuing with install"
echo "[!] APT/DPKG repair preflight reported issues; continuing (see $LOG)"
fi
apt_update_if_needed
run_long "Install packages" 1800 \
/usr/bin/env DEBIAN_FRONTEND=noninteractive \
/usr/bin/apt-get -y \
@ -235,13 +266,18 @@ spinner() {
printf "\r[%c] %s..." "${spin:$i:1}" "$msg"
sleep 0.2
done
printf "\r[✓] %s. \n" "$msg"
if [ -t 1 ]; then
printf "\r%-80s\r" ""
fi
command -v tput >/dev/null 2>&1 && tput cnorm || true
}
run_long() {
local msg="$1"; shift
local timeout_s="$1"; shift
local msg="$1"
local timeout_s="$2"
local rc
shift 2
log "RUN: $msg :: $*"
if command -v timeout >/dev/null 2>&1; then
@ -250,8 +286,24 @@ run_long() {
( "$@" >>"$LOG" 2>&1 ) &
fi
local pid=$!
spinner "$pid" "$msg"
wait "$pid"
if wait "$pid"; then
rc=0
else
rc=$?
fi
if [ "$rc" -eq 0 ]; then
log "OK: $msg"
echo "[OK] $msg"
else
log "FAIL($rc): $msg"
echo "[FAIL:$rc] $msg (see $LOG)"
fi
return "$rc"
}
soft_run() {
@ -310,8 +362,14 @@ rm -f /etc/apt/sources.list.d/*.list 2>/dev/null || true
log "APT sources normalized to official Debian 11 (no backports)"
# -------------------------
# Step 3: APT update
# Step 3: APT repair + update
# -------------------------
step "APT/DPKG repair preflight"
if ! apt_repair_state; then
log "APT/DPKG repair preflight reported issues before update; continuing"
echo "[!] APT/DPKG repair preflight reported issues before update (see $LOG)"
fi
step "APT update"
apt_update_if_needed