Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Created May 6, 2019 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongkongkiwi/bc19cf07094e07bbedf4de31ec24ff5f to your computer and use it in GitHub Desktop.
Save hongkongkiwi/bc19cf07094e07bbedf4de31ec24ff5f to your computer and use it in GitHub Desktop.
Rewnew LetsEncrypt Certificate using docker. I use this for a crontab script.
#!/bin/bash
DOMAIN="$1"
TYPE="$2"
if [[ "$DOMAIN" == "" ]]; then
echo "No domain passed e.g. example.com"
exit 1
fi
if [[ "$TYPE" == "" ]]; then
echo "No type passed e.g. digitalocean or cloudflare"
exit 1
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
if [[ "$TYPE" == "digitalocean" ]]; then
export DIGITALOCEAN_CREDS="${DIR}/do_creds.ini"
docker run \
-it --rm --name certbot \
-v "${DIGITALOCEAN_CREDS}:/root/.secrets/certbot/digitalocean.ini:ro" \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
"certbot/dns-digitalocean" \
certonly \
--keep \
--quiet \
--preferred-challenges dns-01 \
--agree-tos \
--dns-digitalocean \
--dns-digitalocean-credentials ~/.secrets/certbot/digitalocean.ini \
-d "$DOMAIN"
elif [[ "$TYPE" == "cloudflare" ]]; then
export CLOUDFLARE_CREDS="${DIR}/cf_creds.ini"
docker run \
-it --rm --name certbot \
-v "${CLOUDFLARE_CREDS}:/root/.secrets/certbot/cloudflare.ini:ro" \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
certbot/dns-cloudflare \
certonly \
--keep \
--quiet \
--preferred-challenges dns-01 \
--agree-tos \
--dns-cloudflare \
--dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
-d "$DOMAIN"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment