create_pve-mgnt-lxc_v2.sh aktualisiert
This commit is contained in:
@@ -1,40 +1,26 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# =====================================================
|
# =====================================================
|
||||||
# Proxmox VE: Debian 13 LXC automatisch erstellen
|
# Proxmox VE: Debian 13 LXC automatisch erstellen
|
||||||
# Hostname: <Host>-MGNT
|
|
||||||
# Unprivilegiert
|
|
||||||
# Automatisches Debian 13 Template
|
|
||||||
# WebUI-Konsole funktioniert
|
|
||||||
# Autostart aktiviert
|
|
||||||
# Dialog-basierte GUI + Statusfenster
|
|
||||||
# =====================================================
|
# =====================================================
|
||||||
|
|
||||||
# ---- Farben / Layout ----
|
# Root-Check
|
||||||
BOLD="\033[1m"
|
|
||||||
GREEN="\033[32m"
|
|
||||||
CYAN="\033[36m"
|
|
||||||
RED="\033[31m"
|
|
||||||
RESET="\033[0m"
|
|
||||||
INDENT=" "
|
|
||||||
|
|
||||||
# ---- Root Check ----
|
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
dialog --msgbox "Bitte als Root ausführen!" 8 40
|
dialog --msgbox "Bitte als Root ausführen!" 8 40
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ---- Root Passwort ----
|
# Root-Passwort abfragen
|
||||||
ROOTPASS=$(dialog --title "Root Passwort" --passwordbox "Root-Passwort für den LXC:" 8 40 3>&1 1>&2 2>&3 3>&-)
|
ROOTPASS=$(dialog --title "Root Passwort" --passwordbox "Root-Passwort für LXC:" 8 40 3>&1 1>&2 2>&3 3>&-)
|
||||||
clear
|
clear
|
||||||
|
|
||||||
# ---- Hostname & VMID ----
|
# Hostname & VMID
|
||||||
HOSTNAME="$(hostname)-MGNT"
|
HOSTNAME="$(hostname)-MGNT"
|
||||||
VMID=300
|
VMID=300
|
||||||
while pct status $VMID &>/dev/null; do ((VMID++)); done
|
while pct status $VMID &>/dev/null; do ((VMID++)); done
|
||||||
|
|
||||||
dialog --msgbox "Hostname: $HOSTNAME\nNächste freie VMID: $VMID" 10 50
|
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}')
|
mapfile -t STORAGES < <(pvesm status --content rootdir | awk 'NR>1 {print $1}')
|
||||||
STORAGE_CHOICES=()
|
STORAGE_CHOICES=()
|
||||||
for i in "${!STORAGES[@]}"; do
|
for i in "${!STORAGES[@]}"; do
|
||||||
@@ -47,7 +33,7 @@ STORAGE_INDEX=$(dialog --title "Storage Auswahl" --radiolist \
|
|||||||
STORAGE="${STORAGES[$STORAGE_INDEX]}"
|
STORAGE="${STORAGES[$STORAGE_INDEX]}"
|
||||||
clear
|
clear
|
||||||
|
|
||||||
# ---- VMBR Auswahl ----
|
# Bridge Auswahl
|
||||||
mapfile -t BRIDGES < <(grep -Po '^auto \K.*' /etc/network/interfaces)
|
mapfile -t BRIDGES < <(grep -Po '^auto \K.*' /etc/network/interfaces)
|
||||||
BRIDGE_CHOICES=()
|
BRIDGE_CHOICES=()
|
||||||
for i in "${!BRIDGES[@]}"; do
|
for i in "${!BRIDGES[@]}"; do
|
||||||
@@ -60,7 +46,7 @@ BRIDGE_INDEX=$(dialog --title "Bridge Auswahl" --radiolist \
|
|||||||
BRIDGE="${BRIDGES[$BRIDGE_INDEX]}"
|
BRIDGE="${BRIDGES[$BRIDGE_INDEX]}"
|
||||||
clear
|
clear
|
||||||
|
|
||||||
# ---- IP / Netzwerk ----
|
# Netzwerk / Ressourcen
|
||||||
IP="10.60.10.2/24"
|
IP="10.60.10.2/24"
|
||||||
GATEWAY="10.60.10.1"
|
GATEWAY="10.60.10.1"
|
||||||
CORES=1
|
CORES=1
|
||||||
@@ -68,35 +54,23 @@ MEMORY=512
|
|||||||
SWAP=0
|
SWAP=0
|
||||||
ROOTFS_SIZE=8
|
ROOTFS_SIZE=8
|
||||||
|
|
||||||
# ---- Template automatisch wählen ----
|
# Template
|
||||||
dialog --infobox "Suche aktuelles Debian 13 Template..." 5 50
|
dialog --infobox "Suche aktuelles Debian 13 Template..." 5 50
|
||||||
pveam update
|
pveam update
|
||||||
TEMPLATE_NAME=$(pveam available | awk '/debian-13-standard_.*_amd64\.tar\.zst/ {print $2}' | tail -n1)
|
TEMPLATE_NAME=$(pveam available | awk '/debian-13-standard_.*_amd64\.tar\.zst/ {print $2}' | tail -n1)
|
||||||
|
|
||||||
if [[ -z "$TEMPLATE_NAME" ]]; then
|
if [[ -z "$TEMPLATE_NAME" ]]; then
|
||||||
dialog --msgbox "Kein Debian 13 Template gefunden!" 8 50
|
dialog --msgbox "Kein Debian 13 Template gefunden!" 8 50
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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"
|
TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE_NAME"
|
||||||
if [[ ! -f "$TEMPLATE_PATH" ]]; then
|
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
|
fi
|
||||||
|
|
||||||
# ---- LXC erstellen ----
|
# ---- LXC erstellen ----
|
||||||
|
dialog --title "LXC erstellen" --infobox "Erstelle unprivilegierten LXC $HOSTNAME..." 5 60
|
||||||
CREATE_CMD="pct create $VMID local:vztmpl/$TEMPLATE_NAME \
|
CREATE_CMD="pct create $VMID local:vztmpl/$TEMPLATE_NAME \
|
||||||
--hostname $HOSTNAME \
|
--hostname $HOSTNAME \
|
||||||
--cores $CORES \
|
--cores $CORES \
|
||||||
@@ -110,28 +84,28 @@ if [[ -n "$ROOTPASS" ]]; then
|
|||||||
CREATE_CMD="$CREATE_CMD --password $ROOTPASS"
|
CREATE_CMD="$CREATE_CMD --password $ROOTPASS"
|
||||||
fi
|
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"
|
CONF_FILE="/etc/pve/lxc/$VMID.conf"
|
||||||
echo "lxc.tty.max = 2" >> "$CONF_FILE"
|
echo "lxc.tty.max = 2" >> "$CONF_FILE"
|
||||||
echo "lxc.pty.max = 2" >> "$CONF_FILE"
|
echo "lxc.pty.max = 2" >> "$CONF_FILE"
|
||||||
echo "features: nesting=1,keyctl=1" >> "$CONF_FILE"
|
echo "features: nesting=1,keyctl=1" >> "$CONF_FILE"
|
||||||
|
|
||||||
# ---- Autostart aktivieren ----
|
# Autostart aktivieren
|
||||||
run_with_progress "pct set $VMID --onboot 1"
|
pct set $VMID --onboot 1 2>&1 | dialog --title "Autostart setzen" --progressbox 10 60
|
||||||
|
|
||||||
# ---- Container starten ----
|
# Container starten
|
||||||
run_with_progress "pct start $VMID"
|
pct start $VMID 2>&1 | dialog --title "LXC starten" --progressbox 15 60
|
||||||
|
|
||||||
# ---- Software im LXC installieren ----
|
# Software installieren
|
||||||
run_with_progress "pct exec $VMID -- bash -c '
|
pct exec $VMID -- bash -c "
|
||||||
apt update &&
|
apt update &&
|
||||||
apt install -y curl sudo &&
|
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 &&
|
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
|
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
|
clear
|
||||||
rm -f "$LOGFILE"
|
|
||||||
Reference in New Issue
Block a user