forked from eugene-khyst/letsencrypt-docker-compose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcertbot.sh
54 lines (44 loc) · 1.2 KB
/
certbot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
set -e
trap exit INT TERM
if [ -z "$DOMAINS" ]; then
echo "DOMAINS environment variable is not set"
exit 1;
fi
until nc -z nginx 80; do
echo "Waiting for nginx to start..."
sleep 5s & wait ${!}
done
if [ "$CERTBOT_TEST_CERT" != "0" ]; then
test_cert_arg="--test-cert"
fi
domains_fixed=$(echo "$DOMAINS" | tr -d \")
domain_list=($domains_fixed)
emails_fixed=$(echo "$CERTBOT_EMAILS" | tr -d \")
emails_list=($emails_fixed)
for i in "${!domain_list[@]}"; do
domain="${domain_list[i]}"
mkdir -p "/var/www/certbot/$domain"
if [ -d "/etc/letsencrypt/live/$domain" ]; then
echo "Let's Encrypt certificate for $domain already exists"
continue
fi
email="${emails_list[i]}"
if [ -z "$email" ]; then
email_arg="--register-unsafely-without-email"
echo "Obtaining the certificate for $domain without email"
else
email_arg="--email $email"
echo "Obtaining the certificate for $domain with email $email"
fi
certbot certonly \
--webroot \
-w "/var/www/certbot/$domain" \
-d "$domain" -d "www.$domain" \
$test_cert_arg \
$email_arg \
--rsa-key-size "${CERTBOT_RSA_KEY_SIZE:-4096}" \
--agree-tos \
--noninteractive \
--verbose || true
done