Skip to content

Instantly share code, notes, and snippets.

@xorus
Last active February 10, 2016 18:20
Show Gist options
  • Select an option

  • Save xorus/27d5fb2bdba94e80425c to your computer and use it in GitHub Desktop.

Select an option

Save xorus/27d5fb2bdba94e80425c to your computer and use it in GitHub Desktop.
#!/bin/bash
# https://gist.github.com/xorus/8bd4c7c54d01908af37e
certsFolder=/etc/letsencrypt/live
certName=cert.pem
expirationDays=14
letsencryptCmd='/opt/letsencrypt/letsencrypt-auto --config /etc/letsencrypt/cli.ini'
expirationDelay=$((60*60*24*$expirationDays))
toRenew=()
for folder in $(ls $certsFolder); do
certPath=$certsFolder/$folder/$certName
if ! openssl x509 -checkend $expirationDelay -noout -in $certPath
then
toRenew+=($folder)
fi
done
for domain in ${toRenew[@]}; do
echo renewing $domain
$letsencryptCmd -d $domain certonly
rc=$?
if [[ $rc != 0 ]]; then
echo Something went wrong
exit
fi
done
service nginx reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment