From 4f9193a229356f92b26577840c56283041882de8 Mon Sep 17 00:00:00 2001 From: sharky Date: Sun, 4 Oct 2026 21:41:23 +0200 Subject: [PATCH] manager.sh aktualisiert --- manager.sh | 1423 ++++++++++++++++++---------------------------------- 1 file changed, 501 insertions(+), 922 deletions(-) diff --git a/manager.sh b/manager.sh index 02dc417..5196747 100644 --- a/manager.sh +++ b/manager.sh @@ -1,51 +1,24 @@ #!/usr/bin/env bash set -Eeuo pipefail -# ============================================================ -# Proxmox Guest Updater - Manager -# Installation, Konfiguration, Zeitplan, Status, Deinstallation -# ============================================================ - -REPO="https://gitea.vourx.com/sharky/Proxmox-und-GuestUpdater" -RAW="${REPO}/raw/branch/main" +# Proxmox Guest Updater Manager +# Neuaufbau: stabile whiptail-Oberflaeche statt selbst gezeichneter Cursor-Menues. +RAW="https://gitea.vourx.com/sharky/Proxmox-und-GuestUpdater/raw/branch/main" UPDATER="/usr/local/sbin/pve-guest-update" CONFIG="/etc/pve-guest-update.conf" SERVICE="/etc/systemd/system/pve-guest-update.service" TIMER="/etc/systemd/system/pve-guest-update.timer" LOGFILE="/var/log/pve-guest-update.log" -NOTIFY_MATCHER="proxmox-updater" -NOTIFY_TEMPLATE="proxmox-updater" - -# ---------- Farben ---------- -if [[ -t 1 ]]; then - C_RESET=$'\033[0m' - C_BOLD=$'\033[1m' - C_DIM=$'\033[2m' - C_RED=$'\033[1;31m' - C_GREEN=$'\033[1;32m' - C_YELLOW=$'\033[1;33m' - C_BLUE=$'\033[1;34m' - C_CYAN=$'\033[1;36m' - C_WHITE=$'\033[1;37m' - C_INV=$'\033[7m' -else - C_RESET=""; C_BOLD=""; C_DIM=""; C_RED=""; C_GREEN="" - C_YELLOW=""; C_BLUE=""; C_CYAN=""; C_WHITE=""; C_INV="" -fi - -# ---------- Standardwerte ---------- UPDATE_HOST="yes" UPDATE_LXC="yes" UPDATE_VMS="yes" UPDATE_STOPPED="no" AUTO_REBOOT_HOST="yes" -EXCLUDE_GUESTS="" - NOTIFY_ENABLED="no" NOTIFY_TARGET="" - +EXCLUDE_GUESTS="" APT_LOCK_TIMEOUT="600" BACKUP_WAIT_TIMEOUT="7200" BACKUP_WAIT_INTERVAL="60" @@ -62,191 +35,79 @@ SCHEDULE_YEAR_DAY="1" ONCALENDAR="Sun *-*-* 04:00:00" INSTALLED="no" -DIRTY="no" -# ============================================================ -# Basis / UI -# ============================================================ +die() { echo "FEHLER: $*" >&2; exit 1; } -die() { - printf '\n%sFEHLER:%s %s\n' "$C_RED" "$C_RESET" "$*" >&2 - exit 1 -} - -cleanup_terminal() { - printf '%s' "$C_RESET" >/dev/tty 2>/dev/null || true - stty sane /dev/null || true -} -trap cleanup_terminal EXIT - -need_root_and_pve() { - [[ $EUID -eq 0 ]] || die "Bitte als root auf dem Proxmox-Host ausführen." +need_base() { + [[ $EUID -eq 0 ]] || die "Bitte als root ausfuehren." command -v pveversion >/dev/null 2>&1 || die "Proxmox VE wurde nicht erkannt." - [[ -r /dev/tty && -w /dev/tty ]] || die "Für den Manager wird ein interaktives Terminal benötigt." + command -v python3 >/dev/null 2>&1 || die "python3 fehlt." + if ! command -v whiptail >/dev/null 2>&1; then + echo "Installiere whiptail fuer die Menueoberflaeche ..." + apt-get update + apt-get install -y whiptail + fi } -clear_screen() { - printf '\033[2J\033[H' >/dev/tty +# whiptail liest IMMER direkt vom Terminal. Damit funktioniert auch curl ... | bash. +wt_menu() { + local title="$1" text="$2"; shift 2 + whiptail --title "$title" --menu "$text" 22 84 13 "$@" 3>&1 1>&2 2>&3 &1 1>&2 2>&3 /dev/tty - printf '%s%s Proxmox Guest Updater - %-31s%s\n' "$C_CYAN" "$C_BOLD" "$title" "$C_RESET" >/dev/tty - printf '%s%s============================================================%s\n' "$C_CYAN" "$C_BOLD" "$C_RESET" >/dev/tty - printf 'Host: %s Proxmox: %s\n\n' "$(hostname)" "$(pveversion 2>/dev/null | head -n1)" >/dev/tty -} - -pause_key() { - printf '\n%sWeiter mit Enter ...%s' "$C_DIM" "$C_RESET" >/dev/tty - IFS= read -r _ /dev/tty - - for ((i=0; i<${#items[@]}; i++)); do - if (( i == pos )); then - printf ' %s%s> %-52s%s\n' "$C_INV" "$C_BOLD" "${items[$i]}" "$C_RESET" >/dev/tty - else - printf ' %-52s\n' "${items[$i]}" >/dev/tty - fi - done - - printf '\n%shoch/runter auswählen Enter bestätigen%s\n' "$C_DIM" "$C_RESET" >/dev/tty - - key="" - if ! read_key; then - die "Terminal-Eingabe konnte nicht gelesen werden." - fi - key="$KEY_RESULT" - - case "$key" in - $'\x1b[A') (( pos > 0 )) && ((pos--)) || pos=$((${#items[@]}-1)) ;; - $'\x1b[B') (( pos < ${#items[@]}-1 )) && ((pos++)) || pos=0 ;; - "") MENU_RESULT="$pos"; return 0 ;; - esac - done -} - -confirm_menu() { - local title="$1" text="$2" default="${3:-no}" - local -a opts - if [[ "$default" == "yes" ]]; then - opts=("Ja" "Nein") - else - opts=("Nein" "Ja") - fi - menu_select "$title" "$text" "${opts[@]}" - if [[ "${opts[$MENU_RESULT]}" == "Ja" ]]; then - REPLY="yes" - else - REPLY="no" - fi -} - -input_text() { - local title="$1" prompt="$2" current="$3" regex="${4:-}" error="${5:-Ungültige Eingabe.}" - local value - while true; do - header "$title" - printf '%s\n\n' "$prompt" >/dev/tty - printf 'Aktuell: %s%s%s\n\n' "$C_BOLD" "${current:-keine}" "$C_RESET" >/dev/tty - printf '> ' >/dev/tty - IFS= read -r value /dev/tty - sleep 1 - done -} - -# ============================================================ -# Konfiguration lesen / schreiben -# ============================================================ - -load_existing() { +load_config() { + INSTALLED="no" if [[ -f "$CONFIG" ]]; then INSTALLED="yes" # shellcheck disable=SC1090 source "$CONFIG" fi + [[ -x "$UPDATER" ]] && INSTALLED="yes" UPDATE_HOST="${UPDATE_HOST:-yes}" UPDATE_LXC="${UPDATE_LXC:-yes}" UPDATE_VMS="${UPDATE_VMS:-yes}" UPDATE_STOPPED="${UPDATE_STOPPED:-no}" AUTO_REBOOT_HOST="${AUTO_REBOOT_HOST:-yes}" - EXCLUDE_GUESTS="${EXCLUDE_GUESTS:-}" NOTIFY_ENABLED="${NOTIFY_ENABLED:-no}" NOTIFY_TARGET="${NOTIFY_TARGET:-}" + EXCLUDE_GUESTS="${EXCLUDE_GUESTS:-}" APT_LOCK_TIMEOUT="${APT_LOCK_TIMEOUT:-600}" BACKUP_WAIT_TIMEOUT="${BACKUP_WAIT_TIMEOUT:-7200}" BACKUP_WAIT_INTERVAL="${BACKUP_WAIT_INTERVAL:-60}" LOG_FILE="${LOG_FILE:-$LOGFILE}" - SCHEDULE_TYPE="${SCHEDULE_TYPE:-}" + SCHEDULE_TYPE="${SCHEDULE_TYPE:-weekly}" SCHEDULE_TIME="${SCHEDULE_TIME:-04:00}" SCHEDULE_WEEKDAY="${SCHEDULE_WEEKDAY:-Sun}" SCHEDULE_MONTHDAY="${SCHEDULE_MONTHDAY:-1}" @@ -256,47 +117,29 @@ load_existing() { SCHEDULE_YEAR_DAY="${SCHEDULE_YEAR_DAY:-1}" if [[ -f "$TIMER" ]]; then - ONCALENDAR="$(sed -n 's/^[[:space:]]*OnCalendar=//p' "$TIMER" | head -n1)" - fi - ONCALENDAR="${ONCALENDAR:-Sun *-*-* 04:00:00}" - - # Alte Installation ohne neue SCHEDULE_* Variablen erkennen. - if [[ -z "$SCHEDULE_TYPE" ]]; then - if [[ "$ONCALENDAR" =~ ^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[[:space:]]+\*-\*-\*[[:space:]]+([0-9]{2}:[0-9]{2}):[0-9]{2}$ ]]; then - SCHEDULE_TYPE="weekly" - SCHEDULE_WEEKDAY="${BASH_REMATCH[1]}" - SCHEDULE_TIME="${BASH_REMATCH[2]}" - elif [[ "$ONCALENDAR" =~ ^\*-\*-\*[[:space:]]+([0-9]{2}:[0-9]{2}):[0-9]{2}$ ]]; then - SCHEDULE_TYPE="daily" - SCHEDULE_TIME="${BASH_REMATCH[1]}" - else - SCHEDULE_TYPE="custom" - fi + local old + old="$(sed -n 's/^OnCalendar=//p' "$TIMER" | head -n1)" + [[ -n "$old" ]] && ONCALENDAR="$old" fi } write_config() { - cat > "$CONFIG" <"$CONFIG" </dev/null 2>&1; then - echo "Keine Backup-Daten verfügbar." - return - fi - +backup_jobs() { local json json="$(pvesh get /cluster/backup --output-format json 2>/dev/null || true)" - if [[ -z "$json" || "$json" == "[]" ]]; then - echo "Keine Proxmox-Backup-Jobs eingerichtet." - return - fi - + [[ -n "$json" && "$json" != "[]" ]] || { echo "Keine Proxmox-Autobackups eingerichtet."; return; } BACKUP_JSON="$json" python3 - <<'PY' -import json, os -jobs=json.loads(os.environ["BACKUP_JSON"]) -enabled=[] -for j in jobs: - if str(j.get("enabled","1")).lower() in ("0","false","no"): - continue - enabled.append(j) -if not enabled: - print("Keine aktivierten Proxmox-Backup-Jobs.") -else: - for j in enabled: - jid=j.get("id","?") - sched=j.get("schedule","ohne Zeitplan") - storage=j.get("storage","?") - mode=j.get("mode","snapshot") - print(f"- {sched:<20} Storage: {storage:<12} Modus: {mode} ({jid})") +import json,os +for j in json.loads(os.environ["BACKUP_JSON"]): + if str(j.get("enabled","1")).lower() in ("0","false","no"): continue + print(f"{j.get('schedule','?'):16} Storage: {j.get('storage','?'):12} {j.get('id','?')}") PY } -backup_recommendation() { +backup_conflicts() { local json json="$(pvesh get /cluster/backup --output-format json 2>/dev/null || true)" - [[ -n "$json" && "$json" != "[]" ]] || { echo "Keine Backup-Jobs vorhanden."; return; } - - BACKUP_JSON="$json" python3 - <<'PY' -import json, os, re -jobs=json.loads(os.environ["BACKUP_JSON"]) -times=[] -for j in jobs: - if str(j.get("enabled","1")).lower() in ("0","false","no"): - continue - s=str(j.get("schedule","")) - m=re.search(r'(\d{1,2}):([0-5]\d)$', s) - if m: - times.append((int(m.group(1)),int(m.group(2)))) -if not times: - print("Empfehlung: Update möglichst außerhalb der Backup-Zeiten planen.") -else: - h,m=max(times) - total=(h*60+m+180)%(24*60) - print(f"Empfehlung: mindestens ca. 3 Stunden Abstand zu Backup-Starts einplanen; als Orientierung z. B. {total//60:02d}:{total%60:02d} Uhr.") - print("Hinweis: Die echte Backup-Dauer ist aus dem Zeitplan nicht bekannt.") -PY -} - -# Prüft die gewählte Wiederholung gegen häufige Proxmox-Backup-Zeitpläne. -# Es werden Vorkommen der nächsten 400 Tage erzeugt und +/-2 Stunden verglichen. -check_backup_conflicts() { - local json result - json="$(pvesh get /cluster/backup --output-format json 2>/dev/null || true)" - if [[ -z "$json" || "$json" == "[]" ]]; then - BACKUP_CHECK_STATUS="ok" - BACKUP_CHECK_TEXT="Keine Proxmox-Backup-Jobs vorhanden." - return - fi - - result="$( - BACKUP_JSON="$json" \ - S_TYPE="$SCHEDULE_TYPE" S_TIME="$SCHEDULE_TIME" S_WDAY="$SCHEDULE_WEEKDAY" \ - S_MDAY="$SCHEDULE_MONTHDAY" S_INT="$SCHEDULE_INTERVAL_MONTHS" \ - S_START_MONTH="$SCHEDULE_START_MONTH" S_YMONTH="$SCHEDULE_YEAR_MONTH" \ - S_YDAY="$SCHEDULE_YEAR_DAY" \ - python3 - <<'PY' -import json, os, re -from datetime import datetime, timedelta + [[ -n "$json" && "$json" != "[]" ]] || { echo "OK|Keine Autobackups vorhanden."; return; } + BACKUP_JSON="$json" ST="$SCHEDULE_TYPE" TM="$SCHEDULE_TIME" WD="$SCHEDULE_WEEKDAY" \ + MD="$SCHEDULE_MONTHDAY" IV="$SCHEDULE_INTERVAL_MONTHS" SM="$SCHEDULE_START_MONTH" \ + YM="$SCHEDULE_YEAR_MONTH" YD="$SCHEDULE_YEAR_DAY" python3 - <<'PY' +import json,os,re +from datetime import datetime,timedelta now=datetime.now().replace(second=0,microsecond=0) end=now+timedelta(days=400) -daymap={"mon":0,"tue":1,"wed":2,"thu":3,"fri":4,"sat":5,"sun":6} -stype=os.environ["S_TYPE"] -hh,mm=map(int,os.environ["S_TIME"].split(":")) -uw=daymap.get(os.environ["S_WDAY"].lower()[:3],6) -md=int(os.environ["S_MDAY"]); inter=int(os.environ["S_INT"]) -startm=int(os.environ["S_START_MONTH"]); ym=int(os.environ["S_YMONTH"]); yd=int(os.environ["S_YDAY"]) +dm={"mon":0,"tue":1,"wed":2,"thu":3,"fri":4,"sat":5,"sun":6} +st=os.environ["ST"]; hh,mi=map(int,os.environ["TM"].split(":")) +wd=dm[os.environ["WD"].lower()[:3]] +md=int(os.environ["MD"]); iv=int(os.environ["IV"]); sm=int(os.environ["SM"]) +ym=int(os.environ["YM"]); yd=int(os.environ["YD"]) -def updater_occurs(d): - if stype=="daily": return True - if stype=="weekly": return d.weekday()==uw - if stype=="monthly": return d.day==md - if stype=="interval_months": - months=[] - m=startm - while m<=12: - months.append(m); m+=inter - return d.month in months and d.day==md - if stype=="yearly": return d.month==ym and d.day==yd +def updater(d): + if st=="daily": return True + if st=="weekly": return d.weekday()==wd + if st=="monthly": return d.day==md + if st=="interval": + return d.day==md and d.month in range(sm,13,iv) + if st=="yearly": return d.month==ym and d.day==yd return False -up=[] +ups=[] d=now.replace(hour=0,minute=0) while d<=end: - if updater_occurs(d): - x=d.replace(hour=hh,minute=mm) - if x>=now: up.append(x) + if updater(d): + x=d.replace(hour=hh,minute=mi) + if x>=now: ups.append(x) d+=timedelta(days=1) -def parse_days(expr): - expr=(expr or "").lower().strip() - if not expr or expr=="*": return set(range(7)) +def days(expr): + if not expr: return set(range(7)) out=set() - for p in re.split(r"[,;]",expr): - p=p.strip() + for p in re.split(r"[,;]",expr.lower()): if ".." in p: - a,b=p.split("..",1) - a=daymap.get(a[:3]); b=daymap.get(b[:3]) + a,b=p.split("..",1); a=dm.get(a[:3]); b=dm.get(b[:3]) if a is None or b is None: return None - i=a + x=a while True: - out.add(i) - if i==b: break - i=(i+1)%7 + out.add(x) + if x==b: break + x=(x+1)%7 else: - x=daymap.get(p[:3]) - if x is None: return None + x=dm.get(p[:3]) + if x is None:return None out.add(x) return out -def backup_occurrences(s): - s=s.strip().lower() - # Häufig: "1:00", "01:00", "sun 01:00", "mon..fri 03:00", "sat,sun 02:00" - m=re.fullmatch(r"(?:(?P[a-z.,]+(?:\.\.[a-z]+)?)\s+)?(?P\d{1,2}):(?P\d{2})",s) - if not m: return None - days=parse_days(m.group("days") or "*") - if days is None: return None - bh=int(m.group("h")); bm=int(m.group("m")) - arr=[] - d=now.replace(hour=0,minute=0) - while d<=end: - if d.weekday() in days: - x=d.replace(hour=bh,minute=bm) - if x>=now: arr.append(x) - d+=timedelta(days=1) - return arr - -jobs=json.loads(os.environ["BACKUP_JSON"]) -conf=[] -unknown=[] -for j in jobs: +warn=[]; unknown=[] +for j in json.loads(os.environ["BACKUP_JSON"]): if str(j.get("enabled","1")).lower() in ("0","false","no"): continue - sched=str(j.get("schedule","")).strip() - bo=backup_occurrences(sched) - if bo is None: - unknown.append((j.get("id","?"),sched)) - continue - # linear enough for <=400 days - found=None - for u in up: - for b in bo: - diff=(u-b).total_seconds()/60 - if abs(diff)<=120: - found=(u,b,diff) - break + sc=str(j.get("schedule","")).strip() + m=re.fullmatch(r"(?:(?P[A-Za-z.,]+(?:\.\.[A-Za-z]+)?)\s+)?(?P\d{1,2}):(?P\d{2})",sc) + if not m: + unknown.append(sc); continue + ds=days(m.group("d") or "") + if ds is None: + unknown.append(sc); continue + bh,bm=int(m.group("h")),int(m.group("m")) + d=now.replace(hour=0,minute=0) + bos=[] + while d<=end: + if d.weekday() in ds: + x=d.replace(hour=bh,minute=bm) + if x>=now: bos.append(x) + d+=timedelta(days=1) + hit=None + for u in ups: + for b in bos: + delta=(u-b).total_seconds()/60 + if abs(delta)<=120: + hit=delta; break if b>u+timedelta(hours=2): break - if found: break - if found: - conf.append((j.get("id","?"),sched,found[2])) + if hit is not None: break + if hit is not None: + if abs(hit)<1: rel="gleiche Startzeit" + elif hit>0: rel=f"Updater {int(hit)} Min. nach Backup-Start" + else: rel=f"Updater {int(abs(hit))} Min. vor Backup-Start" + warn.append(f"{sc} ({rel})") -if conf: - print("WARN") - for jid,sched,diff in conf: - if abs(diff)<0.5: rel="gleiche Startzeit" - elif diff>0: rel=f"Updater {int(abs(diff))} Min. nach Backup-Start" - else: rel=f"Updater {int(abs(diff))} Min. vor Backup-Start" - print(f"{sched} | {jid} | {rel}") +if warn: + print("WARN|"+ "\n".join(warn)) elif unknown: - print("UNKNOWN") - for jid,sched in unknown: - print(f"{sched} | {jid}") + print("UNKNOWN|Nicht automatisch auswertbar: " + ", ".join(unknown)) else: - print("OK") + print("OK|Keine Backup-Startzeit innerhalb +/-2 Stunden.") PY - )" - - case "$result" in - WARN*) - BACKUP_CHECK_STATUS="warn" - BACKUP_CHECK_TEXT="$(printf '%s\n' "$result" | tail -n +2)" - ;; - UNKNOWN*) - BACKUP_CHECK_STATUS="unknown" - BACKUP_CHECK_TEXT="$(printf '%s\n' "$result" | tail -n +2)" - ;; - *) - BACKUP_CHECK_STATUS="ok" - BACKUP_CHECK_TEXT="Keine zeitliche Überschneidung innerhalb +/-2 Stunden erkannt." - ;; - esac } -schedule_review() { +choose_time() { + local x while true; do - build_oncalendar - check_backup_conflicts - header "Zeitplan prüfen" - - printf '%sGewählter Zeitplan:%s\n %s\n systemd: %s\n\n' "$C_BOLD" "$C_RESET" "$(schedule_description)" "$ONCALENDAR" >/dev/tty - printf '%sVorhandene Proxmox-Autobackups:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - backup_jobs_text | while IFS= read -r line; do printf ' %s\n' "$line" >/dev/tty; done - printf '\n' >/dev/tty - backup_recommendation | while IFS= read -r line; do printf '%s%s%s\n' "$C_CYAN" "$line" "$C_RESET" >/dev/tty; done - printf '\n' >/dev/tty - - case "$BACKUP_CHECK_STATUS" in - warn) - printf '%s%sWARNUNG: Mögliche Überschneidung mit Autobackup!%s\n' "$C_RED" "$C_BOLD" "$C_RESET" >/dev/tty - while IFS='|' read -r sched jid rel; do - printf ' %s- %s (%s) - %s%s\n' "$C_YELLOW" "$sched" "$jid" "$rel" "$C_RESET" >/dev/tty - done <<< "$BACKUP_CHECK_TEXT" - printf '\n%sDie tatsächliche Backup-Dauer kann länger als das +/-2-Stunden-Fenster sein.%s\n' "$C_YELLOW" "$C_RESET" >/dev/tty - ;; - unknown) - printf '%sEinige Backup-Zeitpläne konnten nicht automatisch bewertet werden:%s\n' "$C_YELLOW" "$C_RESET" >/dev/tty - printf '%s\n' "$BACKUP_CHECK_TEXT" >/dev/tty - ;; - ok) - printf '%sOK %s%s\n' "$C_GREEN" "$BACKUP_CHECK_TEXT" "$C_RESET" >/dev/tty - ;; - esac - - printf '\n%sDer Updater wartet zur Laufzeit zusätzlich auf ein bereits laufendes vzdump-Backup.%s\n' "$C_DIM" "$C_RESET" >/dev/tty - printf '%sBackups innerhalb einer VM/eines LXC sind nicht allgemein erkennbar.%s\n' "$C_DIM" "$C_RESET" >/dev/tty - printf '\n%sEnter = Menü öffnen%s' "$C_DIM" "$C_RESET" >/dev/tty - IFS= read -r _ /dev/tty - printf '%sVorhandene Proxmox-Autobackups:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - backup_jobs_text | while IFS= read -r line; do printf ' %s\n' "$line" >/dev/tty; done - printf '\n' >/dev/tty - backup_recommendation | while IFS= read -r line; do printf '%s%s%s\n' "$C_CYAN" "$line" "$C_RESET" >/dev/tty; done - printf '\n%sEnter = Häufigkeit auswählen%s' "$C_DIM" "$C_RESET" >/dev/tty - IFS= read -r _ /dev/null 2>&1; then - if ! systemd-analyze calendar "$ONCALENDAR" >/dev/null 2>&1; then - header "Zeitplan" - printf '%sUngültiger systemd-Kalenderausdruck.%s\n' "$C_RED" "$C_RESET" >/dev/tty - pause_key - continue - fi + custom) + x="$(wt_input "Zeitplan" "systemd OnCalendar-Ausdruck" "$ONCALENDAR")" || continue + if command -v systemd-analyze >/dev/null 2>&1 && ! systemd-analyze calendar "$x" >/dev/null 2>&1; then + wt_msg "Fehler" "Dieser systemd-Zeitplan ist ungueltig." + continue fi + ONCALENDAR="$x" ;; - 6) return 1 ;; esac - build_oncalendar - schedule_review - case "$?" in - 0) DIRTY="yes"; return 0 ;; - 1) return 1 ;; + set +e + review_schedule + rc=$? + set -e + case "$rc" in + 0) return ;; + 1) return ;; 2) continue ;; esac done } -# ============================================================ -# Einstellungen -# ============================================================ +exclusions_menu() { + local -a args=() + local id name status selected + while read -r id name status _; do + [[ "$id" == VMID ]] && continue + [[ -z "$id" ]] && continue + selected=OFF + [[ " $EXCLUDE_GUESTS " == *" $id "* ]] && selected=ON + args+=("$id" "LXC $name [$status]" "$selected") + done < <(pct list 2>/dev/null || true) -toggle_setting() { - local var="$1" label="$2" current - current="${!var}" - confirm_menu "$label" "$label" "$current" - printf -v "$var" '%s' "$REPLY" - DIRTY="yes" -} + while read -r id name status _; do + [[ "$id" == VMID ]] && continue + [[ -z "$id" ]] && continue + selected=OFF + [[ " $EXCLUDE_GUESTS " == *" $id "* ]] && selected=ON + args+=("$id" "VM $name [$status]" "$selected") + done < <(qm list 2>/dev/null || true) -configure_notifications() { - local json - confirm_menu "Benachrichtigungen" "Nach jedem Update-Lauf eine Proxmox-Benachrichtigung senden?" "$NOTIFY_ENABLED" - NOTIFY_ENABLED="$REPLY" - DIRTY="yes" - - if [[ "$NOTIFY_ENABLED" != "yes" ]]; then - NOTIFY_TARGET="" + if (( ${#args[@]} == 0 )); then + wt_msg "Ausschluesse" "Keine Gaeste gefunden." return fi + local result + result="$(whiptail --title "Ausschluesse" \ + --checklist "Leertaste = markieren/entfernen +Enter = uebernehmen +Esc = zurueck + +Markierte Gaeste werden NICHT automatisch aktualisiert." \ + 24 90 15 "${args[@]}" 3>&1 1>&2 2>&3 /dev/tty - printf 'Benachrichtigungen wurden deaktiviert.\n' >/dev/tty - NOTIFY_ENABLED="no" - NOTIFY_TARGET="" - pause_key - return - fi - - targets+=("<- Zurück") - menu_select "Benachrichtigungen" "Notification-Target auswählen." "${targets[@]}" - if (( MENU_RESULT == ${#targets[@]}-1 )); then return; fi - NOTIFY_TARGET="${targets[$MENU_RESULT]}" + (( ${#args[@]} > 0 )) || { NOTIFY_ENABLED="no"; wt_msg "Benachrichtigungen" "Keine Notification-Targets gefunden."; return; } + args+=(BACK "Zurueck") + choice="$(wt_menu "Benachrichtigungen" "Target auswaehlen" "${args[@]}")" || return + [[ "$choice" == BACK ]] && return + NOTIFY_TARGET="$choice" } -configure_exclusions() { - local -a rows ids names types selected - local line id name type key rest pos=0 i - mapfile -t rows < <( - { - pct list 2>/dev/null | awk 'NR>1 {id=$1; name=$3; if(name=="")name="?"; print id"|LXC|"name}' - qm list 2>/dev/null | awk 'NR>1 {id=$1; name=$2; if(name=="")name="?"; print id"|VM|"name}' - } | sort -n - ) - - if (( ${#rows[@]} == 0 )); then - header "Ausschlüsse" - printf 'Keine Gäste gefunden.\n' >/dev/tty - pause_key - return - fi - - for line in "${rows[@]}"; do - IFS='|' read -r id type name <<< "$line" - ids+=("$id"); types+=("$type"); names+=("$name") - if [[ " $EXCLUDE_GUESTS " == *" $id "* ]]; then selected+=("1"); else selected+=("0"); fi - done - - while true; do - header "Ausschlüsse" - printf 'Mit %sLeertaste%s markieren/entfernen, hoch/runter bewegen.\n\n' "$C_BOLD" "$C_RESET" >/dev/tty - for ((i=0;i<${#ids[@]};i++)); do - local mark="[ ]" - [[ "${selected[$i]}" == "1" ]] && mark="[x]" - if (( i == pos )); then - printf ' %s> %s %-4s %-5s %s%s\n' "$C_INV" "$mark" "${ids[$i]}" "${types[$i]}" "${names[$i]}" "$C_RESET" >/dev/tty - else - printf ' %s %-4s %-5s %s\n' "$mark" "${ids[$i]}" "${types[$i]}" "${names[$i]}" >/dev/tty - fi - done - printf '\n%sLeertaste = umschalten Enter = Weiter B = Zurück C = alle löschen%s\n' "$C_DIM" "$C_RESET" >/dev/tty - - key="" - if ! read_key; then - die "Terminal-Eingabe konnte nicht gelesen werden." - fi - key="$KEY_RESULT" - case "$key" in - $'\x1b[A') (( pos > 0 )) && ((pos--)) || pos=$((${#ids[@]}-1)) ;; - $'\x1b[B') (( pos < ${#ids[@]}-1 )) && ((pos++)) || pos=0 ;; - " ") [[ "${selected[$pos]}" == "1" ]] && selected[$pos]="0" || selected[$pos]="1" ;; - c|C) for ((i=0;i<${#selected[@]};i++)); do selected[$i]="0"; done ;; - b|B) return ;; - "") - EXCLUDE_GUESTS="" - for ((i=0;i<${#ids[@]};i++)); do - if [[ "${selected[$i]}" == "1" ]]; then - EXCLUDE_GUESTS+="${EXCLUDE_GUESTS:+ }${ids[$i]}" - fi - done - DIRTY="yes" - return - ;; - esac - done +advanced_menu() { + local x + x="$(wt_input "Erweitert" "APT-Lock-Wartezeit in Sekunden" "$APT_LOCK_TIMEOUT")" || return + [[ "$x" =~ ^[0-9]+$ ]] && APT_LOCK_TIMEOUT="$x" + x="$(wt_input "Erweitert" "Maximale Wartezeit auf laufendes Proxmox-Backup in Sekunden" "$BACKUP_WAIT_TIMEOUT")" || return + [[ "$x" =~ ^[0-9]+$ ]] && BACKUP_WAIT_TIMEOUT="$x" + x="$(wt_input "Erweitert" "Pruefintervall fuer laufendes Backup in Sekunden" "$BACKUP_WAIT_INTERVAL")" || return + [[ "$x" =~ ^[0-9]+$ ]] && BACKUP_WAIT_INTERVAL="$x" } -settings_menu() { - while true; do - menu_select "Einstellungen" 'Mit Cursor auswählen. Änderungen werden erst bei "Speichern & anwenden" geschrieben.' \ - "Host aktualisieren: $(yn_de "$UPDATE_HOST")" \ - "LXC aktualisieren: $(yn_de "$UPDATE_LXC")" \ - "Linux-VMs aktualisieren: $(yn_de "$UPDATE_VMS")" \ - "Gestoppte Gäste starten: $(yn_de "$UPDATE_STOPPED")" \ - "Host automatisch neu starten: $(yn_de "$AUTO_REBOOT_HOST")" \ - "Benachrichtigungen: $(yn_de "$NOTIFY_ENABLED") ${NOTIFY_TARGET:+($NOTIFY_TARGET)}" \ - "Ausschlüsse: ${EXCLUDE_GUESTS:-keine}" \ - "Zeitplan: $(schedule_description)" \ - "Erweiterte Wartezeiten" \ - "OK Speichern & anwenden" \ - "<- Zurück" - - case "$MENU_RESULT" in - 0) toggle_setting UPDATE_HOST "Host automatisch aktualisieren?" ;; - 1) toggle_setting UPDATE_LXC "LXC automatisch aktualisieren?" ;; - 2) toggle_setting UPDATE_VMS "Linux-VMs automatisch aktualisieren?" ;; - 3) toggle_setting UPDATE_STOPPED "Gestoppte Gäste für Updates automatisch starten?" ;; - 4) toggle_setting AUTO_REBOOT_HOST "Host automatisch neu starten, wenn erforderlich?" ;; - 5) configure_notifications ;; - 6) configure_exclusions ;; - 7) configure_schedule || true ;; - 8) - input_text "Erweiterte Wartezeiten" "APT-Lock-Wartezeit in Sekunden." "$APT_LOCK_TIMEOUT" '^[0-9]+$' - APT_LOCK_TIMEOUT="$INPUT_RESULT" - input_text "Erweiterte Wartezeiten" "Maximale Wartezeit auf laufendes Proxmox-Backup in Sekunden." "$BACKUP_WAIT_TIMEOUT" '^[0-9]+$' - BACKUP_WAIT_TIMEOUT="$INPUT_RESULT" - input_text "Erweiterte Wartezeiten" "Prüfintervall für laufendes Backup in Sekunden." "$BACKUP_WAIT_INTERVAL" '^[0-9]+$' - BACKUP_WAIT_INTERVAL="$INPUT_RESULT" - DIRTY="yes" - ;; - 9) apply_installation; return ;; - 10) - if [[ "$DIRTY" == "yes" ]]; then - confirm_menu "Zurück" "Ungespeicherte Änderungen verwerfen?" "no" - [[ "$REPLY" == "yes" ]] && load_existing && DIRTY="no" && return - else - return - fi - ;; - esac - done -} - -# ============================================================ -# Installation / systemd -# ============================================================ - -download_updater() { - local tmp - tmp="$(mktemp)" - if ! curl -fsSL "${RAW}/updater.sh" -o "$tmp"; then - rm -f "$tmp" - die "updater.sh konnte nicht von Gitea geladen werden." - fi - [[ -s "$tmp" ]] || { rm -f "$tmp"; die "Heruntergeladene updater.sh ist leer."; } - bash -n "$tmp" || { rm -f "$tmp"; die "updater.sh enthält einen Syntaxfehler."; } - install -m 0750 "$tmp" "$UPDATER" - rm -f "$tmp" -} - -write_service_timer() { - build_oncalendar - - cat > "$SERVICE" <<'EOF' +write_units() { + build_calendar + cat >"$SERVICE" <<'EOF' [Unit] Description=Proxmox Guest Updater After=network-online.target pve-cluster.service @@ -943,7 +530,7 @@ IOSchedulingPriority=7 TimeoutStartSec=infinity EOF - cat > "$TIMER" <"$TIMER" </dev/null systemctl restart pve-guest-update.timer } -apply_installation() { - build_oncalendar - check_backup_conflicts - - header "Zusammenfassung" - printf '%-34s %s\n' "Host aktualisieren:" "$(yn_de "$UPDATE_HOST")" >/dev/tty - printf '%-34s %s\n' "LXC aktualisieren:" "$(yn_de "$UPDATE_LXC")" >/dev/tty - printf '%-34s %s\n' "Linux-VMs aktualisieren:" "$(yn_de "$UPDATE_VMS")" >/dev/tty - printf '%-34s %s\n' "Gestoppte Gäste starten:" "$(yn_de "$UPDATE_STOPPED")" >/dev/tty - printf '%-34s %s\n' "Automatischer Host-Neustart:" "$(yn_de "$AUTO_REBOOT_HOST")" >/dev/tty - printf '%-34s %s\n' "Benachrichtigungen:" "$(yn_de "$NOTIFY_ENABLED") ${NOTIFY_TARGET:+($NOTIFY_TARGET)}" >/dev/tty - printf '%-34s %s\n' "Ausschlüsse:" "${EXCLUDE_GUESTS:-keine}" >/dev/tty - printf '%-34s %s\n' "Zeitplan:" "$(schedule_description)" >/dev/tty - printf '%-34s %s\n' "OnCalendar:" "$ONCALENDAR" >/dev/tty - - printf '\n%sAutobackups:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - backup_jobs_text | while IFS= read -r line; do printf ' %s\n' "$line" >/dev/tty; done - - if [[ "$BACKUP_CHECK_STATUS" == "warn" ]]; then - printf '\n%s%sWARNUNG: Der gewählte Zeitplan überschneidet sich möglicherweise mit einem Backup.%s\n' "$C_RED" "$C_BOLD" "$C_RESET" >/dev/tty +download_updater() { + local tmp + tmp="$(mktemp)" + if ! curl -fsSL "$RAW/updater.sh" -o "$tmp"; then + rm -f "$tmp"; wt_msg "Fehler" "updater.sh konnte nicht geladen werden."; return 1 fi - - printf '\n' >/dev/tty - confirm_menu "Zusammenfassung" "Diese Einstellungen jetzt speichern und anwenden?" "yes" - [[ "$REPLY" == "yes" ]] || return - - if [[ "$BACKUP_CHECK_STATUS" == "warn" ]]; then - confirm_menu "Backup-Konflikt" "Trotz erkannter Backup-Überschneidung wirklich anwenden?" "no" - [[ "$REPLY" == "yes" ]] || { configure_schedule || true; return; } + if ! bash -n "$tmp"; then + rm -f "$tmp"; wt_msg "Fehler" "Die geladene updater.sh hat einen Syntaxfehler."; return 1 fi - - header "Installation" - printf 'Lade aktuelle updater.sh ...\n' >/dev/tty - command -v curl >/dev/null 2>&1 || { apt-get update && apt-get install -y curl; } - download_updater - write_config - write_service_timer - INSTALLED="yes" - DIRTY="no" - - printf '\n%sOK Proxmox Guest Updater wurde erfolgreich installiert/aktualisiert.%s\n\n' "$C_GREEN" "$C_RESET" >/dev/tty - printf 'Zeitplan: %s\n' "$(schedule_description)" >/dev/tty - printf 'Nächster Lauf:\n' >/dev/tty - systemctl list-timers pve-guest-update.timer --no-pager 2>/dev/null | tail -n +2 >/dev/tty || true - printf '\nEs wurde kein Update-Lauf gestartet.\n' >/dev/tty - pause_key + install -m 0750 "$tmp" "$UPDATER" + rm -f "$tmp" } -uninstall_manager() { - header "Deinstallation" - printf '%sEntfernt werden:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - printf ' - Updater\n - Konfiguration\n - systemd Service und Timer\n - Updater-Notification-Template/Matcher\n\n' >/dev/tty - printf 'Das Log %s bleibt standardmäßig erhalten.\n' "$LOGFILE" >/dev/tty +save_install() { + local c status detail + build_calendar + c="$(backup_conflicts)"; status="${c%%|*}"; detail="${c#*|}" - confirm_menu "Deinstallation" "Proxmox Guest Updater wirklich vollständig entfernen?" "no" - [[ "$REPLY" == "yes" ]] || return + local summary="Host aktualisieren: $(yn "$UPDATE_HOST") +LXC aktualisieren: $(yn "$UPDATE_LXC") +Linux-VMs aktualisieren: $(yn "$UPDATE_VMS") +Gestoppte Gaeste starten: $(yn "$UPDATE_STOPPED") +Host automatisch neu starten: $(yn "$AUTO_REBOOT_HOST") +Benachrichtigungen: $(yn "$NOTIFY_ENABLED") ${NOTIFY_TARGET:+($NOTIFY_TARGET)} +Ausschluesse: ${EXCLUDE_GUESTS:-keine} +Zeitplan: $(schedule_desc) + +Autobackup-Pruefung: +$detail" + + if [[ "$status" == WARN ]]; then + wt_yesno "WARNUNG - Backup-Konflikt" "$summary + +Trotzdem speichern?" no || return + else + wt_yesno "Speichern & anwenden" "$summary + +Einstellungen jetzt anwenden?" yes || return + fi + + download_updater || return + write_config + write_units + INSTALLED="yes" + wt_msg "Fertig" "Proxmox Guest Updater wurde gespeichert und aktiviert. + +Es wurde KEIN Update-Lauf gestartet. + +Zeitplan: +$(schedule_desc) + +Naechster Lauf: +$(systemctl list-timers pve-guest-update.timer --no-pager 2>/dev/null | tail -n +2 | head -n2)" +} + +settings_menu() { + local choice + while true; do + choice="$(wt_menu "Einstellungen" "Aenderungen werden erst mit 'Speichern & anwenden' geschrieben." \ + host "Host aktualisieren: $(yn "$UPDATE_HOST")" \ + lxc "LXC aktualisieren: $(yn "$UPDATE_LXC")" \ + vm "Linux-VMs aktualisieren: $(yn "$UPDATE_VMS")" \ + stopped "Gestoppte Gaeste starten: $(yn "$UPDATE_STOPPED")" \ + reboot "Host automatisch neu starten: $(yn "$AUTO_REBOOT_HOST")" \ + notify "Benachrichtigungen: $(yn "$NOTIFY_ENABLED") ${NOTIFY_TARGET:+($NOTIFY_TARGET)}" \ + exclude "Ausschluesse: ${EXCLUDE_GUESTS:-keine}" \ + schedule "Zeitplan: $(schedule_desc)" \ + advanced "Erweiterte Wartezeiten" \ + SAVE "Speichern & anwenden" \ + BACK "Zurueck")" || return + + case "$choice" in + host) UPDATE_HOST="$(toggle "$UPDATE_HOST")" ;; + lxc) UPDATE_LXC="$(toggle "$UPDATE_LXC")" ;; + vm) UPDATE_VMS="$(toggle "$UPDATE_VMS")" ;; + stopped) UPDATE_STOPPED="$(toggle "$UPDATE_STOPPED")" ;; + reboot) AUTO_REBOOT_HOST="$(toggle "$AUTO_REBOOT_HOST")" ;; + notify) notifications_menu ;; + exclude) exclusions_menu ;; + schedule) schedule_menu ;; + advanced) advanced_menu ;; + SAVE) save_install; load_config ;; + BACK) return ;; + esac + done +} + +show_status() { + wt_msg "Status" "Installation: $INSTALLED +Host: $(hostname) +Proxmox: $(pveversion | head -n1) + +Zeitplan: +$(schedule_desc) + +Ausschluesse: +${EXCLUDE_GUESTS:-keine} + +Autobackups: +$(backup_jobs) + +Timer: +$(systemctl list-timers pve-guest-update.timer --no-pager 2>/dev/null | tail -n +2 | head -n3) + +Letzte Logzeilen: +$(tail -n 8 "$LOGFILE" 2>/dev/null || echo 'Noch kein Log vorhanden.')" +} + +uninstall_all() { + wt_yesno "Deinstallieren" "Proxmox Guest Updater wirklich entfernen? + +Entfernt werden: +- Updater +- Konfiguration +- systemd Service +- systemd Timer + +Das Log bleibt zunaechst erhalten." no || return systemctl disable --now pve-guest-update.timer >/dev/null 2>&1 || true systemctl stop pve-guest-update.service >/dev/null 2>&1 || true - rm -f "$TIMER" "$SERVICE" "$UPDATER" "$CONFIG" - - rm -f \ - "/etc/pve/notification-templates/default/${NOTIFY_TEMPLATE}-subject.txt.hbs" \ - "/etc/pve/notification-templates/default/${NOTIFY_TEMPLATE}-body.txt.hbs" \ - "/etc/pve/notification-templates/default/${NOTIFY_TEMPLATE}-body.html.hbs" - - pvesh delete "/cluster/notifications/matchers/${NOTIFY_MATCHER}" >/dev/null 2>&1 || true + rm -f "$UPDATER" "$CONFIG" "$SERVICE" "$TIMER" systemctl daemon-reload - systemctl reset-failed pve-guest-update.service >/dev/null 2>&1 || true - - confirm_menu "Deinstallation" "Auch das bisherige Log löschen?" "no" - [[ "$REPLY" == "yes" ]] && rm -f "$LOGFILE" - INSTALLED="no" - header "Deinstallation" - printf '%sOK Proxmox Guest Updater wurde entfernt.%s\n' "$C_GREEN" "$C_RESET" >/dev/tty - pause_key -} -# ============================================================ -# Status / Aktionen -# ============================================================ - -show_status() { - header "Status" - if [[ "$INSTALLED" != "yes" ]]; then - printf '%sNicht installiert.%s\n' "$C_YELLOW" "$C_RESET" >/dev/tty - pause_key - return + if wt_yesno "Log" "Auch $LOGFILE loeschen?" no; then + rm -f "$LOGFILE" fi - - printf '%sInstallation:%s vorhanden\n' "$C_BOLD" "$C_RESET" >/dev/tty - printf 'Updater: %s\n' "$UPDATER" >/dev/tty - printf 'Konfiguration: %s\n' "$CONFIG" >/dev/tty - printf 'Zeitplan: %s\n' "$(schedule_description)" >/dev/tty - printf 'Ausschlüsse: %s\n\n' "${EXCLUDE_GUESTS:-keine}" >/dev/tty - - printf '%sTimer:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - systemctl list-timers pve-guest-update.timer --no-pager 2>/dev/null >/dev/tty || true - - printf '\n%sAutobackups:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - backup_jobs_text | while IFS= read -r line; do printf ' %s\n' "$line" >/dev/tty; done - - printf '\n%sLetzte Logzeilen:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - tail -n 12 "$LOGFILE" 2>/dev/null >/dev/tty || echo " Noch kein Log vorhanden." >/dev/tty - pause_key + wt_msg "Deinstalliert" "Proxmox Guest Updater wurde entfernt." } run_check() { - [[ -x "$UPDATER" ]] || { header "Update-Check"; printf 'Updater ist nicht installiert.\n' >/dev/tty; pause_key; return; } - header "Update-Check" - printf 'Starte nur die Prüfung. Es werden keine Pakete installiert.\n\n' >/dev/tty - "$UPDATER" --check /dev/tty 2>&1 || true - pause_key + [[ -x "$UPDATER" ]] || { wt_msg "Fehler" "Updater ist nicht installiert."; return; } + clear + echo "Proxmox Guest Updater - Check" + echo + "$UPDATER" --check /dev/tty; pause_key; return; } - confirm_menu "Update starten" "Vollständigen Update-Lauf jetzt manuell starten?" "no" - [[ "$REPLY" == "yes" ]] || return - header "Update läuft" - "$UPDATER" /dev/tty 2>&1 || true - pause_key -} - -# ============================================================ -# Hauptmenü -# ============================================================ - -first_install_wizard() { - # Sinnvolle Empfehlung anzeigen, dann Einstellungen. - header "Ersteinrichtung" - printf '%sEmpfohlene Grundeinstellung:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - printf ' - Host, laufende LXC und Linux-VMs aktualisieren\n' >/dev/tty - printf ' - Gestoppte Gäste nicht automatisch starten\n' >/dev/tty - printf ' - Host-Neustart nur bei erfolgreichem Host-Update\n' >/dev/tty - printf ' - Wöchentlicher Lauf außerhalb der Backup-Zeiten\n' >/dev/tty - printf ' - Proxmox-Backup-Schutz bleibt zur Laufzeit aktiv\n\n' >/dev/tty - printf '%sVorhandene Autobackups:%s\n' "$C_BOLD" "$C_RESET" >/dev/tty - backup_jobs_text | while IFS= read -r line; do printf ' %s\n' "$line" >/dev/tty; done - printf '\n' >/dev/tty - backup_recommendation | while IFS= read -r line; do printf '%s%s%s\n' "$C_CYAN" "$line" "$C_RESET" >/dev/tty; done - pause_key - - settings_menu +run_now() { + [[ -x "$UPDATER" ]] || { wt_msg "Fehler" "Updater ist nicht installiert."; return; } + wt_yesno "Update jetzt" "Vollstaendigen Update-Lauf jetzt starten?" no || return + clear + "$UPDATER" Update jetzt starten" \ - "Info Status / Zeitplan / Log" \ - "X Deinstallieren" \ - "Beenden" - case "$MENU_RESULT" in - 0) settings_menu ;; - 1) - header "Updater aktualisieren" - printf 'Lade aktuelle updater.sh aus Gitea ...\n\n' >/dev/tty - download_updater - printf '%sOK updater.sh wurde aktualisiert.%s\n' "$C_GREEN" "$C_RESET" >/dev/tty - pause_key - ;; - 2) run_check ;; - 3) run_update_now ;; - 4) show_status ;; - 5) uninstall_manager ;; - 6) clear_screen; return ;; + load_config + if [[ "$INSTALLED" == yes ]]; then + choice="$(wt_menu "Proxmox Guest Updater" "Installiert - $(schedule_desc)" \ + settings "Einstellungen" \ + refresh "updater.sh aus Gitea aktualisieren" \ + check "Update-Check starten" \ + run "Update jetzt starten" \ + status "Status / Zeitplan / Log" \ + uninstall "Deinstallieren" \ + EXIT "Beenden")" || exit 0 + case "$choice" in + settings) settings_menu ;; + refresh) download_updater && wt_msg "Fertig" "updater.sh wurde aktualisiert." ;; + check) run_check ;; + run) run_now ;; + status) show_status ;; + uninstall) uninstall_all ;; + EXIT) exit 0 ;; esac else - menu_select "Manager" "Status: nicht installiert" \ - "> Installieren / Einrichten" \ - "Info Proxmox-Autobackups anzeigen" \ - "Beenden" - case "$MENU_RESULT" in - 0) first_install_wizard ;; - 1) - header "Autobackups" - backup_jobs_text | while IFS= read -r line; do printf '%s\n' "$line" >/dev/tty; done - printf '\n' >/dev/tty - backup_recommendation | while IFS= read -r line; do printf '%s%s%s\n' "$C_CYAN" "$line" "$C_RESET" >/dev/tty; done - pause_key + choice="$(wt_menu "Proxmox Guest Updater" "Nicht installiert" \ + install "Installieren / Einrichten" \ + backups "Proxmox-Autobackups anzeigen" \ + EXIT "Beenden")" || exit 0 + case "$choice" in + install) + wt_msg "Empfehlung" "Empfohlene Grundeinstellung: + +- Host, laufende LXC und Linux-VMs aktualisieren +- Gestoppte Gaeste nicht automatisch starten +- Woechentlich ausserhalb der Backup-Zeiten +- Host-Neustart nur nach erfolgreichem Host-Update +- Laufender vzdump wird vor Update/Neustart beruecksichtigt + +Vorhandene Autobackups: +$(backup_jobs)" + settings_menu ;; - 2) clear_screen; return ;; + backups) wt_msg "Proxmox-Autobackups" "$(backup_jobs)" ;; + EXIT) exit 0 ;; esac fi done } -# ============================================================ -# Start -# ============================================================ - -need_root_and_pve - -# python3 wird auf Proxmox normalerweise bereits benötigt/vorhanden. -command -v python3 >/dev/null 2>&1 || die "python3 wird für den Manager benötigt." - -load_existing +need_base +load_config main_menu