-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-letsencrypt.sh
70 lines (61 loc) · 2.13 KB
/
init-letsencrypt.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
domains=($1)
rsa_key_size=4096
data_path="$DIR/data/certbot"
email="$2" # Adding a valid address is strongly recommended
staging=$3 # 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
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
exit
fi
fi
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
echo "### Downloading recommended TLS parameters ..."
mkdir -p "$data_path/conf"
curl -s -f https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
curl -s -f https://raw.githubusercontent.com/certbot/certbot/master/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
echo
fi
echo "### Starting temporary nginx ..."
set +e
docker stop nginx-temp-setup
set -e
docker pull -q nginx:stable-alpine
docker run -d --rm \
--name nginx-temp-setup \
-v "$DIR/data/nginx-setup:/etc/nginx/conf.d" \
-v "$data_path/www:/var/www/certbot" \
-p 80:80 \
nginx:stable-alpine
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
"") email_arg="--register-unsafely-without-email" ;;
*) email_arg="--email $email" ;;
esac
# Enable staging mode if needed
if [ $staging != "0" ]; then staging_arg="--staging"; fi
docker pull -q certbot/certbot
docker run --rm \
--name certbot-temp-setup \
-v "$data_path/conf:/etc/letsencrypt" \
-v "$data_path/www:/var/www/certbot" \
certbot/certbot \
certonly --webroot -w /var/www/certbot \
--non-interactive \
$staging_arg \
$email_arg \
--rsa-key-size $rsa_key_size \
--agree-tos \
--force-renewal \
$domain_args
echo "### Shutting down temporary nginx ..."
docker stop nginx-temp-setup