diff --git a/docker-compose.yml b/docker-compose.yml index 9615cc1f..8ad35330 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: nginx: - image: nginx:1.15-alpine + image: nginx:1.30-alpine restart: unless-stopped volumes: - ./data/nginx:/etc/nginx/conf.d diff --git a/init-letsencrypt.sh b/init-letsencrypt.sh index a3f3cb01..7f538052 100755 --- a/init-letsencrypt.sh +++ b/init-letsencrypt.sh @@ -11,8 +11,11 @@ data_path="./data/certbot" email="" # Adding a valid address is strongly recommended staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits -if [ -d "$data_path" ]; then - read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision +# Use the first domain as the certificate directory name +cert_dir="${domains[0]}" + +if [ -d "$data_path/conf/live/$cert_dir" ]; then + read -p "Existing data found for $cert_dir (${domains[*]}). Continue and replace existing certificate? (y/N) " decision if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then exit fi @@ -27,9 +30,9 @@ if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ echo fi -echo "### Creating dummy certificate for $domains ..." -path="/etc/letsencrypt/live/$domains" -mkdir -p "$data_path/conf/live/$domains" +echo "### Creating dummy certificate for $cert_dir (${domains[*]}) ..." +path="/etc/letsencrypt/live/$cert_dir" +mkdir -p "$data_path/conf/live/$cert_dir" docker-compose run --rm --entrypoint "\ openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\ -keyout '$path/privkey.pem' \ @@ -42,15 +45,15 @@ echo "### Starting nginx ..." docker-compose up --force-recreate -d nginx echo -echo "### Deleting dummy certificate for $domains ..." +echo "### Deleting dummy certificate for $cert_dir ..." docker-compose run --rm --entrypoint "\ - rm -Rf /etc/letsencrypt/live/$domains && \ - rm -Rf /etc/letsencrypt/archive/$domains && \ - rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot + rm -Rf /etc/letsencrypt/live/$cert_dir && \ + rm -Rf /etc/letsencrypt/archive/$cert_dir && \ + rm -Rf /etc/letsencrypt/renewal/${cert_dir}.conf" certbot echo -echo "### Requesting Let's Encrypt certificate for $domains ..." +echo "### Requesting Let's Encrypt certificate for ${domains[*]} ..." #Join $domains to -d args domain_args="" for domain in "${domains[@]}"; do