2017-01-20 02:17:56 +00:00
|
|
|
error() {
|
|
|
|
(set +x; tput -Tscreen bold
|
|
|
|
tput -Tscreen setaf 1
|
|
|
|
echo $*
|
|
|
|
tput -Tscreen sgr0) >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "$DOMAINS" ]; then
|
|
|
|
error "DOMAINS environment variable undefined; certbot will do nothing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$EMAIL" ]; then
|
|
|
|
error "EMAIL environment variable undefined; certbot will do nothing"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo "Running certbot for domains $DOMAINS for user $EMAIL..."
|
2016-09-21 23:35:19 +00:00
|
|
|
|
2016-11-19 21:22:07 +00:00
|
|
|
get_certificate() {
|
2017-01-20 01:42:04 +00:00
|
|
|
# Gets the certificate for the domain(s) CERT_DOMAINS (a comma separated list)
|
|
|
|
# The certificate will be named after the first domain in the list
|
|
|
|
# To work, the following variables must be set:
|
|
|
|
# - CERT_DOMAINS : comma separated list of domains
|
|
|
|
# - EMAIL
|
2016-11-19 21:22:07 +00:00
|
|
|
|
2017-01-20 01:42:04 +00:00
|
|
|
local d=${CERT_DOMAINS//,*/} # read first domain
|
|
|
|
echo "Getting certificate for $CERT_DOMAINS"
|
|
|
|
certbot certonly --agree-tos --keep -n --text --email $EMAIL --server \
|
|
|
|
https://acme-v01.api.letsencrypt.org/directory -d $CERT_DOMAINS \
|
|
|
|
--standalone --standalone-supported-challenges http-01 --debug
|
|
|
|
ec=$?
|
|
|
|
echo "certbot exit code $ec"
|
|
|
|
if [ $ec -eq 0 ]; then
|
2017-01-20 02:17:56 +00:00
|
|
|
error "Certificates for $CERT_DOMAINS can be found in /etc/letsencrypt/live/$d"
|
2017-01-20 01:42:04 +00:00
|
|
|
else
|
2017-01-20 02:17:56 +00:00
|
|
|
error "Cerbot failed for $CERT_DOMAINS. Check the logs for details."
|
|
|
|
exit 1
|
2017-01-20 01:42:04 +00:00
|
|
|
fi
|
2016-11-19 21:22:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-20 02:17:56 +00:00
|
|
|
exit_code=0
|
2017-01-02 05:34:59 +00:00
|
|
|
set -x
|
2017-01-20 02:17:56 +00:00
|
|
|
for d in $DOMAINS; do
|
|
|
|
CERT_DOMAINS=$d
|
|
|
|
if ! get_certificate; then
|
|
|
|
exit_code=1
|
|
|
|
fi
|
2017-01-20 01:42:04 +00:00
|
|
|
done
|
2017-01-20 02:17:56 +00:00
|
|
|
exit $exit_code
|