#!/usr/bin/env bash
# Copy entire smom-dbis-138-proxmox directory to Proxmox host
# This copies everything needed for deployment

# Suppress locale warnings
export LC_ALL=C
export LANG=C

HOST="${1:-192.168.11.10}"
USER="${2:-root}"
REMOTE_DIR="${3:-/opt/smom-dbis-138-proxmox}"

echo "Copying entire project to $USER@$HOST:$REMOTE_DIR"

# Test connection (suppress locale warnings)
if ! ssh -o BatchMode=yes -o ConnectTimeout=5 "$USER@$HOST" "export LC_ALL=C; export LANG=C; exit" 2>/dev/null; then
    echo "❌ Cannot connect to $HOST"
    echo "   Ensure SSH key is set up: ssh-copy-id $USER@$HOST"
    exit 1
fi

# Create remote directory
ssh "$USER@$HOST" "mkdir -p $REMOTE_DIR"

# Copy entire smom-dbis-138-proxmox directory
echo "Copying files (this may take a few minutes)..."
rsync -avz --exclude='.git' --exclude='*.log' \
    smom-dbis-138-proxmox/ \
    "$USER@$HOST:$REMOTE_DIR/" || {
    echo "⚠ rsync not available, using scp..."
    scp -r smom-dbis-138-proxmox/* "$USER@$HOST:$REMOTE_DIR/"
}

# Make all scripts executable
ssh "$USER@$HOST" "find $REMOTE_DIR -name '*.sh' -exec chmod +x {} \;"

echo "✅ All files copied to $REMOTE_DIR"
echo ""
echo "SSH to Proxmox host and run:"
echo "  ssh $USER@$HOST"
echo "  cd $REMOTE_DIR"
echo "  sudo ./scripts/deployment/deploy-phased.sh --source-project /path/to/smom-dbis-138"

