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 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() { apt_install_missing() {
local pkgs=("$@") local pkgs=("$@")
local missing=() local missing=()
@ -133,15 +164,15 @@ apt_install_missing() {
return 0 return 0
fi fi
log "RUN: dpkg --configure -a || true" log "Missing packages: ${missing[*]}"
dpkg --configure -a || true
soft_run "APT repair (install -f)" 900 \ if ! apt_repair_state; then
/usr/bin/env DEBIAN_FRONTEND=noninteractive \ log "APT/DPKG repair preflight reported issues; continuing with install"
/usr/bin/apt-get -y \ echo "[!] APT/DPKG repair preflight reported issues; continuing (see $LOG)"
-o Dpkg::Options::="--force-confdef" \ fi
-o Dpkg::Options::="--force-confold" \
install -f
apt_update_if_needed apt_update_if_needed
run_long "Install packages" 1800 \ run_long "Install packages" 1800 \
/usr/bin/env DEBIAN_FRONTEND=noninteractive \ /usr/bin/env DEBIAN_FRONTEND=noninteractive \
/usr/bin/apt-get -y \ /usr/bin/apt-get -y \
@ -235,13 +266,18 @@ spinner() {
printf "\r[%c] %s..." "${spin:$i:1}" "$msg" printf "\r[%c] %s..." "${spin:$i:1}" "$msg"
sleep 0.2 sleep 0.2
done 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 command -v tput >/dev/null 2>&1 && tput cnorm || true
} }
run_long() { run_long() {
local msg="$1"; shift local msg="$1"
local timeout_s="$1"; shift local timeout_s="$2"
local rc
shift 2
log "RUN: $msg :: $*" log "RUN: $msg :: $*"
if command -v timeout >/dev/null 2>&1; then if command -v timeout >/dev/null 2>&1; then
@ -250,8 +286,24 @@ run_long() {
( "$@" >>"$LOG" 2>&1 ) & ( "$@" >>"$LOG" 2>&1 ) &
fi fi
local pid=$! local pid=$!
spinner "$pid" "$msg" 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() { 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)" 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" step "APT update"
apt_update_if_needed apt_update_if_needed