#!/usr/bin/env bash # container-anlegen.sh — den Container für den Homelab-Teil auf dem Proxmox-PC anlegen (Phase 3). # # Läuft am PC (Git-Bash) und spricht per SSH mit dem Proxmox-Host (Alias „pve“, Schlüssel id_lucy_infra). # Legt EINEN unprivilegierten Debian-13-Container an: 1 Kern, 1 GB RAM, 4 GB Platte, DHCP, Autostart. # Etikett „mc2“ — bewusst NICHT community-script/watcher: Der Orchestrator aktualisiert sich nicht selbst. # # Nutzung: bash deploy/homelab/container-anlegen.sh [vmid] # Danach: bash deploy/homelab/ausrollen.sh set -euo pipefail PVE="${MC_PVE:-pve}" VORLAGE="${MC_VORLAGE:-local:vztmpl/debian-13-standard_13.1-2_amd64.tar.zst}" VMID="${1:-$(ssh -o BatchMode=yes "$PVE" pvesh get /cluster/nextid)}" echo "Lege Container $VMID (homelab-orchestrator) auf $PVE an …" ssh -o BatchMode=yes "$PVE" "pct create $VMID $VORLAGE \ --hostname homelab-orchestrator --description 'Homelab Orchestrator – Homelab-Teil (MC2, Rolle homelab)' \ --cores 1 --memory 1024 --swap 512 --rootfs local-lvm:4 \ --net0 name=eth0,bridge=vmbr0,ip=dhcp --unprivileged 1 --features nesting=1 \ --onboot 1 --tags mc2 --timezone Europe/Berlin --start 1" # Auf die IP warten (DHCP), dann den SSH-Schlüssel des PCs und der Box eintragen (wie bei allen Gästen). for _ in $(seq 1 30); do IP="$(ssh -o BatchMode=yes "$PVE" "pct exec $VMID -- hostname -I 2>/dev/null | awk '{print \$1}'" || true)" [ -n "$IP" ] && break sleep 2 done [ -n "${IP:-}" ] || { echo "✗ Container $VMID hat keine IP bekommen."; exit 1; } ssh -o BatchMode=yes "$PVE" "pct exec $VMID -- bash -c 'apt-get update -q && apt-get install -y -q openssh-server && \ mkdir -p /root/.ssh && chmod 700 /root/.ssh' && cat /root/.ssh/authorized_keys | pct exec $VMID -- bash -c \ 'cat >> /root/.ssh/authorized_keys && chmod 600 /root/.ssh/authorized_keys && systemctl enable --now ssh'" echo "✅ Container $VMID läuft unter $IP. Weiter mit: bash deploy/homelab/ausrollen.sh $IP"