#!/usr/bin/env bash # Create NPMplus Mifos container (VMID 10237) on r630-02 at 192.168.11.171. # Tunnel points to this NPMplus; NPMplus proxies mifos.d-bis.org to VMID 5800 (192.168.11.85:80). # See: docs/04-configuration/MIFOS_NPMPLUS_TUNNEL.md set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" source "$PROJECT_ROOT/config/ip-addresses.conf" 2>/dev/null || true [ -f "$PROJECT_ROOT/.env" ] && set +u && source "$PROJECT_ROOT/.env" 2>/dev/null || true && set -u VMID="${NPMPLUS_MIFOS_VMID:-10237}" HOST="${PROXMOX_HOST_R630_02:-192.168.11.12}" IP="${IP_NPMPLUS_MIFOS:-192.168.11.171}" TEMPLATE="${TEMPLATE:-local:vztmpl/debian-12-standard_12.12-1_amd64.tar.zst}" STORAGE="${STORAGE_R630_02_NPMPLUS_MIFOS:-thin3}" NETWORK="${NETWORK:-vmbr0}" GATEWAY="${NETWORK_GATEWAY:-192.168.11.1}" log() { echo "[INFO] $1"; } success() { echo "[OK] $1"; } warn() { echo "[WARN] $1"; } error() { echo "[ERROR] $1"; exit 1; } log "Creating NPMplus Mifos container (VMID $VMID) on $HOST at $IP (tunnel origin to 5800)..." exists() { ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@"$HOST" "pct list 2>/dev/null | grep -q '^[[:space:]]*$VMID[[:space:]]' && echo yes || echo no" 2>/dev/null || echo "no" } if [[ "$(exists)" == "yes" ]]; then warn "Container $VMID already exists. Skipping creation." success "Next: install NPMplus, add proxy mifos.d-bis.org to http://192.168.11.85:80, install cloudflared. See docs/04-configuration/MIFOS_NPMPLUS_TUNNEL.md" exit 0 fi if ! ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 root@"$HOST" "echo ok" >/dev/null 2>&1; then error "Cannot SSH to $HOST" fi TEMPLATE_ALT=$(ssh -o StrictHostKeyChecking=no root@"$HOST" "pveam list local 2>/dev/null | grep -E 'debian|ubuntu' | head -1 | awk '{print \$1}'" || echo "") if [ -n "$TEMPLATE_ALT" ] && ! echo "$TEMPLATE" | grep -q "debian-12-standard"; then TEMPLATE="local:$TEMPLATE_ALT" log "Using template: $TEMPLATE" fi log "Creating container..." ssh -o StrictHostKeyChecking=no root@"$HOST" "pct create $VMID $TEMPLATE \ --hostname npmplus-mifos \ --memory 2048 \ --cores 2 \ --rootfs $STORAGE:20 \ --net0 name=eth0,bridge=$NETWORK,ip=$IP/24,gw=$GATEWAY \ --description 'NPMplus Mifos - tunnel origin; proxies mifos.d-bis.org to 5800' \ --start 1 \ --onboot 1 \ --unprivileged 1 \ --features nesting=1" 2>&1 || error "Failed to create container" sleep 5 if [[ "$(exists)" == "yes" ]]; then success "Container $VMID created and started at $IP" log "Next: Install NPMplus, add proxy mifos.d-bis.org to http://${MIFOS_IP:-192.168.11.85}:80, install cloudflared. See docs/04-configuration/MIFOS_NPMPLUS_TUNNEL.md" else error "Container creation may have failed. Check: ssh root@$HOST 'pct list'" fi