forked from saberone/mosquitto-docker-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
certbot.sh
executable file
·65 lines (63 loc) · 2.79 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
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
# Check to see if certs for the specified domain exist
# Attempt to retrieve certs if missing or
# if present attempt to renew them
#
# WARNING:
# This script is called weekly from /etc/periodic/weekly/croncert.sh
#
# Duing the weekly check, if certs are renewed,
# the mosquitto process is restarted, causing
# a brief (few second) unavoidable service disruption
#
# If the environment varialbe TESTCERT is defined, this script
# will use --staging --test-cert for obtaining a cert and --dry-run for renewal
# This allows the user to test out the configuration and connectivity for obtaining
# certs without running into LetsEncrypt limits. It's advisable to define TESTCERT
# when initially bringing up the container. Once the logs (docker logs <containername>)
# show that LetsEncrypt is working fine, then remove TESTCERT environment variable
# to let this script obtain and manage the real certificates
#
FOLDER="/etc/letsencrypt/live/$DOMAIN"
echo "Dealing with certificates..."
echo "Location: $FOLDER"
if [ -d "$FOLDER" ]; then
echo "Certificates exist, attempting to renew..."
if [ ! -z "$TESTCERT" ]; then
echo "Renew dry run ..."
certbot renew --dry-run --noninteractive --post-hook "/restart.sh"
else
echo "Renew certs ..."
certbot renew --noninteractive --post-hook "/restart.sh"
fi
else
if [ ! -z "$DOMAIN" ]; then
if [ ! -z "$EMAIL" ]; then
if [ ! -z "$TESTCERT" ]; then
echo "Obtaining TEST cert for $DOMAIN"
certbot certonly \
--staging \
--test-cert \
--standalone \
--agree-tos \
--standalone-supported-challenges http-01 \
-n \
-d $DOMAIN \
-m $EMAIL
else
echo "Obtaining cert for $DOMAIN"
certbot certonly \
--standalone \
--agree-tos \
--standalone-supported-challenges http-01 \
-n \
-d $DOMAIN \
-m $EMAIL
fi
else
echo 'ERROR: $EMAIL must be defined'
fi
else
echo 'ERROR: $DOMAIN must be defined'
fi
fi