email now optional, and wildcard defaults to false

This commit is contained in:
Maksim 2019-12-10 23:38:25 +11:00
parent 00cc1484a3
commit aa97821190
3 changed files with 25 additions and 19 deletions

View file

@ -4,10 +4,10 @@ Automatically generates Let's Encrypt certificates using a lightweight Docker co
Variables: Variables:
* `DUCKDNS_TOKEN`: Duck DNS Account Token * `DUCKDNS_TOKEN`: Duck DNS account token (obtained from [Duck DNS](https://www.duckdns.org))
* `DUCKDNS_DOMAIN`: Full Duck DNS domain (e.g. `test.duckdns.org`) * `DUCKDNS_DOMAIN`: Full Duck DNS domain (e.g. `test.duckdns.org`)
* `LETSENCRYPT_EMAIL`: Email used for certificate renewal notifications (optional) * `LETSENCRYPT_EMAIL`: Email used for certificate renewal notifications (optional)
* `LETSENCRYPT_WILDCARD`: `true` or `false`, indicating whether the SSL certificate should be for all subdomains of `DUCKDNS_DOMAIN` (i.e. `*.test.duckdns.org`), or just the main domain (i.e. `test.duckdns.org`) * `LETSENCRYPT_WILDCARD`: `true` or `false`, indicating whether the SSL certificate should be for all subdomains of `DUCKDNS_DOMAIN` (i.e. `*.test.duckdns.org`), or just the main domain (i.e. `test.duckdns.org`) (default: `false`)
**Note:** The format of `DUCKDNS_DOMAIN` should be the same regardless of the value of `LETSENCRYPT_WILDCARD`. **Note:** The format of `DUCKDNS_DOMAIN` should be the same regardless of the value of `LETSENCRYPT_WILDCARD`.
@ -17,5 +17,5 @@ Volumes:
**Note:** If a hosted volume is used, the volume should be mounted in an unused directory in another container to prevent access conflicts. **Note:** If a hosted volume is used, the volume should be mounted in an unused directory in another container to prevent access conflicts.
#### TODO: ### TODO:
* Implement tests so `depends_on` can be used in docker-compose to prevent other containers from initialising until certificates are ready * Implement tests so `depends_on` can be used in docker-compose to prevent other containers from initialising until certificates are ready

View file

@ -1,16 +1,26 @@
#!/bin/sh #!/bin/sh
# TODO: Make email an optional parameter if [ -z "$LETSENCRYPT_EMAIL" ]; then
# Check what happens when both -m and registration without email are supplied export EMAIL_PARAM="--register-unsafely-without-email"
else
export EMAIL_PARAM="-m ${LETSENCRYPT_EMAIL} --no-eff-email"
fi
if [ ! -z "$TESTING" ]; then
echo NOTICE: Generating staging certificate
export TEST_PARAM="--staging"
fi
# Initial check for certificates # Initial check for certificates
certbot certonly --manual --preferred-challenges dns --manual-auth-hook \ certbot certonly --manual --preferred-challenges dns --manual-auth-hook \
/scripts/auth.sh --manual-cleanup-hook /scripts/cleanup.sh \ /scripts/auth.sh --manual-cleanup-hook /scripts/cleanup.sh \
-m "${LETSENCRYPT_EMAIL}" --no-eff-email -d "${LETSENCRYPT_DOMAIN}" \ "${EMAIL_PARAM}" -d "${LETSENCRYPT_DOMAIN}" \
--agree-tos --manual-public-ip-logging-ok --keep --agree-tos --manual-public-ip-logging-ok --keep ${TEST_PARAM}
# Basic check for successful certificate generation # Basic check for successful certificate generation
if [ ! -d "/etc/letsencrypt/live" ]; then if [ ! -d "/etc/letsencrypt/live/${LETSENCRYPT_DOMAIN}" ] || \
[ ! -f "/etc/letsencrypt/live/${LETSENCRYPT_DOMAIN}/fullchain.pem" ] || \
[ ! -f "/etc/letsencrypt/live/${LETSENCRYPT_DOMAIN}/privkey.pem" ]; then
echo ERROR: Failed to create SSL certificates echo ERROR: Failed to create SSL certificates
exit 1 exit 1
fi fi

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# Check variables DUCKDNS_TOKEN, DUCKDNS_DOMAIN, LETSENCRYPT_EMAIL, LETSENCRYPT_WILDCARD # Check variables DUCKDNS_TOKEN, DUCKDNS_DOMAIN
if [ -z "$DUCKDNS_TOKEN" ]; then if [ -z "$DUCKDNS_TOKEN" ]; then
echo ERROR: Variable DUCKDNS_TOKEN is unset echo ERROR: Variable DUCKDNS_TOKEN is unset
exit 1 exit 1
@ -11,30 +11,26 @@ if [ -z "$DUCKDNS_DOMAIN" ]; then
exit 1 exit 1
fi fi
if [ -z "$LETSENCRYPT_WILDCARD" ]; then # Print email notice if applicable
echo ERROR: Variable LETSENCRYPT_WILDCARD is unset
exit 1
fi
if [ -z "$LETSENCRYPT_EMAIL" ]; then if [ -z "$LETSENCRYPT_EMAIL" ]; then
echo NOTICE: You will not receive SSL certificate expiration notices echo NOTICE: You will not receive SSL certificate expiration notices
fi fi
# Set certificate url based on LETSENCRYPT_WILDCARD value # Set certificate url based on LETSENCRYPT_WILDCARD value
if [ "$LETSENCRYPT_WILDCARD" = "true" ]; then if [ "$LETSENCRYPT_WILDCARD" = "true" ]; then
echo NOTICE: A wildcard SSL certificate will be created
export LETSENCRYPT_DOMAIN=*.${DUCKDNS_DOMAIN} export LETSENCRYPT_DOMAIN=*.${DUCKDNS_DOMAIN}
elif [ "$LETSENCRYPT_WILDCARD" = "false" ]; then export WILDCARD_STR="true"
export LETSENCRYPT_DOMAIN=${DUCKDNS_DOMAIN}
else else
echo ERROR: Invalid value for LETSENCRYPT_WILDCARD export LETSENCRYPT_DOMAIN=${DUCKDNS_DOMAIN}
exit 1 export WILDCARD_STR="false"
fi fi
# Print variables # Print variables
echo DUCKDNS_TOKEN: $DUCKDNS_TOKEN echo DUCKDNS_TOKEN: $DUCKDNS_TOKEN
echo DUCKDNS_DOMAIN: $DUCKDNS_DOMAIN echo DUCKDNS_DOMAIN: $DUCKDNS_DOMAIN
echo LETSENCRYPT_EMAIL: $LETSENCRYPT_EMAIL echo LETSENCRYPT_EMAIL: $LETSENCRYPT_EMAIL
echo LETSENCRYPT_WILDCARD: $LETSENCRYPT_WILDCARD echo LETSENCRYPT_WILDCARD: $WILDCARD_STR \(Input: \"${LETSENCRYPT_WILDCARD}\"\)
# Start automatic ssl certificate generation # Start automatic ssl certificate generation
/bin/sh /scripts/cert.sh /bin/sh /scripts/cert.sh