#!/bin/bash
set -e
FRONTEND_DIR="$(dirname "$0")/frontend"
REMOTE="root@192.168.85.20"
WEB_ROOT="/var/www/html"

echo "Building..."
cd "$FRONTEND_DIR" && npm run build

echo "Deploying..."
ssh "$REMOTE" "rm -rf ${WEB_ROOT}/assets/*"
scp -r dist/* "$REMOTE:${WEB_ROOT}/"
ssh "$REMOTE" "chmod -R 755 ${WEB_ROOT}/assets && chmod 644 ${WEB_ROOT}/assets/* ${WEB_ROOT}/index.html ${WEB_ROOT}/vite.svg 2>/dev/null; nginx -s reload"
echo "Done."
