#!/bin/bash
# Run this ON THE SERVER after deploy-local.sh has uploaded deploy.tar.gz:
#   source ~/nodevenv/tspeed_website/20/bin/activate
#   cd ~/tspeed_website
#   bash scripts/deploy-server.sh

set -e  # stop on first error

cd ~/tspeed_website

if [ ! -f deploy.tar.gz ]; then
  echo "deploy.tar.gz not found in ~/tspeed_website — run deploy-local.sh from your laptop first."
  exit 1
fi

echo "==> Removing old .next..."
rm -rf .next

echo "==> Extracting new build..."
tar -xzf deploy.tar.gz
rm deploy.tar.gz

echo "==> Installing production dependencies..."
npm install --omit=dev --no-audit --no-fund

echo "==> Restarting app (Passenger)..."
mkdir -p tmp
touch tmp/restart.txt

echo ""
echo "==> Done. Check https://textspeed.in/ in a browser to confirm."
