#!/bin/bash
# Manual copy script with diagnostic information
# This script provides the exact commands to copy the script manually

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Source .env file
if [ -f "$PROJECT_ROOT/.env" ]; then
    set -a
    source "$PROJECT_ROOT/.env"
    set +a
fi

# Get password (with fallback)
PROXMOX_PASS="${PROXMOX_ROOT_PASS:-L@kers2010}"

# Get hostnames/IPs
PROXMOX_1_HOST="${PROXMOX_1_HOST:-192.168.11.10}"
PROXMOX_2_HOST="${PROXMOX_2_HOST:-192.168.11.11}"

SCRIPT_NAME="complete-vm-100-guest-agent-check.sh"
SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_NAME"

echo "=========================================="
echo "Manual Copy Instructions"
echo "=========================================="
echo ""
echo "Script: $SCRIPT_NAME"
echo "Source: $SCRIPT_PATH"
echo ""

# Check if script exists
if [ ! -f "$SCRIPT_PATH" ]; then
    echo "❌ Error: Script not found: $SCRIPT_PATH"
    exit 1
fi

echo "Copy and paste these commands to copy the script:"
echo ""
echo "=========================================="
echo "For ml110-01 (Site 1):"
echo "=========================================="
echo ""
echo "# Copy script to ml110-01"
echo "sshpass -p '$PROXMOX_PASS' scp -o StrictHostKeyChecking=no \\"
echo "  $SCRIPT_PATH \\"
echo "  root@$PROXMOX_1_HOST:/usr/local/bin/$SCRIPT_NAME"
echo ""
echo "# Make executable"
echo "sshpass -p '$PROXMOX_PASS' ssh -o StrictHostKeyChecking=no root@$PROXMOX_1_HOST \\"
echo "  'chmod +x /usr/local/bin/$SCRIPT_NAME'"
echo ""
echo "# Verify"
echo "sshpass -p '$PROXMOX_PASS' ssh -o StrictHostKeyChecking=no root@$PROXMOX_1_HOST \\"
echo "  '/usr/local/bin/$SCRIPT_NAME'"
echo ""
echo "=========================================="
echo "For r630-01 (Site 2):"
echo "=========================================="
echo ""
echo "# Copy script to r630-01"
echo "sshpass -p '$PROXMOX_PASS' scp -o StrictHostKeyChecking=no \\"
echo "  $SCRIPT_PATH \\"
echo "  root@$PROXMOX_2_HOST:/usr/local/bin/$SCRIPT_NAME"
echo ""
echo "# Make executable"
echo "sshpass -p '$PROXMOX_PASS' ssh -o StrictHostKeyChecking=no root@$PROXMOX_2_HOST \\"
echo "  'chmod +x /usr/local/bin/$SCRIPT_NAME'"
echo ""
echo "# Verify"
echo "sshpass -p '$PROXMOX_PASS' ssh -o StrictHostKeyChecking=no root@$PROXMOX_2_HOST \\"
echo "  '/usr/local/bin/$SCRIPT_NAME'"
echo ""
echo "=========================================="
echo "Alternative: Copy script content directly"
echo "=========================================="
echo ""
echo "If SCP doesn't work, you can copy the script content:"
echo ""
echo "1. Display the script:"
echo "   cat $SCRIPT_PATH"
echo ""
echo "2. SSH to the node and create the file:"
echo "   sshpass -p '$PROXMOX_PASS' ssh -o StrictHostKeyChecking=no root@$PROXMOX_1_HOST"
echo ""
echo "3. Then on the Proxmox node, create the file:"
echo "   cat > /usr/local/bin/$SCRIPT_NAME << 'SCRIPT_EOF'"
echo "   [paste script content here]"
echo "   SCRIPT_EOF"
echo "   chmod +x /usr/local/bin/$SCRIPT_NAME"
echo ""


