#!/bin/bash
# deploy.sh - Deployment-Skript für Harheimer TC

echo "🚀 Starting Harheimer TC Deployment..."

# Repository aktualisieren
echo "📥 Updating repository..."
cd /var/www/harheimertc
git pull origin main

# Dependencies installieren
echo "📦 Installing dependencies..."
npm install

# Website bauen (Static Generation)
echo "🔨 Building website..."
npm run generate

# Berechtigungen setzen
echo "🔐 Setting permissions..."
sudo chown -R www-data:www-data /var/www/harheimertc/dist/
sudo chmod -R 755 /var/www/harheimertc/dist/

# PM2 Backend starten (falls nicht läuft)
echo "🖥️ Starting backend server..."
pm2 start ecosystem.config.cjs || pm2 restart harheimertc

echo "✅ Deployment completed!"
echo "🌐 Website: https://harheimertc.tsschulz.de"
echo "🔧 Backend: https://harheimertc.tsschulz.de/api/"
