From 4fdf84c99bb4f8d513709b018f948f2c8f876653 Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Tue, 27 Jan 2026 23:35:06 +0100 Subject: [PATCH] create_pve-mgnt-lxc_v2.sh aktualisiert --- create_pve-mgnt-lxc_v2.sh | 70 ++++++++++++--------------------------- 1 file changed, 22 insertions(+), 48 deletions(-) diff --git a/create_pve-mgnt-lxc_v2.sh b/create_pve-mgnt-lxc_v2.sh index 7906345..28dd974 100644 --- a/create_pve-mgnt-lxc_v2.sh +++ b/create_pve-mgnt-lxc_v2.sh @@ -1,40 +1,26 @@ #!/bin/bash # ===================================================== # Proxmox VE: Debian 13 LXC automatisch erstellen -# Hostname: -MGNT -# Unprivilegiert -# Automatisches Debian 13 Template -# WebUI-Konsole funktioniert -# Autostart aktiviert -# Dialog-basierte GUI + Statusfenster # ===================================================== -# ---- Farben / Layout ---- -BOLD="\033[1m" -GREEN="\033[32m" -CYAN="\033[36m" -RED="\033[31m" -RESET="\033[0m" -INDENT=" " - -# ---- Root Check ---- +# Root-Check if [[ $EUID -ne 0 ]]; then dialog --msgbox "Bitte als Root ausführen!" 8 40 exit 1 fi -# ---- Root Passwort ---- -ROOTPASS=$(dialog --title "Root Passwort" --passwordbox "Root-Passwort für den LXC:" 8 40 3>&1 1>&2 2>&3 3>&-) +# Root-Passwort abfragen +ROOTPASS=$(dialog --title "Root Passwort" --passwordbox "Root-Passwort für LXC:" 8 40 3>&1 1>&2 2>&3 3>&-) clear -# ---- Hostname & VMID ---- +# Hostname & VMID HOSTNAME="$(hostname)-MGNT" VMID=300 while pct status $VMID &>/dev/null; do ((VMID++)); done dialog --msgbox "Hostname: $HOSTNAME\nNächste freie VMID: $VMID" 10 50 -# ---- Storage Auswahl ---- +# Storage Auswahl mapfile -t STORAGES < <(pvesm status --content rootdir | awk 'NR>1 {print $1}') STORAGE_CHOICES=() for i in "${!STORAGES[@]}"; do @@ -47,7 +33,7 @@ STORAGE_INDEX=$(dialog --title "Storage Auswahl" --radiolist \ STORAGE="${STORAGES[$STORAGE_INDEX]}" clear -# ---- VMBR Auswahl ---- +# Bridge Auswahl mapfile -t BRIDGES < <(grep -Po '^auto \K.*' /etc/network/interfaces) BRIDGE_CHOICES=() for i in "${!BRIDGES[@]}"; do @@ -60,7 +46,7 @@ BRIDGE_INDEX=$(dialog --title "Bridge Auswahl" --radiolist \ BRIDGE="${BRIDGES[$BRIDGE_INDEX]}" clear -# ---- IP / Netzwerk ---- +# Netzwerk / Ressourcen IP="10.60.10.2/24" GATEWAY="10.60.10.1" CORES=1 @@ -68,35 +54,23 @@ MEMORY=512 SWAP=0 ROOTFS_SIZE=8 -# ---- Template automatisch wählen ---- +# Template dialog --infobox "Suche aktuelles Debian 13 Template..." 5 50 pveam update TEMPLATE_NAME=$(pveam available | awk '/debian-13-standard_.*_amd64\.tar\.zst/ {print $2}' | tail -n1) - if [[ -z "$TEMPLATE_NAME" ]]; then dialog --msgbox "Kein Debian 13 Template gefunden!" 8 50 exit 1 fi -# ---- Temp-Log für Status ---- -LOGFILE=$(mktemp) - -run_with_progress() { - local CMD="$1" - echo -e ">>> $CMD" >> "$LOGFILE" - bash -c "$CMD" >> "$LOGFILE" 2>&1 & - PID=$! - dialog --title "LXC Setup: $HOSTNAME" --progressbox "$LOGFILE" 20 80 - wait $PID -} - -# ---- Template prüfen / herunterladen ---- TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE_NAME" if [[ ! -f "$TEMPLATE_PATH" ]]; then - run_with_progress "pveam download local $TEMPLATE_NAME" + dialog --title "Template herunterladen" --infobox "Lade $TEMPLATE_NAME..." 5 60 + pveam download local "$TEMPLATE_NAME" | tee /tmp/lxc_template.log fi # ---- LXC erstellen ---- +dialog --title "LXC erstellen" --infobox "Erstelle unprivilegierten LXC $HOSTNAME..." 5 60 CREATE_CMD="pct create $VMID local:vztmpl/$TEMPLATE_NAME \ --hostname $HOSTNAME \ --cores $CORES \ @@ -110,28 +84,28 @@ if [[ -n "$ROOTPASS" ]]; then CREATE_CMD="$CREATE_CMD --password $ROOTPASS" fi -run_with_progress "$CREATE_CMD" +# Direkt ausführen + Output ins Dialog-Fenster +$CREATE_CMD 2>&1 | dialog --title "LXC erstellen (VMID $VMID)" --progressbox 20 80 -# ---- WebUI-Konsole aktivieren (modern) ---- +# WebUI-Konsole CONF_FILE="/etc/pve/lxc/$VMID.conf" echo "lxc.tty.max = 2" >> "$CONF_FILE" echo "lxc.pty.max = 2" >> "$CONF_FILE" echo "features: nesting=1,keyctl=1" >> "$CONF_FILE" -# ---- Autostart aktivieren ---- -run_with_progress "pct set $VMID --onboot 1" +# Autostart aktivieren +pct set $VMID --onboot 1 2>&1 | dialog --title "Autostart setzen" --progressbox 10 60 -# ---- Container starten ---- -run_with_progress "pct start $VMID" +# Container starten +pct start $VMID 2>&1 | dialog --title "LXC starten" --progressbox 15 60 -# ---- Software im LXC installieren ---- -run_with_progress "pct exec $VMID -- bash -c ' +# Software installieren +pct exec $VMID -- bash -c " apt update && apt install -y curl sudo && curl -fsSL https://gitea.vmd55888.de/manuel.maier/update-install-newt/raw/branch/main/install_newt_v2.sh -o install_newt_v2.sh && bash ./install_newt_v2.sh --install -'" +" 2>&1 | dialog --title "Software installieren" --progressbox 20 80 -dialog --msgbox "✔ Unprivilegierter LXC $HOSTNAME (VMID $VMID) erstellt, gestartet und Autostart aktiviert!" 8 60 +dialog --msgbox "✔ LXC $HOSTNAME (VMID $VMID) erstellt, gestartet und Autostart aktiviert!" 8 60 clear -rm -f "$LOGFILE" \ No newline at end of file