#!/bin/bash
# Sunbelt Mail Matrix — VPS Startup Script
# Run this once after uploading the zip: bash start.sh

set -e
cd "$(dirname "$0")"

echo ""
echo "=== Sunbelt Mail Matrix ==="
echo ""

# Check .env exists
if [ ! -f ".env" ]; then
  echo "ERROR: .env file not found."
  echo "Copy .env.example to .env and fill in your credentials first:"
  echo "  cp .env.example .env && nano .env"
  echo ""
  exit 1
fi

echo "[1/2] Installing dependencies..."
npm install

echo "[2/2] Starting server..."
echo ""
NODE_ENV=production node --import tsx/esm server.ts
