#!/bin/bash set -e echo "🚀 quiXzoom Shop — Produktionssetup" echo "====================================" # Kontrollera att vi är root if [ "$EUID" -ne 0 ]; then echo "❌ Kör som root: sudo ./setup.sh" exit 1 fi # 1. Kontrollera förutsättningar echo "📋 Kontrollerar förutsättningar..." if ! command -v nginx &> /dev/null; then echo "❌ nginx inte installerat" exit 1 fi if ! command -v certbot &> /dev/null; then echo "❌ certbot inte installerat" exit 1 fi if ! command -v psql &> /dev/null; then echo "❌ PostgreSQL inte installerat" exit 1 fi echo "✅ Alla förutsättningar uppfyllda" # 2. Skapa databas echo "🗄️ Skapar databas..." su - postgres -c "psql -c \"CREATE DATABASE quixzoom_shop;\"" 2>/dev/null || echo " Databas finns redan" # 3. Kopiera systemd service echo "⚙️ Konfigurerar systemd service..." cp quixzoom-shop.service /etc/systemd/system/ systemctl daemon-reload systemctl enable quixzoom-shop # 4. Kopiera nginx config echo "🌐 Konfigurerar nginx..." cp nginx-shop.conf /etc/nginx/conf.d/ nginx -t # 5. SSL echo "🔒 Sätter upp SSL..." if [ ! -d "/etc/letsencrypt/live/quixzoom.com" ]; then certbot --nginx -d shop.quixzoom.com --non-interactive --agree-tos --email admin@quixzoom.com else echo " SSL-certifikat finns redan" fi # 6. Starta tjänster echo "🚀 Startar tjänster..." systemctl start quixzoom-shop systemctl reload nginx # 7. Verifiera echo "✅ Verifierar..." sleep 3 if curl -s http://localhost:8087/health | grep -q "ok"; then echo "✅ Shop-tjänsten körs på port 8087" else echo "⚠️ Shop-tjänsten svarar inte, kolla loggar: journalctl -u quixzoom-shop" fi echo "" echo "🎉 Setup klar!" echo "" echo "Nästa steg:" echo "1. Uppdatera miljövariabler: sudo systemctl edit --full quixzoom-shop" echo "2. Lägg till Stripe-nycklar i miljövariablerna" echo "3. Konfigurera Stripe webhook: https://dashboard.stripe.com/webhooks" echo "" echo "URL:er:" echo " Shop: https://shop.quixzoom.com" echo " API: https://shop.quixzoom.com/api/" echo " Verify: https://shop.quixzoom.com/verify/{id}" echo " Health: https://shop.quixzoom.com/health"