diff --git a/init-letsencrypt.sh b/init-letsencrypt.sh index 13eaa757..e3c4bbaf 100755 --- a/init-letsencrypt.sh +++ b/init-letsencrypt.sh @@ -27,35 +27,33 @@ 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" -docker-compose run --rm --entrypoint "\ - openssl req -x509 -nodes -newkey rsa:1024 -days 1\ - -keyout '$path/privkey.pem' \ - -out '$path/fullchain.pem' \ - -subj '/CN=localhost'" certbot -echo - +for domain in "${domains[@]}"; do + echo "### Creating dummy certificate for $domain ..." + path="/etc/letsencrypt/live/$domain" + mkdir -p "$data_path/conf/live/$domain" + docker-compose run --rm --entrypoint "\ + openssl req -x509 -nodes -newkey rsa:4096 -days 1\ + -keyout '$path/privkey.pem' \ + -out '$path/fullchain.pem' \ + -subj '/CN=localhost'" certbot + echo +done echo "### Starting nginx ..." docker-compose up --force-recreate -d nginx echo -echo "### Deleting dummy certificate for $domains ..." -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 -echo - +for domain in "${domains[@]}"; do + echo "### Deleting dummy certificate for $domain ..." + docker-compose run --rm --entrypoint "\ + rm -Rf /etc/letsencrypt/live/$domain && \ + rm -Rf /etc/letsencrypt/archive/$domain && \ + rm -Rf /etc/letsencrypt/renewal/$domain.conf" certbot + echo +done echo "### Requesting Let's Encrypt certificate for $domains ..." #Join $domains to -d args -domain_args="" -for domain in "${domains[@]}"; do - domain_args="$domain_args -d $domain" -done # Select appropriate email arg case "$email" in @@ -66,15 +64,20 @@ esac # Enable staging mode if needed if [ $staging != "0" ]; then staging_arg="--staging"; fi -docker-compose run --rm --entrypoint "\ - certbot certonly --webroot -w /var/www/certbot \ - $staging_arg \ - $email_arg \ - $domain_args \ - --rsa-key-size $rsa_key_size \ - --agree-tos \ - --force-renewal" certbot -echo +for domain in "${domains[@]}"; do + domain_args="$domain_args -d $domain" + + docker-compose run --rm --entrypoint "\ + certbot certonly --webroot -w /var/www/certbot \ + $staging_arg \ + $email_arg \ + -d $domain \ + --rsa-key-size $rsa_key_size \ + --agree-tos \ + --force-renewal" certbot + echo + +done echo "### Reloading nginx ..." docker-compose exec nginx nginx -s reload