#!/bin/bash
# Create tar archive and transfer to server

SERVER_USER="admin_n"
SERVER_IP="192.168.43.201"  # Replace with your actual server IP

echo "📦 Creating workspace archive..."

# Get current directory
CURRENT_DIR="$(pwd)"
echo "📁 Creating archive from: ${CURRENT_DIR}"

# Create tar archive excluding unnecessary files
tar -czf infoscreen-workspace.tar.gz \
  --exclude='node_modules' \
  --exclude='__pycache__' \
  --exclude='.git' \
  --exclude='*.log' \
  --exclude='.vscode' \
  --exclude='dashboard/.vite' \
  --exclude='server/received_screenshots' \
  --exclude='server/screenshots' \
  --exclude='mosquitto/data' \
  --exclude='mosquitto/log' \
  .

echo "📤 Transferring archive to server..."

# Transfer archive
scp infoscreen-workspace.tar.gz ${SERVER_USER}@${SERVER_IP}:~/

echo "📥 Extracting on server..."

# Extract on server
ssh ${SERVER_USER}@${SERVER_IP} "
  mkdir -p ~/infoscreen_2025 &&
  cd ~/infoscreen_2025 &&
  tar -xzf ~/infoscreen-workspace.tar.gz &&
  rm ~/infoscreen-workspace.tar.gz
"

# Clean up local archive
rm infoscreen-workspace.tar.gz

echo "✅ Transfer and extraction complete!"
echo ""
echo "📋 Next steps:"
echo "1. SSH to server: ssh ${SERVER_USER}@${SERVER_IP}"
echo "2. Go to project: cd infoscreen_2025"
echo "3. Run setup: ./setup-dev-environment.sh"
