#!/usr/bin/env bash # ============================================================================= # SmartCrop26 Deploy Script # Builds and deploys the SPA to Apache on Ubuntu # ============================================================================= # # Apache config for /var/www/html/smartcrop26: # # # Options -Indexes +FollowSymLinks # AllowOverride None # FallbackResource /smartcrop26/index.html # # # Or create /var/www/html/smartcrop26/.htaccess: # RewriteEngine On # RewriteBase /smartcrop26/ # RewriteCond %{REQUEST_FILENAME} !-f # RewriteCond %{REQUEST_FILENAME} !-d # RewriteRule . /smartcrop26/index.html [L] # # ============================================================================= set -euo pipefail REPO_DIR=/opt/smartcrop26 WEB_DIR=/var/www/html/smartcrop26 ENV_FILE="$REPO_DIR/.env" if [ ! -f "$ENV_FILE" ]; then echo "ERROR: $ENV_FILE not found. Create it with required VITE_ variables." exit 1 fi echo "==> Pulling latest code..." cd "$REPO_DIR" git pull echo "==> Installing dependencies..." npm ci echo "==> Building production bundle..." npm run build echo "==> Deploying to $WEB_DIR..." sudo mkdir -p "$WEB_DIR" sudo rm -rf "${WEB_DIR:?}"/* sudo cp -r dist/* "$WEB_DIR/" echo "==> Setting permissions..." sudo chown -R www-data:www-data "$WEB_DIR" echo "==> Deploy complete at $(date '+%Y-%m-%d %H:%M:%S')"