Skip to content

Instantly share code, notes, and snippets.

@PeeHaa

PeeHaa/le.sh Secret

Created April 19, 2016 09:03
Show Gist options
  • Save PeeHaa/f76129754c9e5282a96883f44b591b46 to your computer and use it in GitHub Desktop.
Save PeeHaa/f76129754c9e5282a96883f44b591b46 to your computer and use it in GitHub Desktop.
renew script
if [ -z "$1" ]; then
echo "Usage: renew_certificates [domain(s)] [docroot]";
exit 1;
fi;
if [ -z "$2" ]; then
echo "Usage: renew_certificates [domain(s)] [docroot]";
exit 1;
fi;
/etc/hosting/certificates/acme-client.phar check --name "$1"
# generate new certificates
/etc/hosting/certificates/acme-client.phar issue -d "$1" -p "$2" --user www-data
# Something unexpected happen and we could not renew.
if [ $? -ne 0 ]; then
printf "Subject: Certificate renewal failed!\n\nRenewal of certificate for $1 failed!" | /usr/sbin/sendmail support@me.com
exit 1;
fi
# Move previous certificates to the backup directory
mv /etc/ssl/"$1".pem /etc/ssl/backup/
mv /etc/ssl/"$1".private.pem /etc/ssl/backup/
# Move and rename the new certificates
cp /etc/hosting/certificates/data/certs/acme-v01.api.letsencrypt.org.directory/"$1"/fullchain.pem /etc/ssl/"$1".pem
cp /etc/hosting/certificates/data/certs/acme-v01.api.letsencrypt.org.directory/"$1"/key.pem /etc/ssl/"$1".private.pem
# Send mail to confirm certificates renewal
printf "Subject: Certificate renewal succeeded\n\nRenewal of certificate for $1 succeeded!" | /usr/sbin/sendmail support@me.com
# Test configuration and restart.
apachectl -k graceful
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment