|
1 |
| -#!/bin/bash |
2 |
| - |
3 |
| -set -a |
4 |
| -source <(cat resgrid.env | \ |
5 |
| - sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g") |
6 |
| -set +a |
7 |
| - |
8 |
| -if ! [ -x "$(command -v docker-compose)" ]; then |
9 |
| - echo 'Error: docker-compose is not installed.' >&2 |
10 |
| - exit 1 |
11 |
| -fi |
12 |
| - |
13 |
| -domains=($NGINX_RESGRID_WEB_URL $NGINX_RESGRID_API_URL $NGINX_RESGRID_EVENTS_URL) |
14 |
| -rsa_key_size=4096 |
15 |
| -data_path="./docker-data/certbot" |
16 |
| -email=$NGINX_LETSENCRYPT_EMAIL # Adding a valid address is strongly recommended |
17 |
| -staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits |
18 |
| - |
19 |
| -if [ -d "$data_path" ]; then |
20 |
| - read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision |
21 |
| - if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then |
22 |
| - exit |
23 |
| - fi |
24 |
| -fi |
25 |
| - |
26 |
| - |
27 |
| -if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then |
28 |
| - echo "### Downloading recommended TLS parameters ..." |
29 |
| - mkdir -p "$data_path/conf" |
30 |
| - curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf" |
31 |
| - curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem" |
32 |
| - echo |
33 |
| -fi |
34 |
| - |
35 |
| -echo "### Creating dummy certificate for $domains ..." |
36 |
| -path="/etc/letsencrypt/live/$domains" |
37 |
| -mkdir -p "$data_path/conf/live/$domains" |
38 |
| -docker-compose run --rm --entrypoint "\ |
39 |
| - openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\ |
40 |
| - -keyout '$path/privkey.pem' \ |
41 |
| - -out '$path/fullchain.pem' \ |
42 |
| - -subj '/CN=localhost'" certbot |
43 |
| -echo |
44 |
| - |
45 |
| - |
46 |
| -echo "### Starting nginx ..." |
47 |
| -docker-compose up --force-recreate -d nginx |
48 |
| -echo |
49 |
| - |
50 |
| -echo "### Deleting dummy certificate for $domains ..." |
51 |
| -docker-compose run --rm --entrypoint "\ |
52 |
| - rm -Rf /etc/letsencrypt/live/$domains && \ |
53 |
| - rm -Rf /etc/letsencrypt/archive/$domains && \ |
54 |
| - rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot |
55 |
| -echo |
56 |
| - |
57 |
| - |
58 |
| -echo "### Requesting Let's Encrypt certificate for $domains ..." |
59 |
| -#Join $domains to -d args |
60 |
| -domain_args="" |
61 |
| -for domain in "${domains[@]}"; do |
62 |
| - domain_args="$domain_args -d $domain" |
63 |
| -done |
64 |
| - |
65 |
| -# Select appropriate email arg |
66 |
| -case "$email" in |
67 |
| - "") email_arg="--register-unsafely-without-email" ;; |
68 |
| - *) email_arg="--email $email" ;; |
69 |
| -esac |
70 |
| - |
71 |
| -# Enable staging mode if needed |
72 |
| -if [ $staging != "0" ]; then staging_arg="--staging"; fi |
73 |
| - |
74 |
| -docker-compose run --rm --entrypoint "\ |
75 |
| - certbot certonly --webroot -w /var/www/certbot \ |
76 |
| - $staging_arg \ |
77 |
| - $email_arg \ |
78 |
| - $domain_args \ |
79 |
| - --rsa-key-size $rsa_key_size \ |
80 |
| - --agree-tos \ |
81 |
| - --force-renewal" certbot |
82 |
| -echo |
83 |
| - |
84 |
| -for domain in "${domains[@]}"; do |
85 |
| - domain_args="$domain_args -d $domain" |
86 |
| -done |
87 |
| - |
88 |
| -cp -f ./docker-data/nginx/resgrid-ssl.template ./docker-data/nginx/resgrid.template |
89 |
| - |
90 |
| -echo "### Reloading nginx ..." |
91 |
| -docker-compose exec nginx nginx -s reload |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -a |
| 4 | +source <(cat resgrid.env | \ |
| 5 | + sed -e '/^#/d;/^\s*$/d' -e "s/'/'\\\''/g" -e "s/=\(.*\)/='\1'/g") |
| 6 | +set +a |
| 7 | + |
| 8 | +if ! [ -x "$(command -v docker-compose)" ]; then |
| 9 | + echo 'Error: docker-compose is not installed.' >&2 |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +domains=($NGINX_RESGRID_WEB_URL $NGINX_RESGRID_API_URL $NGINX_RESGRID_EVENTS_URL) |
| 14 | +rsa_key_size=4096 |
| 15 | +data_path="./docker-data/certbot" |
| 16 | +email=$NGINX_LETSENCRYPT_EMAIL # Adding a valid address is strongly recommended |
| 17 | +staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits |
| 18 | + |
| 19 | +if [ -d "$data_path" ]; then |
| 20 | + read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision |
| 21 | + if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then |
| 22 | + exit |
| 23 | + fi |
| 24 | +fi |
| 25 | + |
| 26 | + |
| 27 | +if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then |
| 28 | + echo "### Downloading recommended TLS parameters ..." |
| 29 | + mkdir -p "$data_path/conf" |
| 30 | + curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf" |
| 31 | + curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem" |
| 32 | + echo |
| 33 | +fi |
| 34 | + |
| 35 | +echo "### Creating dummy certificate for $domains ..." |
| 36 | +path="/etc/letsencrypt/live/$domains" |
| 37 | +mkdir -p "$data_path/conf/live/$domains" |
| 38 | +docker-compose run --rm --entrypoint "\ |
| 39 | + openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\ |
| 40 | + -keyout '$path/privkey.pem' \ |
| 41 | + -out '$path/fullchain.pem' \ |
| 42 | + -subj '/CN=localhost'" certbot |
| 43 | +echo |
| 44 | + |
| 45 | + |
| 46 | +echo "### Starting nginx ..." |
| 47 | +docker-compose up --force-recreate -d nginx |
| 48 | +echo |
| 49 | + |
| 50 | +echo "### Deleting dummy certificate for $domains ..." |
| 51 | +docker-compose run --rm --entrypoint "\ |
| 52 | + rm -Rf /etc/letsencrypt/live/$domains && \ |
| 53 | + rm -Rf /etc/letsencrypt/archive/$domains && \ |
| 54 | + rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot |
| 55 | +echo |
| 56 | + |
| 57 | + |
| 58 | +echo "### Requesting Let's Encrypt certificate for $domains ..." |
| 59 | +#Join $domains to -d args |
| 60 | +domain_args="" |
| 61 | +for domain in "${domains[@]}"; do |
| 62 | + domain_args="$domain_args -d $domain" |
| 63 | +done |
| 64 | + |
| 65 | +# Select appropriate email arg |
| 66 | +case "$email" in |
| 67 | + "") email_arg="--register-unsafely-without-email" ;; |
| 68 | + *) email_arg="--email $email" ;; |
| 69 | +esac |
| 70 | + |
| 71 | +# Enable staging mode if needed |
| 72 | +if [ $staging != "0" ]; then staging_arg="--staging"; fi |
| 73 | + |
| 74 | +docker-compose run --rm --entrypoint "\ |
| 75 | + certbot certonly --webroot -w /var/www/certbot \ |
| 76 | + $staging_arg \ |
| 77 | + $email_arg \ |
| 78 | + $domain_args \ |
| 79 | + --rsa-key-size $rsa_key_size \ |
| 80 | + --agree-tos \ |
| 81 | + --force-renewal" certbot |
| 82 | +echo |
| 83 | + |
| 84 | +for domain in "${domains[@]}"; do |
| 85 | + domain_args="$domain_args -d $domain" |
| 86 | +done |
| 87 | + |
| 88 | +cp -f ./docker-data/nginx/resgrid-ssl.template ./docker-data/nginx/resgrid.template |
| 89 | + |
| 90 | +echo "### Reloading nginx ..." |
| 91 | +docker-compose exec nginx nginx -s reload |
0 commit comments