From 12193270cd0c9f9e36a2ba242f208eb7978fe3bc Mon Sep 17 00:00:00 2001 From: "manuel.maier" Date: Tue, 27 Jan 2026 23:32:08 +0100 Subject: [PATCH] create_pve-mgnt-lxc_v2.sh aktualisiert --- create_pve-mgnt-lxc_v2.sh | 138 +++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 69 deletions(-) diff --git a/create_pve-mgnt-lxc_v2.sh b/create_pve-mgnt-lxc_v2.sh index b8669e8..7906345 100644 --- a/create_pve-mgnt-lxc_v2.sh +++ b/create_pve-mgnt-lxc_v2.sh @@ -6,10 +6,10 @@ # Automatisches Debian 13 Template # WebUI-Konsole funktioniert # Autostart aktiviert -# Dialog-basiert +# Dialog-basierte GUI + Statusfenster # ===================================================== -# ---- Farben für Terminal-Ausgabe ---- +# ---- Farben / Layout ---- BOLD="\033[1m" GREEN="\033[32m" CYAN="\033[36m" @@ -19,119 +19,119 @@ INDENT=" " # ---- Root Check ---- if [[ $EUID -ne 0 ]]; then - echo -e "${RED}${INDENT}Bitte als Root ausführen!${RESET}" + dialog --msgbox "Bitte als Root ausführen!" 8 40 exit 1 fi -# ---- Dynamischer Hostname ---- +# ---- Root Passwort ---- +ROOTPASS=$(dialog --title "Root Passwort" --passwordbox "Root-Passwort für den LXC:" 8 40 3>&1 1>&2 2>&3 3>&-) +clear + +# ---- Hostname & VMID ---- HOSTNAME="$(hostname)-MGNT" +VMID=300 +while pct status $VMID &>/dev/null; do ((VMID++)); done -# ---- Nächste freie VMID ab 300 ---- -MIN_VMID=300 -VMID=$MIN_VMID -while pct status $VMID &>/dev/null; do - ((VMID++)) -done +dialog --msgbox "Hostname: $HOSTNAME\nNächste freie VMID: $VMID" 10 50 -# ---- Storage auswählen ---- +# ---- Storage Auswahl ---- mapfile -t STORAGES < <(pvesm status --content rootdir | awk 'NR>1 {print $1}') - -if [[ ${#STORAGES[@]} -eq 0 ]]; then - echo -e "${RED}${INDENT}Kein geeigneter Storage gefunden!${RESET}" - exit 1 -fi - -STORAGE_OPTIONS=() +STORAGE_CHOICES=() for i in "${!STORAGES[@]}"; do - STORAGE_OPTIONS+=("$i" "${STORAGES[$i]}") + STORAGE_CHOICES+=("$i" "${STORAGES[$i]}" "off") done -STORAGE_INDEX=$(dialog --clear --stdout \ - --title "LXC RootFS Storage wählen" \ - --menu "Wähle den Storage für den LXC RootFS" 15 50 5 \ - "${STORAGE_OPTIONS[@]}") - -if [ $? -ne 0 ]; then - echo -e "${RED}${INDENT}Abgebrochen${RESET}" - clear - exit 1 -fi +STORAGE_INDEX=$(dialog --title "Storage Auswahl" --radiolist \ +"Welcher Storage für RootFS?" 15 50 5 \ +"${STORAGE_CHOICES[@]}" 3>&1 1>&2 2>&3 3>&-) STORAGE="${STORAGES[$STORAGE_INDEX]}" +clear -# ---- Root-Passwort abfragen ---- -ROOTPASS=$(dialog --clear --stdout --title "Root-Passwort für LXC" \ - --insecure --passwordbox "Gib ein Root-Passwort für den LXC ein:" 10 50) -if [ $? -ne 0 ]; then - echo -e "${RED}${INDENT}Abgebrochen${RESET}" - clear - exit 1 -fi +# ---- VMBR Auswahl ---- +mapfile -t BRIDGES < <(grep -Po '^auto \K.*' /etc/network/interfaces) +BRIDGE_CHOICES=() +for i in "${!BRIDGES[@]}"; do + BRIDGE_CHOICES+=("$i" "${BRIDGES[$i]}" "off") +done -# ---- LXC Settings ---- +BRIDGE_INDEX=$(dialog --title "Bridge Auswahl" --radiolist \ +"Welche Bridge soll der LXC nutzen?" 15 50 5 \ +"${BRIDGE_CHOICES[@]}" 3>&1 1>&2 2>&3 3>&-) +BRIDGE="${BRIDGES[$BRIDGE_INDEX]}" +clear + +# ---- IP / Netzwerk ---- IP="10.60.10.2/24" GATEWAY="10.60.10.1" CORES=1 MEMORY=512 SWAP=0 ROOTFS_SIZE=8 -BRIDGE="xx_vmbrmgt" # ---- Template automatisch wählen ---- -pveam update >/dev/null +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!" 10 50 - clear + 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 - dialog --infobox "Template $TEMPLATE_NAME wird heruntergeladen..." 5 50 - pveam download local "$TEMPLATE_NAME" + run_with_progress "pveam download local $TEMPLATE_NAME" fi -# ---- Container erstellen ---- -dialog --infobox "Erstelle unprivilegierten LXC $HOSTNAME (VMID: $VMID)..." 5 50 - +# ---- LXC erstellen ---- CREATE_CMD="pct create $VMID local:vztmpl/$TEMPLATE_NAME \ ---hostname $HOSTNAME \ ---cores $CORES \ ---memory $MEMORY \ ---swap $SWAP \ ---rootfs $STORAGE:$ROOTFS_SIZE \ ---net0 name=eth0,bridge=$BRIDGE,ip=$IP,gw=$GATEWAY,type=veth \ ---unprivileged 1 \ ---password $ROOTPASS" + --hostname $HOSTNAME \ + --cores $CORES \ + --memory $MEMORY \ + --swap $SWAP \ + --rootfs $STORAGE:$ROOTFS_SIZE \ + --net0 name=eth0,bridge=$BRIDGE,ip=$IP,gw=$GATEWAY,type=veth \ + --unprivileged 1" -eval $CREATE_CMD || { - dialog --msgbox "Fehler beim Erstellen des LXC!" 10 50 - clear - exit 1 -} +if [[ -n "$ROOTPASS" ]]; then + CREATE_CMD="$CREATE_CMD --password $ROOTPASS" +fi -# ---- WebUI-Konsole aktivieren ---- +run_with_progress "$CREATE_CMD" + +# ---- WebUI-Konsole aktivieren (modern) ---- 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 ---- -pct set $VMID --onboot 1 +run_with_progress "pct set $VMID --onboot 1" # ---- Container starten ---- -dialog --infobox "Starte LXC..." 5 50 -pct start $VMID +run_with_progress "pct start $VMID" -# ---- Newt installieren ---- -dialog --infobox "Installiere Newt-PVE-Mgnt im LXC..." 5 50 -pct exec $VMID -- bash -c " +# ---- Software im LXC installieren ---- +run_with_progress "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 -" +'" -dialog --msgbox "✔ Unprivilegierter LXC $HOSTNAME (VMID $VMID) erstellt, gestartet und Autostart aktiviert!" 10 50 +dialog --msgbox "✔ Unprivilegierter LXC $HOSTNAME (VMID $VMID) erstellt, gestartet und Autostart aktiviert!" 8 60 clear +rm -f "$LOGFILE" \ No newline at end of file