mailwolt/mailwolt-installer/scripts/phase2-go-live.sh

103 lines
4.4 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#!/usr/bin/env bash
# Phase 2: Go-Live — DNS-Check → LE-Zertifikate → Nginx → Postfix/Dovecot aktualisieren
# Muss als root ausgeführt werden, NACHDEM die DNS-Einträge gesetzt wurden.
# Liest Konfiguration aus /etc/mailwolt/installer.env (durch Phase 1 geschrieben).
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/lib.sh"
require_root
ENV_FILE="/etc/mailwolt/installer.env"
[[ -f "$ENV_FILE" ]] || die "Phase 1 noch nicht abgeschlossen ${ENV_FILE} fehlt."
set -a; . "$ENV_FILE"; set +a
# ── Pflichtfelder ─────────────────────────────────────────────────────────────
: "${BASE_DOMAIN:?BASE_DOMAIN fehlt in ${ENV_FILE}}"
: "${UI_HOST:?UI_HOST fehlt in ${ENV_FILE}}"
: "${WEBMAIL_HOST:?WEBMAIL_HOST fehlt in ${ENV_FILE}}"
: "${MAIL_HOSTNAME:?MAIL_HOSTNAME fehlt in ${ENV_FILE}}"
: "${SERVER_PUBLIC_IPV4:?SERVER_PUBLIC_IPV4 fehlt in ${ENV_FILE}}"
header
echo -e "${CYAN} Phase 2 Go-Live${NC}"
echo -e "${CYAN}${BAR}${NC}"
echo
# ── Schritt 1: DNS Preflight ──────────────────────────────────────────────────
log "DNS-Vorab-Check …"
SKIP_DNS="${SKIP_DNS:-0}"
dns_ok=0
if [[ "$SKIP_DNS" != "1" ]]; then
if dns_preflight "$UI_HOST" "$WEBMAIL_HOST" "$MAIL_HOSTNAME"; then
dns_ok=1
else
warn "Einige DNS-Einträge zeigen noch nicht auf diesen Server."
echo
echo -e " Möglichkeiten:"
echo -e " a) DNS reparieren und dieses Skript erneut ausführen."
echo -e " b) Trotzdem fortfahren: SKIP_DNS=1 bash phase2-go-live.sh"
echo
read -rp "Trotzdem fortfahren? [j/N] " _ans
[[ "${_ans,,}" == "j" ]] || die "Abgebrochen."
dns_ok=1
fi
else
warn "DNS-Check übersprungen (SKIP_DNS=1)."
dns_ok=1
fi
echo
# ── Schritt 2: Let's Encrypt Zertifikate ─────────────────────────────────────
log "Let's Encrypt Zertifikate ausstellen …"
bash "${SCRIPT_DIR}/75-le-issue.sh"
echo
# ── Schritt 3: Nginx-Konfiguration neu schreiben (TLS) ───────────────────────
log "Nginx-Konfiguration aktualisieren (TLS) …"
# Nginx-Builder aus 70-nginx.sh wiederverwenden
source "${SCRIPT_DIR}/70-nginx.sh" || true # sourcing setzt Variablen und führt aus
echo
# ── Schritt 4: Postfix hostname + TLS-Zertifikate aktualisieren ──────────────
log "Postfix: myhostname = ${MAIL_HOSTNAME}"
postconf -e "myhostname = ${MAIL_HOSTNAME}"
postconf -e "myorigin = \$myhostname"
postconf -e "smtpd_tls_cert_file = /etc/ssl/mail/fullchain.pem"
postconf -e "smtpd_tls_key_file = /etc/ssl/mail/privkey.pem"
systemctl reload postfix || true
# ── Schritt 5: Dovecot TLS ───────────────────────────────────────────────────
log "Dovecot: TLS-Zertifikate aktualisieren …"
if [[ -f /etc/dovecot/conf.d/10-ssl.conf ]]; then
sed -i "s|^ssl_cert =.*|ssl_cert = </etc/ssl/mail/fullchain.pem|" /etc/dovecot/conf.d/10-ssl.conf || true
sed -i "s|^ssl_key =.*|ssl_key = </etc/ssl/mail/privkey.pem|" /etc/dovecot/conf.d/10-ssl.conf || true
systemctl reload dovecot || true
fi
# ── Schritt 6: App-URL in .env aktualisieren ──────────────────────────────────
APP_ENV_FILE="${APP_DIR}/.env"
if [[ -f "$APP_ENV_FILE" ]]; then
log "Laravel APP_URL aktualisieren → https://${UI_HOST}"
ENV_FILE="$APP_ENV_FILE"
upsert_env APP_URL "https://${UI_HOST}"
upsert_env APP_HOST "${UI_HOST}"
upsert_env SESSION_SECURE_COOKIE "true"
sudo -u "${APP_USER}" -H bash -lc "cd ${APP_DIR} && php artisan optimize:clear && php artisan config:cache" || true
fi
# ── Fertig ────────────────────────────────────────────────────────────────────
echo
echo -e "${GREEN}${BAR}${NC}"
echo -e "${GREEN} ✔ Phase 2 abgeschlossen!${NC}"
echo -e "${GREEN}${BAR}${NC}"
echo -e " UI: ${CYAN}https://${UI_HOST}${NC}"
echo -e " Webmail: ${CYAN}https://${WEBMAIL_HOST}${NC}"
echo -e " MX: ${GREY}${MAIL_HOSTNAME}${NC}"
echo