Files
Proxmox-und-GuestUpdater/install.sh
T
2026-10-04 21:12:36 +02:00

810 lines
24 KiB
Bash

#!/usr/bin/env bash
set -Eeuo pipefail
REPO="https://gitea.vourx.com/sharky/Proxmox-und-GuestUpdater"
RAW="${REPO}/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"
if [[ -t 1 ]]; then
RED=$'\033[1;31m'
YELLOW=$'\033[1;33m'
GREEN=$'\033[1;32m'
BOLD=$'\033[1m'
RESET=$'\033[0m'
else
RED=""
YELLOW=""
GREEN=""
BOLD=""
RESET=""
fi
usage() {
cat <<'EOF'
Proxmox Guest Updater - Installer
Aufruf:
install.sh
install.sh --uninstall
install.sh --clear-excludes
install.sh --help
Optionen:
--uninstall Updater, Timer, Service, Konfiguration und eigene
Notification-Hilfsdateien entfernen.
--clear-excludes Alle Gast-Ausschlüsse aus der vorhandenen Konfiguration entfernen.
--help Diese Hilfe anzeigen.
Bei interaktiver Installation kann die Ausschlussliste zusätzlich mit
"keine", "none" oder "-" vollständig geleert werden.
EOF
}
uninstall_updater() {
echo
echo "Entferne Proxmox Guest Updater ..."
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"
if command -v pvesh >/dev/null 2>&1; then
pvesh delete "/cluster/notifications/matchers/${NOTIFY_MATCHER}" >/dev/null 2>&1 || true
fi
systemctl daemon-reload
systemctl reset-failed pve-guest-update.service >/dev/null 2>&1 || true
echo "Proxmox Guest Updater wurde entfernt."
echo
echo "Das bisherige Log wurde absichtlich behalten:"
echo " $LOGFILE"
echo
echo "Zum Löschen des Logs:"
echo " rm -f $LOGFILE"
}
clear_excludes() {
if [[ ! -f "$CONFIG" ]]; then
echo "FEHLER: Keine vorhandene Installation/Konfiguration gefunden."
exit 1
fi
if grep -q '^EXCLUDE_GUESTS=' "$CONFIG"; then
sed -i 's/^EXCLUDE_GUESTS=.*/EXCLUDE_GUESTS=""/' "$CONFIG"
else
printf '\nEXCLUDE_GUESTS=""\n' >> "$CONFIG"
fi
chmod 600 "$CONFIG"
echo "Alle Gast-Ausschlüsse wurden entfernt."
}
case "${1:-}" in
--uninstall)
if [[ $EUID -ne 0 ]]; then
echo "FEHLER: Bitte als root ausführen."
exit 1
fi
uninstall_updater
exit 0
;;
--clear-excludes)
if [[ $EUID -ne 0 ]]; then
echo "FEHLER: Bitte als root ausführen."
exit 1
fi
clear_excludes
exit 0
;;
--help|-h)
usage
exit 0
;;
"")
;;
*)
echo "Unbekannte Option: $1"
echo
usage
exit 1
;;
esac
# ------------------------------------------------------------
# Grundprüfungen
# ------------------------------------------------------------
if [[ $EUID -ne 0 ]]; then
echo
echo "FEHLER: Bitte als root auf dem Proxmox-Host ausführen."
exit 1
fi
if ! command -v pveversion >/dev/null 2>&1; then
echo
echo "FEHLER: Proxmox VE wurde auf diesem System nicht erkannt."
exit 1
fi
if ! command -v curl >/dev/null 2>&1; then
echo "curl fehlt - wird installiert ..."
apt-get update
apt-get install -y curl
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=""
DAY="7"
DAY_SYSTEMD="Sun"
DAY_NAME="Sonntag"
UPDATE_TIME="04:00"
EXISTING_INSTALL="no"
# ------------------------------------------------------------
# Vorhandene Installation einlesen
# ------------------------------------------------------------
if [[ -f "$CONFIG" ]]; then
EXISTING_INSTALL="yes"
# Vorhandene Konfiguration laden
# shellcheck disable=SC1090
source "$CONFIG"
# Fehlende Werte absichern
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:-}"
# Vorhandenen systemd-Zeitplan auslesen
if [[ -f "$TIMER" ]]; then
ONCALENDAR="$(
sed -n 's/^[[:space:]]*OnCalendar=//p' "$TIMER" |
head -n1
)"
if [[ "$ONCALENDAR" =~ ^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)[[:space:]]+\*-\*-\*[[:space:]]+([0-9]{2}:[0-9]{2}):[0-9]{2}$ ]]; then
DAY_SYSTEMD="${BASH_REMATCH[1]}"
UPDATE_TIME="${BASH_REMATCH[2]}"
case "$DAY_SYSTEMD" in
Mon) DAY="1"; DAY_NAME="Montag" ;;
Tue) DAY="2"; DAY_NAME="Dienstag" ;;
Wed) DAY="3"; DAY_NAME="Mittwoch" ;;
Thu) DAY="4"; DAY_NAME="Donnerstag" ;;
Fri) DAY="5"; DAY_NAME="Freitag" ;;
Sat) DAY="6"; DAY_NAME="Samstag" ;;
Sun) DAY="7"; DAY_NAME="Sonntag" ;;
esac
fi
fi
fi
clear
echo "============================================================"
echo " Proxmox Guest Updater"
echo " Installation"
echo "============================================================"
echo
echo "Host: $(hostname)"
echo "Proxmox: $(pveversion)"
echo
if [[ "$EXISTING_INSTALL" == "yes" ]]; then
echo "Vorhandene Installation erkannt."
echo
echo "Aktuelle Einstellungen:"
echo
echo " Proxmox-Host aktualisieren: $UPDATE_HOST"
echo " LXC automatisch aktualisieren: $UPDATE_LXC"
echo " VMs automatisch aktualisieren: $UPDATE_VMS"
echo " Gestoppte Gäste starten: $UPDATE_STOPPED"
echo " Automatischer Host-Reboot: $AUTO_REBOOT_HOST"
echo " Benachrichtigungen: $NOTIFY_ENABLED"
if [[ "$NOTIFY_ENABLED" == "yes" ]]; then
echo " Notification-Target: ${NOTIFY_TARGET:-nicht gesetzt}"
fi
echo " Zeitplan: $DAY_NAME $UPDATE_TIME Uhr"
echo " Ausgeschlossene Gäste: ${EXCLUDE_GUESTS:-keine}"
echo
echo "Mit Enter wird jeweils die vorhandene Einstellung übernommen."
echo
fi
# ------------------------------------------------------------
# Hilfsfunktionen
# ------------------------------------------------------------
ask_yes_no() {
local prompt="$1"
local current="$2"
local answer
while true; do
if [[ "$current" == "yes" ]]; then
read -r -p "$prompt [J/n]: " answer </dev/tty
answer="${answer:-j}"
else
read -r -p "$prompt [j/N]: " answer </dev/tty
answer="${answer:-n}"
fi
case "${answer,,}" in
j|ja|y|yes)
REPLY="yes"
return
;;
n|nein|no)
REPLY="no"
return
;;
*)
echo "Bitte J oder N eingeben."
;;
esac
done
}
check_backup_schedule_conflicts() {
local backup_json
local result
if ! command -v pvesh >/dev/null 2>&1 || ! command -v python3 >/dev/null 2>&1; then
echo "Backup-Zeitplanprüfung: nicht möglich (pvesh/python3 fehlt)."
return
fi
backup_json="$(pvesh get /cluster/backup --output-format json 2>/dev/null || true)"
if [[ -z "$backup_json" || "$backup_json" == "[]" ]]; then
echo "Backup-Zeitplanprüfung: keine Proxmox-Backup-Jobs gefunden."
return
fi
result="$(
BACKUP_JSON="$backup_json" python3 - "$DAY_SYSTEMD" "$UPDATE_TIME" <<'PY'
import json, os, re, sys
upd_day = sys.argv[1].lower()
upd_time = sys.argv[2]
jobs = json.loads(os.environ.get("BACKUP_JSON", "[]"))
daynum = {"mon":0,"tue":1,"wed":2,"thu":3,"fri":4,"sat":5,"sun":6}
ud = daynum[upd_day[:3]]
uh, um = map(int, upd_time.split(":"))
u = ud*1440 + uh*60 + um
def days_from_expr(expr):
expr = expr.lower().strip()
if not expr or expr in ("*", "daily"):
return set(range(7))
out=set()
for part in re.split(r"[,;]", expr):
part=part.strip()
if ".." in part:
a,b=part.split("..",1)
a=daynum.get(a[:3]); b=daynum.get(b[:3])
if a is None or b is None: continue
i=a
while True:
out.add(i)
if i==b: break
i=(i+1)%7
else:
d=daynum.get(part[:3])
if d is not None: out.add(d)
return out
conflicts=[]
unknown=[]
for job in jobs:
if str(job.get("enabled","1")).lower() in ("0","false","no"):
continue
sched=str(job.get("schedule","")).strip()
if not sched:
continue
# Common PVE forms: "sun 02:00", "mon..fri 03:00", "02:00"
m=re.search(r"(?:(?P<days>[A-Za-z.,]+(?:\.\.[A-Za-z]+)?)\s+)?(?P<h>[0-2]?\d):(?P<m>[0-5]\d)$", sched)
if not m:
unknown.append((job.get("id","?"), sched))
continue
days=days_from_expr(m.group("days") or "*")
bh=int(m.group("h")); bm=int(m.group("m"))
for d in days:
b=d*1440+bh*60+bm
diff=(b-u+7*1440)%(7*1440)
if diff>7*1440//2:
diff-=7*1440
# Potential overlap window: backup starts within 2h before/after updater.
if abs(diff) <= 120:
conflicts.append((job.get("id","?"), sched, diff))
break
if conflicts:
print("WARN")
for jid,sched,diff in conflicts:
if diff == 0:
rel="gleiche Startzeit"
elif diff < 0:
rel=f"{abs(diff)} Min. vor dem Updater"
else:
rel=f"{diff} Min. nach dem Updater"
print(f" - Backup-Job {jid}: {sched} ({rel})")
elif unknown:
print("UNKNOWN")
for jid,sched in unknown:
print(f" - Backup-Job {jid}: {sched}")
else:
print("OK")
PY
)"
case "$result" in
WARN*)
echo
echo "${RED}${BOLD}============================================================${RESET}"
echo "${RED}${BOLD} WARNUNG: BACKUP-ZEITPLAN ÜBERSCHNEIDET SICH!${RESET}"
echo "${RED}${BOLD}============================================================${RESET}"
echo
while IFS= read -r line; do
echo "${YELLOW}${BOLD}${line}${RESET}"
done < <(printf '%s\n' "$result" | tail -n +2)
echo
echo "${YELLOW}Geprüft wird ein Sicherheitsfenster von ±2 Stunden um den Updater-Start.${RESET}"
echo "${YELLOW}Die tatsächliche Backup-Dauer kann Proxmox aus dem Zeitplan nicht vorhersagen.${RESET}"
echo "${YELLOW}Der Updater wartet zur Laufzeit zusätzlich auf ein bereits laufendes vzdump-Backup.${RESET}"
echo
echo "${RED}${BOLD}Der gewählte Update-Zeitpunkt sollte geändert werden.${RESET}"
echo
while true; do
read -r -p "Trotzdem mit diesem Zeitplan fortfahren? [j/N]: " BACKUP_CONFLICT_CONTINUE </dev/tty
case "${BACKUP_CONFLICT_CONTINUE,,}" in
j|ja|y|yes)
echo
echo "${YELLOW}${BOLD}Zeitliche Überschneidung wurde ausdrücklich bestätigt.${RESET}"
break
;;
""|n|nein|no)
echo
echo "${YELLOW}${BOLD}Bitte einen neuen Update-Zeitpunkt wählen.${RESET}"
echo
while true; do
read -r -p "Neuer Wochentag [Mon/Tue/Wed/Thu/Fri/Sat/Sun]: " NEW_DAY </dev/tty
case "${NEW_DAY,,}" in
mon|monday|mo|montag) DAY_SYSTEMD="Mon"; break ;;
tue|tuesday|di|dienstag) DAY_SYSTEMD="Tue"; break ;;
wed|wednesday|mi|mittwoch) DAY_SYSTEMD="Wed"; break ;;
thu|thursday|do|donnerstag) DAY_SYSTEMD="Thu"; break ;;
fri|friday|fr|freitag) DAY_SYSTEMD="Fri"; break ;;
sat|saturday|sa|samstag) DAY_SYSTEMD="Sat"; break ;;
sun|sunday|so|sonntag) DAY_SYSTEMD="Sun"; break ;;
*) echo "Ungültiger Wochentag." ;;
esac
done
while true; do
read -r -p "Neue Uhrzeit [HH:MM]: " NEW_TIME </dev/tty
if [[ "$NEW_TIME" =~ ^([01][0-9]|2[0-3]):[0-5][0-9]$ ]]; then
UPDATE_TIME="$NEW_TIME"
break
fi
echo "Bitte Uhrzeit als HH:MM eingeben, z.B. 04:00."
done
echo
echo "Prüfe den neuen Zeitpunkt erneut ..."
check_backup_schedule_conflicts
return
;;
*)
echo "Bitte j oder n eingeben."
;;
esac
done
;;
UNKNOWN*)
echo "Backup-Zeitplanprüfung: einige Zeitpläne konnten nicht automatisch verglichen werden:"
printf '%s\n' "$result" | tail -n +2
;;
*)
echo "${GREEN}Backup-Zeitplanprüfung: keine Proxmox-Backup-Startzeit innerhalb ±2 Stunden.${RESET}"
;;
esac
echo "Hinweis: Backups, die innerhalb einer VM/eines LXC selbst laufen,"
echo "kann der Proxmox-Host nicht allgemein erkennen."
}
# ------------------------------------------------------------
# Einstellungen abfragen
# ------------------------------------------------------------
ask_yes_no "Proxmox-Host automatisch aktualisieren?" "$UPDATE_HOST"
UPDATE_HOST="$REPLY"
echo
ask_yes_no "Laufende LXC-Container automatisch aktualisieren?" "$UPDATE_LXC"
UPDATE_LXC="$REPLY"
echo
ask_yes_no "Linux-VMs automatisch aktualisieren?" "$UPDATE_VMS"
UPDATE_VMS="$REPLY"
echo
ask_yes_no "Gestoppte Gäste für Updates automatisch starten?" "$UPDATE_STOPPED"
UPDATE_STOPPED="$REPLY"
echo
ask_yes_no "Proxmox automatisch neu starten, wenn erforderlich?" "$AUTO_REBOOT_HOST"
AUTO_REBOOT_HOST="$REPLY"
echo
ask_yes_no "Proxmox-Benachrichtigung nach Update-Läufen senden?" "$NOTIFY_ENABLED"
NOTIFY_ENABLED="$REPLY"
if [[ "$NOTIFY_ENABLED" == "yes" ]]; then
echo
echo "Vorhandene Proxmox-Notification-Targets:"
TARGETS="$(pvesh get /cluster/notifications/targets --output-format json 2>/dev/null |
grep -oE '"name":"[^"]+"' |
sed -E 's/^"name":"([^"]+)"$/\1/' |
sort -u || true)"
if [[ -z "$TARGETS" ]]; then
echo " Keine Targets gefunden."
echo " Benachrichtigungen werden deaktiviert."
NOTIFY_ENABLED="no"
NOTIFY_TARGET=""
else
while IFS= read -r target; do
[[ -n "$target" ]] && echo " - $target"
done <<< "$TARGETS"
# Eingebautes Proxmox-Fallback nicht als bevorzugtes Ziel behandeln.
# Wenn genau ein anderes Target existiert, automatisch verwenden.
CUSTOM_TARGETS="$(printf '%s\n' "$TARGETS" | grep -Fxv 'mail-to-root' || true)"
CUSTOM_COUNT="$(printf '%s\n' "$CUSTOM_TARGETS" | sed '/^$/d' | wc -l)"
if [[ "$CUSTOM_COUNT" -eq 1 ]]; then
NOTIFY_TARGET="$(printf '%s\n' "$CUSTOM_TARGETS" | sed '/^$/d' | head -n1)"
echo
echo "Notification-Target automatisch gewählt: $NOTIFY_TARGET"
elif [[ "$CUSTOM_COUNT" -eq 0 ]]; then
# Nur mail-to-root vorhanden. Das ist ein gültiges Proxmox-Ziel.
NOTIFY_TARGET="mail-to-root"
echo
echo "Notification-Target automatisch gewählt: $NOTIFY_TARGET"
else
echo
echo "Mehrere benutzerdefinierte Targets vorhanden."
while true; do
read -r -p "Notification-Target [${NOTIFY_TARGET:-keins}]: " NEW_TARGET </dev/tty
NEW_TARGET="${NEW_TARGET:-$NOTIFY_TARGET}"
if [[ -z "$NEW_TARGET" ]]; then
echo "Bitte ein vorhandenes Target eingeben."
continue
fi
if printf '%s\n' "$CUSTOM_TARGETS" | grep -Fxq "$NEW_TARGET"; then
NOTIFY_TARGET="$NEW_TARGET"
break
fi
echo "Target '$NEW_TARGET' wurde nicht gefunden."
done
fi
fi
else
NOTIFY_TARGET=""
fi
echo
echo "Automatischer Zeitplan"
echo
echo "1 = Montag"
echo "2 = Dienstag"
echo "3 = Mittwoch"
echo "4 = Donnerstag"
echo "5 = Freitag"
echo "6 = Samstag"
echo "7 = Sonntag"
echo
while true; do
read -r -p "Wochentag [$DAY]: " NEW_DAY </dev/tty
NEW_DAY="${NEW_DAY:-$DAY}"
case "$NEW_DAY" in
1) DAY="1"; DAY_SYSTEMD="Mon"; DAY_NAME="Montag"; break ;;
2) DAY="2"; DAY_SYSTEMD="Tue"; DAY_NAME="Dienstag"; break ;;
3) DAY="3"; DAY_SYSTEMD="Wed"; DAY_NAME="Mittwoch"; break ;;
4) DAY="4"; DAY_SYSTEMD="Thu"; DAY_NAME="Donnerstag"; break ;;
5) DAY="5"; DAY_SYSTEMD="Fri"; DAY_NAME="Freitag"; break ;;
6) DAY="6"; DAY_SYSTEMD="Sat"; DAY_NAME="Samstag"; break ;;
7) DAY="7"; DAY_SYSTEMD="Sun"; DAY_NAME="Sonntag"; break ;;
*) echo "Bitte eine Zahl zwischen 1 und 7 eingeben." ;;
esac
done
while true; do
read -r -p "Uhrzeit [$UPDATE_TIME]: " NEW_TIME </dev/tty
NEW_TIME="${NEW_TIME:-$UPDATE_TIME}"
if [[ "$NEW_TIME" =~ ^([01][0-9]|2[0-3]):[0-5][0-9]$ ]]; then
UPDATE_TIME="$NEW_TIME"
break
fi
echo "Bitte Uhrzeit als HH:MM eingeben, z.B. 04:00."
done
echo
echo "Prüfe Proxmox-Backup-Zeitpläne ..."
check_backup_schedule_conflicts
echo
echo "Gäste können vom automatischen Update ausgeschlossen werden."
echo
echo "Ausgeschlossene Gäste (VM-/CT-IDs, durch Leerzeichen getrennt):"
echo
if [[ -n "$EXCLUDE_GUESTS" ]]; then
echo "Aktuell ausgeschlossen: $EXCLUDE_GUESTS"
else
echo "Aktuell ausgeschlossen: keine"
fi
echo
echo " Enter = bisherige Ausschlüsse beibehalten"
echo " keine = alle Ausschlüsse entfernen"
echo " none = alle Ausschlüsse entfernen"
echo " - = alle Ausschlüsse entfernen"
echo " 101 107 = genau diese Gäste ausschließen"
echo
echo "Nach der Installation können alle Ausschlüsse auch direkt entfernt werden:"
echo " curl -fsSL ${RAW}/install.sh | bash -s -- --clear-excludes"
echo
read -r -p "Ausgeschlossene Gäste [${EXCLUDE_GUESTS:-keine}]: " NEW_EXCLUDES </dev/tty
if [[ -z "$NEW_EXCLUDES" ]]; then
:
elif [[ "${NEW_EXCLUDES,,}" == "keine" || "${NEW_EXCLUDES,,}" == "none" || "$NEW_EXCLUDES" == "-" ]]; then
EXCLUDE_GUESTS=""
else
EXCLUDE_GUESTS="$NEW_EXCLUDES"
fi
# ------------------------------------------------------------
# Zusammenfassung
# ------------------------------------------------------------
clear
echo "============================================================"
echo " Zusammenfassung"
echo "============================================================"
echo
echo "Proxmox-Host aktualisieren: $UPDATE_HOST"
echo "LXC automatisch aktualisieren: $UPDATE_LXC"
echo "VMs automatisch aktualisieren: $UPDATE_VMS"
echo "Gestoppte Gäste starten: $UPDATE_STOPPED"
echo "Automatischer Host-Reboot: $AUTO_REBOOT_HOST"
echo "Benachrichtigungen: $NOTIFY_ENABLED"
if [[ "$NOTIFY_ENABLED" == "yes" ]]; then
echo "Notification-Target: $NOTIFY_TARGET"
fi
echo "Zeitplan: $DAY_NAME $UPDATE_TIME Uhr"
echo "Ausgeschlossene Gäste: ${EXCLUDE_GUESTS:-keine}"
echo
echo "============================================================"
echo
if [[ "$EXISTING_INSTALL" == "yes" ]]; then
ask_yes_no "Vorhandene Installation mit diesen Einstellungen aktualisieren?" "yes"
else
ask_yes_no "Installation mit diesen Einstellungen starten?" "yes"
fi
if [[ "$REPLY" != "yes" ]]; then
echo
echo "Installation abgebrochen."
exit 0
fi
echo
if [[ "$EXISTING_INSTALL" == "yes" ]]; then
echo "Aktualisiere Proxmox Guest Updater ..."
else
echo "Installiere Proxmox Guest Updater ..."
fi
echo
# ------------------------------------------------------------
# updater.sh laden
# ------------------------------------------------------------
TMP_UPDATER="$(mktemp)"
trap 'rm -f "$TMP_UPDATER"' EXIT
echo "Lade updater.sh ..."
if ! curl -fsSL "${RAW}/updater.sh" -o "$TMP_UPDATER"; then
echo
echo "FEHLER: updater.sh konnte nicht von Gitea geladen werden."
exit 1
fi
if [[ ! -s "$TMP_UPDATER" ]]; then
echo
echo "FEHLER: Die heruntergeladene updater.sh ist leer."
exit 1
fi
if ! bash -n "$TMP_UPDATER"; then
echo
echo "FEHLER: updater.sh enthält einen Bash-Syntaxfehler."
exit 1
fi
install -m 0750 "$TMP_UPDATER" "$UPDATER"
# ------------------------------------------------------------
# Konfiguration
# ------------------------------------------------------------
cat > "$CONFIG" <<EOF
# Proxmox Guest Updater
# Automatisch durch install.sh erzeugt
UPDATE_HOST="$UPDATE_HOST"
UPDATE_LXC="$UPDATE_LXC"
UPDATE_VMS="$UPDATE_VMS"
UPDATE_STOPPED="$UPDATE_STOPPED"
AUTO_REBOOT_HOST="$AUTO_REBOOT_HOST"
NOTIFY_ENABLED="$NOTIFY_ENABLED"
NOTIFY_TARGET="$NOTIFY_TARGET"
EXCLUDE_GUESTS="$EXCLUDE_GUESTS"
APT_LOCK_TIMEOUT="600"
BACKUP_WAIT_TIMEOUT="7200"
BACKUP_WAIT_INTERVAL="60"
LOG_FILE="/var/log/pve-guest-update.log"
EOF
chmod 600 "$CONFIG"
# ------------------------------------------------------------
# systemd Service
# ------------------------------------------------------------
cat > "$SERVICE" <<'EOF'
[Unit]
Description=Proxmox Guest Updater
After=network-online.target pve-cluster.service
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/pve-guest-update
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7
TimeoutStartSec=infinity
EOF
# ------------------------------------------------------------
# systemd Timer
# ------------------------------------------------------------
cat > "$TIMER" <<EOF
[Unit]
Description=Proxmox Guest Updater - automatischer Zeitplan
[Timer]
OnCalendar=$DAY_SYSTEMD *-*-* $UPDATE_TIME:00
Persistent=true
RandomizedDelaySec=0
Unit=pve-guest-update.service
[Install]
WantedBy=timers.target
EOF
systemctl daemon-reload
systemctl enable --now pve-guest-update.timer
systemctl restart pve-guest-update.timer
echo
echo "============================================================"
if [[ "$EXISTING_INSTALL" == "yes" ]]; then
echo " Installation erfolgreich aktualisiert"
else
echo " Installation erfolgreich abgeschlossen"
fi
echo "============================================================"
echo
echo "Updater:"
echo " $UPDATER"
echo
echo "Konfiguration:"
echo " $CONFIG"
echo
echo "Log:"
echo " /var/log/pve-guest-update.log"
echo
echo "Zeitplan:"
echo " $DAY_NAME um $UPDATE_TIME Uhr"
echo
echo "Ausgeschlossene Gäste:"
echo " ${EXCLUDE_GUESTS:-keine}"
echo
echo "Es wurde KEIN Update durchgeführt."
echo
echo "Verwaltung:"
echo " Ausschlüsse komplett leeren:"
echo " curl -fsSL ${RAW}/install.sh | bash -s -- --clear-excludes"
echo
echo " Updater vollständig entfernen:"
echo " curl -fsSL ${RAW}/install.sh | bash -s -- --uninstall"
echo
echo "Aktiver Timer:"
systemctl list-timers pve-guest-update.timer --no-pager
echo