|
|
|
@@ -8,11 +8,16 @@
|
|
|
|
|
# cartella /etc/letsencrypt/live/<primario>/ referenziata in nginx.conf.
|
|
|
|
|
#
|
|
|
|
|
# Lanciarlo una volta sola, al primo setup. Per i rinnovi usare renew.sh.
|
|
|
|
|
#
|
|
|
|
|
# NB: usa il plugin "docker compose" (v2). Con questo plugin --entrypoint accetta
|
|
|
|
|
# solo un eseguibile: i comandi con piu' token o con && vanno wrappati in
|
|
|
|
|
# `--entrypoint sh <service> -c "..."`, altrimenti gli argomenti oltre il primo
|
|
|
|
|
# vengono scartati silenziosamente.
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
if ! [ -x "$(command -v docker-compose)" ]; then
|
|
|
|
|
echo 'Error: docker-compose is not installed.' >&2
|
|
|
|
|
if ! docker compose version >/dev/null 2>&1; then
|
|
|
|
|
echo 'Error: "docker compose" (plugin v2) is not available.' >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
@@ -35,9 +40,9 @@ email="riccardo.didato@gmail.com"
|
|
|
|
|
staging=0
|
|
|
|
|
|
|
|
|
|
# Costruisce la sequenza di argomenti -d per certbot
|
|
|
|
|
domain_args=""
|
|
|
|
|
domain_args=()
|
|
|
|
|
for domain in "${domains[@]}"; do
|
|
|
|
|
domain_args="$domain_args -d $domain"
|
|
|
|
|
domain_args+=(-d "$domain")
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
@@ -62,45 +67,48 @@ else
|
|
|
|
|
echo "### Creating dummy certificate for $primary_domain ..."
|
|
|
|
|
path="/etc/letsencrypt/live/$primary_domain"
|
|
|
|
|
mkdir -p "$data_path/conf/live/$primary_domain"
|
|
|
|
|
docker-compose run --rm --entrypoint "\
|
|
|
|
|
docker compose run --rm --entrypoint sh certbot -c "\
|
|
|
|
|
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1 \
|
|
|
|
|
-keyout '$path/privkey.pem' \
|
|
|
|
|
-out '$path/fullchain.pem' \
|
|
|
|
|
-subj '/CN=localhost'" certbot
|
|
|
|
|
-subj '/CN=localhost'"
|
|
|
|
|
echo
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "### Starting nginx ..."
|
|
|
|
|
docker-compose up --force-recreate -d nginx
|
|
|
|
|
docker compose up --force-recreate -d nginx
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
# FASE 2: richiesta del certificato REALE
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
echo "### Deleting dummy certificate ..."
|
|
|
|
|
docker-compose run --rm --entrypoint "\
|
|
|
|
|
docker compose run --rm --entrypoint sh certbot -c "\
|
|
|
|
|
rm -Rf /etc/letsencrypt/live/$primary_domain && \
|
|
|
|
|
rm -Rf /etc/letsencrypt/archive/$primary_domain && \
|
|
|
|
|
rm -Rf /etc/letsencrypt/renewal/$primary_domain.conf" certbot
|
|
|
|
|
rm -Rf /etc/letsencrypt/renewal/$primary_domain.conf"
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
email_arg=()
|
|
|
|
|
case "$email" in
|
|
|
|
|
"") email_arg="--register-unsafely-without-email" ;;
|
|
|
|
|
*) email_arg="--email $email" ;;
|
|
|
|
|
"") email_arg=(--register-unsafely-without-email) ;;
|
|
|
|
|
*) email_arg=(--email "$email") ;;
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
if [ "$staging" != "0" ]; then staging_arg="--staging"; fi
|
|
|
|
|
staging_arg=()
|
|
|
|
|
if [ "$staging" != "0" ]; then staging_arg=(--staging); fi
|
|
|
|
|
|
|
|
|
|
echo "### Requesting Let's Encrypt certificate for: ${domains[*]} ..."
|
|
|
|
|
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
|
|
|
|
|
# L'immagine certbot/certbot ha gia' "certbot" come entrypoint: passiamo solo
|
|
|
|
|
# gli argomenti come comando (niente --entrypoint da sovrascrivere).
|
|
|
|
|
docker compose run --rm certbot certonly --webroot -w /var/www/certbot \
|
|
|
|
|
"${staging_arg[@]}" \
|
|
|
|
|
"${email_arg[@]}" \
|
|
|
|
|
"${domain_args[@]}" \
|
|
|
|
|
--rsa-key-size "$rsa_key_size" \
|
|
|
|
|
--agree-tos \
|
|
|
|
|
--force-renewal
|
|
|
|
|
echo
|
|
|
|
|
|
|
|
|
|
echo "### Reloading nginx ..."
|
|
|
|
|
docker-compose exec nginx nginx -s reload
|
|
|
|
|
docker compose exec nginx nginx -s reload
|
|
|
|
|