This commit is contained in:
sharky committed 2026-10-04 19:16:06 +02:00
1 parent 57903725c1
commit 1ddfb1233a
1 file changed
+30 -8
+30 -8
View File
@@ -984,11 +984,23 @@ update_vm() {
local installed=0
local removed=0
simulation="$(qm guest exec "$id" -- bash -lc \
'LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get -s upgrade | tail -n1' 2>&1)"
simulation="$(qm guest exec "$id" -- bash -lc '
out="$(LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get -s upgrade 2>&1)" || exit 10
summary="$(printf "%s\n" "$out" | grep -E "^[0-9]+ upgraded, [0-9]+ newly installed, [0-9]+ to remove" | tail -n1)"
[ -n "$summary" ] || exit 11
set -- $summary
upgraded="$1"
installed="$3"
removed="$6"
printf "APTCOUNTS=%s,%s,%s\n" "$upgraded" "$installed" "$removed"
if [ "$upgraded" -eq 0 ] && [ "$installed" -eq 0 ] && [ "$removed" -eq 0 ]; then
exit 0
fi
exit 42
' 2>&1)"
sim_rc=$?
if (( sim_rc != 0 )) || ! printf '%s\n' "$simulation" | grep -Eq '"exitcode"[[:space:]]*:[[:space:]]*0'; then
if (( sim_rc != 0 )); then
printf '%s\n' "$simulation"
log "VM $id ($name): upgrade Simulation FEHLER."
add_error "VM $id ($name): upgrade Simulation fehlgeschlagen"
@@ -1000,13 +1012,21 @@ update_vm() {
return
fi
upgraded="$(printf '%s\n' "$simulation" | sed -nE 's/.*out-data"[[:space:]]*:[[:space:]]*"([0-9]+) upgraded, ([0-9]+) newly installed, ([0-9]+) to remove.*/\1/p' | head -n1)"
installed="$(printf '%s\n' "$simulation" | sed -nE 's/.*out-data"[[:space:]]*:[[:space:]]*"([0-9]+) upgraded, ([0-9]+) newly installed, ([0-9]+) to remove.*/\2/p' | head -n1)"
removed="$(printf '%s\n' "$simulation" | sed -nE 's/.*out-data"[[:space:]]*:[[:space:]]*"([0-9]+) upgraded, ([0-9]+) newly installed, ([0-9]+) to remove.*/\3/p' | head -n1)"
guest_rc="$(
printf '%s\n' "$simulation" |
sed -nE 's/^[[:space:]]*"exitcode"[[:space:]]*:[[:space:]]*([0-9]+),?[[:space:]]*$/\1/p' |
head -n1
)"
if [[ -z "$upgraded" || -z "$installed" || -z "$removed" ]]; then
counts="$(
printf '%s\n' "$simulation" |
sed -nE 's/.*APTCOUNTS=([0-9]+),([0-9]+),([0-9]+).*/\1 \2 \3/p' |
head -n1
)"
if [[ -z "$guest_rc" || -z "$counts" || ( "$guest_rc" != "0" && "$guest_rc" != "42" ) ]]; then
printf '%s\n' "$simulation"
log "VM $id ($name): Simulation konnte nicht ausgewertet werden."
log "VM $id ($name): upgrade Simulation konnte nicht ausgewertet werden."
add_error "VM $id ($name): upgrade Simulation konnte nicht ausgewertet werden"
VM_FAILED=$((VM_FAILED + 1))
ERRORS=$((ERRORS + 1))
@@ -1016,6 +1036,8 @@ update_vm() {
return
fi
read -r upgraded installed removed <<< "$counts"
if (( upgraded == 0 && installed == 0 && removed == 0 )); then
log "VM $id ($name): bereits aktuell."
VM_CURRENT=$((VM_CURRENT + 1))