Skip to content

Instantly share code, notes, and snippets.

@eniac111
Created December 27, 2015 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eniac111/c7146b3e59c7eff27fbe to your computer and use it in GitHub Desktop.
Save eniac111/c7146b3e59c7eff27fbe to your computer and use it in GitHub Desktop.
#!/bin/bash
########################################################################
## Script for updating Let's encrypt certs
## http://petrovs.info/2015/12/27/My-way-to-auto-update-Lets-Encrypt/
## (C) 2015 Blagovest Petrov (blagovest <at> petrovs dot info)
## Released under the GPL
########################################################################
cd /etc/letsencrypt/live
for DIRS in *; do
if ssl-cert-check -c $DIRS/fullchain.pem | grep -q "Valid"; then
echo On `date`, $DIRS is Valid. >> /var/log/letsencrypt-update.log
#cat $DIRS/fullchain.pem > /srv/certs/$DIRS.pem
#cat $DIRS/privkey.pem >> /srv/certs/$DIRS.pem
else
echo On `date`, $DIRS is NOT Valid. Generating a new certificate from Let\'s encrypt... >> /var/log/letsencrypt-update.log
/root/letsencrypt/letsencrypt-auto --email it@veriosoft.com -d $DIRS --authenticator standalone --tls-sni-01-port 63443 --renew-by-default --text auth --http-01-port 8099 >> /var/log/letsencrypt-update.log
echo Generating fullchain token for $DIRS to be used for HAProxy... >> /var/log/letsencrypt-update.log
cat $DIRS/fullchain.pem > /srv/certs/$DIRS.pem
cat $DIRS/privkey.pem >> /srv/certs/$DIRS.pem
echo Reloading the HAProxy configuration... >> /var/log/letsencrypt-update.log
service haproxy reload
echo Done :\) >> /var/log/letsencrypt-update.log
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment