Request only one certificate for all domains

This commit is contained in:
Philipp 2019-01-01 22:10:24 +01:00
parent 07f113d3d8
commit 94c73dbf3f
1 changed files with 30 additions and 28 deletions

View File

@ -22,32 +22,34 @@ if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/
echo echo
fi fi
echo "### Creating dummy certificate for $domains ..."
for domain in "${domains[@]}"; do path="/etc/letsencrypt/live/$domains"
if [ -d "$data_path/conf/live/$domain" ]; then mkdir -p "$data_path/conf/live/$domains"
read -p "There is already folder with $domain domain data, do you want to remove it? (WARNING: removing folder will remove all certbot data for this domain) (Y/n) " decision docker-compose run --rm --entrypoint "\
case $decision in openssl req -x509 -nodes -newkey rsa:1024 -days 1\
[Y]* ) rm -rf "$data_path/conf/live/$domain" && mkdir -p "$data_path/conf/live/$domain";; -keyout '$path/privkey.pem' \
[n]* ) domains=(${domains[@]/$domain});; -out '$path/fullchain.pem' \
* ) echo "Please choose the right variant (Y/n).";; -subj '/CN=localhost'" certbot
esac echo
else
mkdir -p "$data_path/conf/live/$domain"
fi
done
for domain in "${domains[@]}"; do
echo "### Creating dummy certificate for $domain domain..."
path="/etc/letsencrypt/live/$domain" echo "### Deleting dummy certificate for $domains ..."
docker-compose run --rm --entrypoint "openssl req -x509 -nodes -newkey rsa:1024 \ docker-compose run --rm --entrypoint "\
-days 1 -keyout '$path/privkey.pem' -out '$path/fullchain.pem' -subj '/CN=localhost'" certbot rm -Rf /etc/letsencrypt/live/$domains && \
done rm -Rf /etc/letsencrypt/archive/$domains && \
rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
echo
echo "### Starting nginx ..." echo "### Starting nginx ..."
# Restarting for case if nginx container is already started # Restarting for case if nginx container is already started
docker-compose up -d nginx && docker-compose restart nginx docker-compose up -d nginx && docker-compose restart nginx
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"
# Select appropriate email arg # Select appropriate email arg
case "$email" in case "$email" in
@ -58,14 +60,14 @@ esac
# Enable staging mode if needed # Enable staging mode if needed
if [ $staging != "0" ]; then staging_arg="--staging"; fi if [ $staging != "0" ]; then staging_arg="--staging"; fi
for domain in "${domains[@]}"; do docker-compose run --rm --entrypoint "\
echo "### Deleting dummy certificate for $domain domain ..." certbot certonly --webroot -w /var/www/certbot \
rm -rf "$data_path/conf/live/$domain" $staging_arg \
$email_arg \
echo "### Requesting Let's Encrypt certificate for $domain domain ..." $domain_args \
mkdir -p "$data_path/www" --rsa-key-size $rsa_key_size \
docker-compose run --rm --entrypoint "certbot certonly --webroot -w /var/www/certbot -d $domain \ --agree-tos \
$staging_arg $email_arg --rsa-key-size $rsa_key_size --agree-tos --force-renewal" certbot --force-renewal" certbot
done echo
docker-compose exec nginx nginx -s reload docker-compose exec nginx nginx -s reload