#!/bin/bash # Check if email is provided if [ -z "$EMAIL" ]; then echo "ERROR: Email address is required" exit 1 fi # Function to generate Let's Encrypt certificate generate_cert() { local domain=$1 certbot --nginx \ --non-interactive \ --agree-tos \ --email "$EMAIL" \ -d "$domain" \ --redirect } # If no domain is provided, use the DOMAINS environment variable if [ $# -eq 0 ] && [ -n "$DOMAINS" ]; then IFS=',' read -ra DOMAIN_LIST <<< "$DOMAINS" for domain in "${DOMAIN_LIST[@]}"; do generate_cert "$domain" done else # Generate for specified domains for domain in "$@"; do generate_cert "$domain" done fi