Created
November 26, 2017 22:11
-
-
Save excalq/f4b757d08294ccd9c440d4377945b217 to your computer and use it in GitHub Desktop.
A Bash Script to Manage Creation & Renewal of Lets Encrypt Certificates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Klassica LetsEncrypt Generate/Autorenew Tool | |
# Pass an argument: create, renew | |
DOMAINS=("klassica.com" "www.klassica.com" "blog.klassica.com") | |
DRY_RUN="--dry-run --staging" # Comment out to run for real! | |
LE_DIR="/data/site-tools/letsencrypt/" | |
WEBROOT_DIR="/data/web/klassica.com/" | |
case "$1" in | |
# Note: This has to be run each time a subdomain is added or removed! | |
'create') | |
echo "Creating new LE certs for ${DOMAINS[@]}..." | |
certbot certonly ${DRY_RUN} --config-dir "$LE_DIR"/etc/ --work-dir "$LE_DIR"/var --logs-dir "$LE_DIR"/log --webroot -w "$WEBROOT_DIR" "${DOMAINS[@]/#/-d }" | |
;; | |
'renew') | |
echo "Renewing LE certs for ${DOMAINS[@]}..." | |
certbot renew --quiet ${DRY_RUN} --config-dir "$LE_DIR"/etc/ --work-dir "$LE_DIR"/var --logs-dir "$LE_DIR"/log | |
;; | |
*) | |
echo "Error: I don't understand the argument '$1'. Try 'create' or 'renew'." 1>&2; | |
exit -1 | |
;; | |
esac | |
if [ $? -eq 0 ]; then | |
[ -t 1 ] && echo 'Restarting NGINX Web Server.' ## Silent if via cron | |
sudo nginx -qt && sudo /usr/sbin/service nginx restart >/dev/null | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment