#!/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" # ------------------------------------------------------------ # 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 clear echo "============================================================" echo " Proxmox Guest Updater" echo " Installation" echo "============================================================" echo echo "Host: $(hostname)" echo "Proxmox: $(pveversion)" echo # ------------------------------------------------------------ # Hilfsfunktionen # ------------------------------------------------------------ ask_yes_no() { local prompt="$1" local default="$2" local answer while true; do if [[ "$default" == "yes" ]]; then read -r -p "$prompt [J/n]: " answer answer="${answer:-j}" else read -r -p "$prompt [j/N]: " answer 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 } # ------------------------------------------------------------ # Einstellungen abfragen # ------------------------------------------------------------ ask_yes_no "Proxmox-Host automatisch aktualisieren?" "yes" UPDATE_HOST="$REPLY" echo ask_yes_no "Laufende LXC-Container automatisch aktualisieren?" "yes" UPDATE_LXC="$REPLY" echo ask_yes_no "Linux-VMs automatisch aktualisieren?" "yes" UPDATE_VMS="$REPLY" echo ask_yes_no "Gestoppte Gäste für Updates automatisch starten?" "no" UPDATE_STOPPED="$REPLY" echo ask_yes_no "Proxmox automatisch neu starten, wenn erforderlich?" "yes" AUTO_REBOOT_HOST="$REPLY" 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 [7]: " DAY DAY="${DAY:-7}" case "$DAY" in 1) DAY_SYSTEMD="Mon"; DAY_NAME="Montag"; break ;; 2) DAY_SYSTEMD="Tue"; DAY_NAME="Dienstag"; break ;; 3) DAY_SYSTEMD="Wed"; DAY_NAME="Mittwoch"; break ;; 4) DAY_SYSTEMD="Thu"; DAY_NAME="Donnerstag"; break ;; 5) DAY_SYSTEMD="Fri"; DAY_NAME="Freitag"; break ;; 6) DAY_SYSTEMD="Sat"; DAY_NAME="Samstag"; break ;; 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 [04:00]: " UPDATE_TIME UPDATE_TIME="${UPDATE_TIME:-04:00}" if [[ "$UPDATE_TIME" =~ ^([01][0-9]|2[0-3]):[0-5][0-9]$ ]]; then break fi echo "Bitte Uhrzeit als HH:MM eingeben, z.B. 04:00." done echo echo "Gäste können vom automatischen Update ausgeschlossen werden." echo "Mehrere VM-/CT-IDs mit Leerzeichen trennen." echo "Beispiel: 101 105 200" echo read -r -p "Ausgeschlossene Gäste [keine]: " EXCLUDE_GUESTS # ------------------------------------------------------------ # 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 "Zeitplan: $DAY_NAME $UPDATE_TIME Uhr" echo "Ausgeschlossene Gäste: ${EXCLUDE_GUESTS:-keine}" echo echo "============================================================" echo ask_yes_no "Installation mit diesen Einstellungen starten?" "yes" if [[ "$REPLY" != "yes" ]]; then echo echo "Installation abgebrochen." exit 0 fi echo echo "Installiere Proxmox Guest Updater ..." 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 "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" < "$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" <