From e29f4374c03071283e8afbfe4d39a4f54b43fc81 Mon Sep 17 00:00:00 2001 From: elpatron Date: Wed, 1 Oct 2025 23:16:07 +0200 Subject: [PATCH] Fix: Handle existing SSL certificates in setup script - Added check for existing SSL certificates before attempting to create new ones - Restore original HTTPS nginx.conf after certificate verification - This prevents the script from hanging when certificates already exist --- scripts/setup-ssl-improved.sh | 46 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/scripts/setup-ssl-improved.sh b/scripts/setup-ssl-improved.sh index 682cc4c..12af61b 100644 --- a/scripts/setup-ssl-improved.sh +++ b/scripts/setup-ssl-improved.sh @@ -96,30 +96,38 @@ ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml up -d nginx echo -e "${YELLOW}⏳ Warte auf Nginx...${NC}" sleep 10 -# Erstelle SSL-Zertifikat -echo -e "${YELLOW}🔐 Erstelle SSL-Zertifikat für $DOMAIN...${NC}" -${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certonly \ - --webroot \ - --webroot-path=/var/www/certbot \ - --email $ADMIN_EMAIL \ - --agree-tos \ - --no-eff-email \ - --force-renewal \ - -d $DOMAIN - -if [ $? -eq 0 ]; then - echo -e "${GREEN}✅ SSL-Zertifikat erfolgreich erstellt!${NC}" +# Prüfe ob SSL-Zertifikat bereits existiert +echo -e "${YELLOW}🔍 Prüfe vorhandene SSL-Zertifikate...${NC}" +if ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certificates -d $DOMAIN | grep -q "Certificate Name: $DOMAIN"; then + echo -e "${GREEN}✅ SSL-Zertifikat für $DOMAIN bereits vorhanden!${NC}" else - echo -e "${RED}❌ SSL-Zertifikat-Erstellung fehlgeschlagen!${NC}" - echo "Mögliche Ursachen:" - echo "- Domain ist nicht erreichbar" - echo "- Port 80 ist blockiert" - echo "- DNS-Einträge sind nicht korrekt" - exit 1 + # Erstelle SSL-Zertifikat + echo -e "${YELLOW}🔐 Erstelle SSL-Zertifikat für $DOMAIN...${NC}" + ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certonly \ + --webroot \ + --webroot-path=/var/www/certbot \ + --email $ADMIN_EMAIL \ + --agree-tos \ + --no-eff-email \ + --force-renewal \ + -d $DOMAIN + + if [ $? -eq 0 ]; then + echo -e "${GREEN}✅ SSL-Zertifikat erfolgreich erstellt!${NC}" + else + echo -e "${RED}❌ SSL-Zertifikat-Erstellung fehlgeschlagen!${NC}" + echo "Mögliche Ursachen:" + echo "- Domain ist nicht erreichbar" + echo "- Port 80 ist blockiert" + echo "- DNS-Einträge sind nicht korrekt" + exit 1 + fi fi # Erstelle HTTPS Nginx-Konfiguration echo -e "${YELLOW}📝 Erstelle HTTPS Nginx-Konfiguration...${NC}" +# Stelle die ursprüngliche HTTPS-Konfiguration wieder her +git checkout nginx/nginx.conf sed "s/\${DOMAIN}/$DOMAIN/g" nginx/nginx.conf > nginx/nginx.conf.tmp mv nginx/nginx.conf.tmp nginx/nginx.conf