#!/usr/bin/env bash set -Eeuo pipefail # Bootstrap/downloader for the Proxmox configuration backup/recovery tools. # Before publishing, set DEFAULT_RAW_BASE to your GitHub raw repository URL, # ideally pinned to a release/tag for production use. umask 077 DEFAULT_RAW_BASE="https://raw.githubusercontent.com/GATACA-Systemhaus/proxmox-dr-tools/main" RAW_BASE="${1:-${PVE_DR_RAW_BASE:-$DEFAULT_RAW_BASE}}" INSTALL_DIR="${PVE_DR_INSTALL_DIR:-/root}" log() { printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*"; } fail() { log "ERROR: $*" >&2; exit 1; } [[ $EUID -eq 0 ]] || fail "Run this script as root." command -v curl >/dev/null 2>&1 || fail "curl is required. Install it with: apt update && apt install -y curl" resolve_raw_base() { local input if [[ "$RAW_BASE" == *"CHANGE-ME"* ]]; then echo echo "GitHub raw base URL is not configured in this bootstrap yet." echo "Example: https://raw.githubusercontent.com/ORG/REPO/v1.0" read -r -p "Raw base URL: " input [[ "$input" == https://raw.githubusercontent.com/* ]] || fail "Please enter a raw.githubusercontent.com URL." RAW_BASE="${input%/}" fi } download_one() { local file="$1" target tmp target="$INSTALL_DIR/$file" tmp="${target}.download.$$" mkdir -p "$INSTALL_DIR" log "Downloading $file" curl -fL --retry 2 --connect-timeout 15 "$RAW_BASE/$file" -o "$tmp" [[ -s "$tmp" ]] || { rm -f "$tmp"; fail "Downloaded file is empty: $file"; } if [[ "$file" == *.sh ]]; then sed -i 's/\r$//' "$tmp" bash -n "$tmp" || { rm -f "$tmp"; fail "Syntax check failed for $file"; } fi install -o root -g root -m 0700 "$tmp" "$target" rm -f "$tmp" echo " [OK] $target" } maybe_run() { local file="$1" answer read -r -p "Run $file now? [y/N]: " answer case "$answer" in y|Y|j|J|yes|YES|ja|JA) exec "$INSTALL_DIR/$file" ;; esac } resolve_raw_base while true; do echo echo "============================================================" echo " Proxmox Config Backup / Recovery Tools" echo "============================================================" echo "Quelle: $RAW_BASE" echo echo " 1) Backup-Script herunterladen/aktualisieren" echo " 2) Restore-Script herunterladen/aktualisieren" echo " 3) Scheduler herunterladen/aktualisieren" echo " 4) Alle drei Tools herunterladen/aktualisieren" echo " 5) Backup-Script herunterladen und starten" echo " 6) Restore-Script herunterladen und starten" echo " 7) Scheduler herunterladen und starten" echo " 8) Restore-Script herunterladen und Precheck (--check) starten" echo " 0) Beenden" read -r -p "Auswahl [0-8]: " choice case "$choice" in 1) download_one pve-config-backup.sh ;; 2) download_one pve-config-restore.sh ;; 3) download_one pve-config-backup-scheduler.sh ;; 4) download_one pve-config-backup.sh download_one pve-config-restore.sh download_one pve-config-backup-scheduler.sh ;; 5) download_one pve-config-backup.sh; exec "$INSTALL_DIR/pve-config-backup.sh" ;; 6) download_one pve-config-restore.sh; exec "$INSTALL_DIR/pve-config-restore.sh" ;; 7) download_one pve-config-backup-scheduler.sh; exec "$INSTALL_DIR/pve-config-backup-scheduler.sh" ;; 8) download_one pve-config-restore.sh; exec "$INSTALL_DIR/pve-config-restore.sh" --check ;; 0) exit 0 ;; *) echo "Ungueltige Auswahl." ;; esac done