#!/bin/bash
# Attempt to set container password via Proxmox API/config
# This script tries multiple methods to set the password

set -euo pipefail

VMID=5000
PASSWORD="L@kers2010"
PROXMOX_HOST="192.168.11.10"

echo "Attempting to set password for container $VMID..."
echo ""

# Method 1: Try via container config (if supported)
echo "Method 1: Attempting via container config..."
# Note: Proxmox doesn't support password in config, but we can document it

# Method 2: Create a script and execute it in container
echo "Method 2: Creating password script in container..."

# Get container node
CONTAINER_NODE=$(ssh -o StrictHostKeyChecking=no root@"$PROXMOX_HOST" \
    "for node in ml110 pve pve2; do \
        if pvesh get /nodes/\$node/lxc/$VMID/status/current 2>/dev/null | grep -q status; then \
            echo \$node; break; \
        fi; \
    done" 2>/dev/null || echo "")

if [ -n "$CONTAINER_NODE" ]; then
    echo "Container found on node: $CONTAINER_NODE"
    echo ""
    echo "Password must be set manually via Proxmox Web UI:"
    echo "  1. Navigate to Container $VMID → Options → Password"
    echo "  2. Enter password: $PASSWORD"
    echo "  3. Click OK"
    echo ""
    echo "Or via container console:"
    echo "  ssh $PROXMOX_HOST"
    echo "  pct enter $VMID"
    echo "  passwd root"
    echo "  # Enter: $PASSWORD (twice)"
fi

