# PowerShell-Script für SSL-Setup auf Windows (Entwicklung) # Für Produktionsumgebung verwende das Bash-Script auf Linux param( [string]$Domain = "", [string]$AdminEmail = "" ) Write-Host "🔧 Stargirlnails Kiel - SSL-Setup (Windows)" -ForegroundColor Blue Write-Host "=============================================" # Prüfe ob .env-Datei existiert if (-not (Test-Path ".env")) { Write-Host "❌ .env-Datei nicht gefunden!" -ForegroundColor Red Write-Host "Bitte erstelle eine .env-Datei mit DOMAIN und ADMIN_EMAIL" exit 1 } # Lade .env-Datei $envContent = Get-Content ".env" $envVars = @{} foreach ($line in $envContent) { if ($line -match "^([^#][^=]+)=(.*)$") { $envVars[$matches[1]] = $matches[2] } } # Verwende Parameter oder .env-Werte if ($Domain) { $envVars["DOMAIN"] = $Domain } if ($AdminEmail) { $envVars["ADMIN_EMAIL"] = $AdminEmail } # Prüfe erforderliche Variablen if (-not $envVars["DOMAIN"]) { Write-Host "❌ DOMAIN nicht definiert!" -ForegroundColor Red Write-Host "Verwende: .\setup-ssl.ps1 -Domain 'example.com' -AdminEmail 'admin@example.com'" exit 1 } if (-not $envVars["ADMIN_EMAIL"]) { Write-Host "❌ ADMIN_EMAIL nicht definiert!" -ForegroundColor Red Write-Host "Verwende: .\setup-ssl.ps1 -Domain 'example.com' -AdminEmail 'admin@example.com'" exit 1 } Write-Host "✅ Domain: $($envVars['DOMAIN'])" -ForegroundColor Green Write-Host "✅ Admin E-Mail: $($envVars['ADMIN_EMAIL'])" -ForegroundColor Green Write-Host "" # Erstelle nginx.conf mit korrekter Domain Write-Host "📝 Erstelle Nginx-Konfiguration..." -ForegroundColor Yellow $nginxConfig = Get-Content "nginx/nginx.conf" -Raw $nginxConfig = $nginxConfig -replace '\$\{DOMAIN\}', $envVars["DOMAIN"] Set-Content "nginx/nginx.conf" $nginxConfig # Erstelle Docker Volumes Write-Host "📦 Erstelle Docker Volumes..." -ForegroundColor Yellow docker volume create certbot-certs 2>$null docker volume create certbot-webroot 2>$null # Starte temporären HTTP-Server Write-Host "🌐 Starte temporären HTTP-Server..." -ForegroundColor Yellow docker-compose -f docker-compose-prod.yml up -d nginx # Warte auf Nginx Write-Host "⏳ Warte auf Nginx..." -ForegroundColor Yellow Start-Sleep -Seconds 10 # Erstelle SSL-Zertifikat Write-Host "🔐 Erstelle SSL-Zertifikat für $($envVars['DOMAIN'])..." -ForegroundColor Yellow $certbotCmd = "docker-compose -f docker-compose-prod.yml run --rm certbot certbot certonly --webroot --webroot-path=/var/www/certbot --email $($envVars['ADMIN_EMAIL']) --agree-tos --no-eff-email --force-renewal -d $($envVars['DOMAIN'])" Invoke-Expression $certbotCmd if ($LASTEXITCODE -eq 0) { Write-Host "✅ SSL-Zertifikat erfolgreich erstellt!" -ForegroundColor Green } else { Write-Host "❌ SSL-Zertifikat-Erstellung fehlgeschlagen!" -ForegroundColor Red Write-Host "Mögliche Ursachen:" Write-Host "- Domain ist nicht erreichbar" Write-Host "- Port 80 ist blockiert" Write-Host "- DNS-Einträge sind nicht korrekt" exit 1 } # Starte alle Services Write-Host "🚀 Starte alle Services..." -ForegroundColor Yellow docker-compose -f docker-compose-prod.yml up -d # Prüfe Status Write-Host "🔍 Prüfe Service-Status..." -ForegroundColor Yellow Start-Sleep -Seconds 5 $services = docker-compose -f docker-compose-prod.yml ps if ($services -match "Up") { Write-Host "✅ Alle Services laufen!" -ForegroundColor Green Write-Host "" Write-Host "🌐 Deine Anwendung ist jetzt verfügbar unter:" -ForegroundColor Blue Write-Host " https://$($envVars['DOMAIN'])" -ForegroundColor Green Write-Host "" Write-Host "📋 Nützliche Befehle:" -ForegroundColor Blue Write-Host " Status anzeigen: docker-compose -f docker-compose-prod.yml ps" Write-Host " Logs anzeigen: docker-compose -f docker-compose-prod.yml logs -f" Write-Host " Services stoppen: docker-compose -f docker-compose-prod.yml down" Write-Host " Zertifikat erneuern: docker-compose -f docker-compose-prod.yml run --rm certbot certbot renew" Write-Host "" Write-Host "⚠️ Wichtig:" -ForegroundColor Yellow Write-Host " - SSL-Zertifikate werden automatisch alle 12 Stunden erneuert" Write-Host " - Überwache die Logs regelmäßig" Write-Host " - Stelle sicher, dass Port 80 und 443 erreichbar sind" } else { Write-Host "❌ Einige Services sind nicht gestartet!" -ForegroundColor Red Write-Host "Prüfe die Logs: docker-compose -f docker-compose-prod.yml logs" exit 1 }