Last active
February 10, 2016 18:20
-
-
Save xorus/27d5fb2bdba94e80425c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| # 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