Files
patrickandClaude Sonnet 5 6104a67c9e feat(tls): optionales certbot-Setup vorbereitet (Option A)
setup-tls.sh: auf Server ausführbares, manuelles Skript für direktes
Let's-Encrypt-Zertifikat via certbot --nginx. Bleibt ungenutzt solange
der vorgeschaltete Proxy TLS+Domain übernimmt (aktueller Stand) -
nginx.conf bleibt deshalb bewusst HTTP-only, certbot würde die
443-Erweiterung selbst in /etc/nginx/ einfügen, nicht ins Repo.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTxkZEUdfgMxZvHPiZJ8bV
2026-08-05 19:34:25 +02:00

56 lines
2.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# =============================================================================
# setup-tls.sh AUF DEM SERVER ausführen (nicht lokal), OPTIONAL
#
# Aktiviert direktes TLS-Zertifikat via certbot/Let's Encrypt für diesen
# Server. NICHT nötig solange ein vorgeschalteter Proxy die Domain +
# Zertifikat übernimmt (aktueller Stand) dann läuft nginx.conf bewusst
# reines HTTP hinter dem Proxy weiter, dieses Skript bleibt ungenutzt.
#
# Erst ausführen wenn:
# - der Server direkt (ohne vorgeschalteten Proxy) erreichbar sein soll, UND
# - eine echte Domain per DNS auf diesen Server zeigt (A-Record)
#
# Macht NICHTS automatisch am Server-Setup muss manuell mit Domain
# aufgerufen werden:
# ssh root@<host> "cd /opt/timemaster && ./setup-tls.sh timemaster.example.com"
#
# certbot --nginx erweitert /etc/nginx/sites-available/timemaster selbst um
# den 443-Block (SSL-Zertifikat, HSTS optional per --redirect-Flag) und
# richtet einen systemd-Timer für automatisches Renewal ein (certbot.timer).
# Das Repo-nginx.conf bleibt absichtlich HTTP-only die von certbot
# vorgenommene Änderung landet direkt in /etc/nginx/, nicht im Git-Tree.
# =============================================================================
set -euo pipefail
DOMAIN="${1:-}"
if [[ -z "$DOMAIN" ]]; then
echo "Usage: ./setup-tls.sh <domain>" >&2
echo "Beispiel: ./setup-tls.sh timemaster.example.com" >&2
exit 1
fi
if ! command -v certbot >/dev/null 2>&1; then
echo "==> Installiere certbot + nginx-Plugin"
apt-get update -qq
apt-get install -y certbot python3-certbot-nginx
fi
echo "==> Prüfe DNS-Auflösung für $DOMAIN"
RESOLVED="$(getent hosts "$DOMAIN" | awk '{print $1}' | head -1 || true)"
if [[ -z "$RESOLVED" ]]; then
echo "FEHLER: $DOMAIN löst nicht auf. A-Record setzen, dann erneut versuchen." >&2
exit 1
fi
echo " $DOMAIN -> $RESOLVED"
echo "==> Hole Zertifikat + richte 443-Redirect ein (certbot --nginx)"
certbot --nginx -d "$DOMAIN" --redirect --hsts --agree-tos --non-interactive \
-m "${CERTBOT_EMAIL:-admin@${DOMAIN}}"
echo "==> Renewal-Timer prüfen"
systemctl status certbot.timer --no-pager | head -5
echo "==> Fertig. HTTPS aktiv unter https://$DOMAIN"
echo " Falls vorher ein Proxy davor stand: DNS/Load-Balancer jetzt auf diesen Server direkt zeigen lassen."