From 5b4392155021e09978a1d9c7308bffbb0b4e3432 Mon Sep 17 00:00:00 2001 From: sharky Date: Sun, 4 Oct 2026 17:26:58 +0200 Subject: [PATCH] V15 --- updater.sh | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/updater.sh b/updater.sh index 695152a..189ad48 100644 --- a/updater.sh +++ b/updater.sh @@ -31,6 +31,7 @@ ONLY_VM="" NO_REBOOT="no" ERRORS=0 +ERROR_DETAILS=() HOST_OK="not-run" HOST_REBOOT_REQUIRED="no" HOST_REBOOT_SCHEDULED="no" @@ -71,6 +72,12 @@ log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" } +add_error() { + local detail="$1" + ERROR_DETAILS+=("$detail") +} + + ensure_notification_setup() { [[ "$NOTIFY_ENABLED" == "yes" ]] || return 0 @@ -147,7 +154,17 @@ send_update_notification() { title="Proxmox Updater - $status" fi - message="Proxmox Guest Updater + local error_details_text="Keine" + if (( ${#ERROR_DETAILS[@]} > 0 )); then + error_details_text="" + local error_detail + for error_detail in "${ERROR_DETAILS[@]}"; do + error_details_text+="- ${error_detail}"$'\n' + done + error_details_text="${error_details_text%$'\n'}" + fi + +message="Proxmox Guest Updater Host: $(hostname) Zeit: $(date '+%d.%m.%Y %H:%M:%S') @@ -170,6 +187,9 @@ VM: Fehler gesamt: $ERRORS +Fehlerdetails: +$error_details_text + Neustarts: $MAIL_STATUS_DETAIL @@ -498,6 +518,7 @@ check_lxc() { if ! pct exec "$id" -- bash -lc 'apt-get update'; then log "CT $id ($name): apt-get update FEHLER." + add_error "CT $id ($name): apt-get update fehlgeschlagen" LXC_FAILED=$((LXC_FAILED + 1)) ERRORS=$((ERRORS + 1)) return @@ -571,6 +592,7 @@ update_lxc() { if ! pct exec "$id" -- bash -lc 'apt-get update'; then log "CT $id ($name): apt-get update FEHLER." + add_error "CT $id ($name): apt-get update fehlgeschlagen" LXC_FAILED=$((LXC_FAILED + 1)) ERRORS=$((ERRORS + 1)) @@ -589,6 +611,7 @@ update_lxc() { if ! simulation="$(pct exec "$id" -- bash -lc 'LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get -s full-upgrade' 2>&1)"; then printf '%s\n' "$simulation" log "CT $id ($name): full-upgrade Simulation FEHLER." + add_error "CT $id ($name): full-upgrade Simulation fehlgeschlagen" LXC_FAILED=$((LXC_FAILED + 1)) ERRORS=$((ERRORS + 1)) @@ -604,6 +627,7 @@ update_lxc() { if [[ -z "$upgraded" || -z "$installed" || -z "$removed" ]]; then log "CT $id ($name): Simulation konnte nicht ausgewertet werden." + add_error "CT $id ($name): full-upgrade Simulation konnte nicht ausgewertet werden" LXC_FAILED=$((LXC_FAILED + 1)) ERRORS=$((ERRORS + 1)) if [[ "$started_by_us" == "yes" ]]; then @@ -622,6 +646,7 @@ update_lxc() { 'DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" full-upgrade' then log "CT $id ($name): full-upgrade FEHLER." + add_error "CT $id ($name): full-upgrade fehlgeschlagen" LXC_FAILED=$((LXC_FAILED + 1)) ERRORS=$((ERRORS + 1)) @@ -886,6 +911,7 @@ update_vm() { if ! vm_exec "$id" 'apt-get update'; then log "VM $id ($name): apt-get update FEHLER." + add_error "VM $id ($name): apt-get update fehlgeschlagen" VM_FAILED=$((VM_FAILED + 1)) ERRORS=$((ERRORS + 1)) @@ -909,6 +935,7 @@ update_vm() { if (( sim_rc != 0 )) || ! printf '%s\n' "$simulation" | grep -Eq '"exitcode"[[:space:]]*:[[:space:]]*0'; then printf '%s\n' "$simulation" log "VM $id ($name): full-upgrade Simulation FEHLER." + add_error "VM $id ($name): full-upgrade Simulation fehlgeschlagen" VM_FAILED=$((VM_FAILED + 1)) ERRORS=$((ERRORS + 1)) if [[ "$started_by_us" == "yes" ]]; then @@ -924,6 +951,7 @@ update_vm() { if [[ -z "$upgraded" || -z "$installed" || -z "$removed" ]]; then printf '%s\n' "$simulation" log "VM $id ($name): Simulation konnte nicht ausgewertet werden." + add_error "VM $id ($name): full-upgrade Simulation konnte nicht ausgewertet werden" VM_FAILED=$((VM_FAILED + 1)) ERRORS=$((ERRORS + 1)) if [[ "$started_by_us" == "yes" ]]; then @@ -942,6 +970,7 @@ update_vm() { 'DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" full-upgrade' then log "VM $id ($name): full-upgrade FEHLER." + add_error "VM $id ($name): full-upgrade fehlgeschlagen" VM_FAILED=$((VM_FAILED + 1)) ERRORS=$((ERRORS + 1)) @@ -1147,6 +1176,13 @@ else fi log "" log "Fehler gesamt: $ERRORS" + if (( ${#ERROR_DETAILS[@]} > 0 )); then + log "" + log "Fehlerdetails:" + for error_detail in "${ERROR_DETAILS[@]}"; do + log "- $error_detail" + done + fi log "Host Update: $HOST_OK" log "Host Reboot nötig: $HOST_REBOOT_REQUIRED" log "============================================================"