#!/bin/bash # # Deploy Archipelago code to the HP ProDesk target # # Usage: # ./scripts/deploy-to-target.sh # Sync and rebuild # ./scripts/deploy-to-target.sh --quick # Sync only, no rebuild # ./scripts/deploy-to-target.sh --live # Deploy to live system # set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" PROJECT_DIR="$(dirname "$SCRIPT_DIR")" # Configuration TARGET_HOST="${ARCHIPELAGO_TARGET:-archipelago@192.168.1.228}" TARGET_DIR="/home/archipelago/archy" echo "╔════════════════════════════════════════════════════════════════╗" echo "║ Deploying to Archipelago Target ║" echo "╚════════════════════════════════════════════════════════════════╝" echo "" echo "Target: $TARGET_HOST" echo "" # Parse arguments QUICK=false LIVE=false for arg in "$@"; do case $arg in --quick) QUICK=true ;; --live) LIVE=true ;; esac done # Sync code echo "📦 Syncing code..." rsync -avz --delete \ --exclude 'node_modules' \ --exclude 'target' \ --exclude 'dist' \ --exclude '.git' \ --exclude 'image-recipe/build' \ --exclude 'image-recipe/results' \ "$PROJECT_DIR/" "$TARGET_HOST:$TARGET_DIR/" if [ "$QUICK" = true ]; then echo "" echo "✅ Quick sync complete!" exit 0 fi # Build on target echo "" echo "🔨 Building on target..." # Frontend echo " Building frontend..." ssh "$TARGET_HOST" "cd $TARGET_DIR/neode-ui && npm install --silent && npm run build" 2>&1 | sed 's/^/ /' # Backend (if Rust is installed) if ssh "$TARGET_HOST" "source ~/.cargo/env 2>/dev/null && command -v cargo" >/dev/null 2>&1; then echo " Building backend..." ssh "$TARGET_HOST" "source ~/.cargo/env && cd $TARGET_DIR/core && cargo build --release 2>&1" | tail -10 | sed 's/^/ /' else echo " ⚠️ Rust not installed on target, skipping backend build" fi if [ "$LIVE" = true ]; then echo "" echo "🚀 Deploying to live system..." # Deploy backend (check if binary exists) if ssh "$TARGET_HOST" "[ -f $TARGET_DIR/core/target/release/archipelago ]" 2>/dev/null; then echo " Deploying backend binary..." # Stop service first so we can overwrite the binary ssh "$TARGET_HOST" "sudo systemctl stop archipelago" ssh "$TARGET_HOST" "sudo cp $TARGET_DIR/core/target/release/archipelago /usr/local/bin/" fi # Deploy frontend echo " Deploying frontend..." ssh "$TARGET_HOST" "sudo rm -rf /opt/archipelago/web-ui/*" ssh "$TARGET_HOST" "sudo cp -r $TARGET_DIR/web/dist/neode-ui/* /opt/archipelago/web-ui/" ssh "$TARGET_HOST" "sudo chown -R 1000:1000 /opt/archipelago/web-ui" # Restart services echo " Restarting services..." ssh "$TARGET_HOST" "sudo systemctl start archipelago && sudo systemctl restart nginx" echo "" echo "✅ Deployed to live system!" echo " Backend: $(ssh "$TARGET_HOST" 'sudo systemctl is-active archipelago')" echo " Web UI: http://$(echo $TARGET_HOST | cut -d@ -f2)" else echo "" echo "✅ Build complete!" echo "" echo "To test frontend dev server:" echo " ssh $TARGET_HOST" echo " cd ~/archy/neode-ui && npm run dev -- --host 0.0.0.0" echo " Then open: http://$(echo $TARGET_HOST | cut -d@ -f2):5173" echo "" echo "To deploy to live system:" echo " ./scripts/deploy-to-target.sh --live" fi