#!/bin/bash
# Quick SSH key setup for Proxmox deployment

PROXMOX_HOST="${PROXMOX_HOST:-192.168.11.10}"

echo "Setting up SSH key for Proxmox host..."

# Check if key exists
if [ ! -f ~/.ssh/id_ed25519 ]; then
    echo "Generating SSH key..."
    ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N "" -C "proxmox-deployment"
fi

echo "Copying SSH key to Proxmox host..."
echo "You will be prompted for the root password:"
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@"${PROXMOX_HOST}"

echo ""
echo "Testing SSH connection..."
if ssh -o BatchMode=yes -o ConnectTimeout=5 root@"${PROXMOX_HOST}" "echo 'SSH key working'" 2>/dev/null; then
    echo "✅ SSH key setup successful!"
    echo "You can now run deployment without password prompts:"
    echo "  ./scripts/deploy-to-proxmox-host.sh"
else
    echo "⚠️  SSH key may not be working. You'll need to enter password during deployment."
fi
