-
-
Save revelt/1cfef1092d044373ad61 to your computer and use it in GitHub Desktop.
Let's encrypt auto authenticator runner for multiply domains
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 | |
#Vars | |
web_service='nginx' | |
config_path='/usr/local/letssl/' | |
le_path='/opt/letsencrypt' | |
exp_limit=20; | |
#Func | |
function check_ssl { | |
echo $1 | |
if [ -f $1 ]; then | |
#find domain | |
domain=`grep "^\s*domains" $1 | sed "s/^\s*domains\s*=\s*//" | sed 's/(\s*)\|,.*$//'` | |
cert_file="/etc/letsencrypt/live/$domain/fullchain.pem" | |
#check if cert exist | |
if [ ! -f $cert_file ]; then | |
echo "[ERROR] certificate file not found for domain $domain." | |
fi | |
#get exp date | |
exp=$(date -d "`openssl x509 -in $cert_file -text -noout|grep "Not After"|cut -c 25-`" +%s) | |
datenow=$(date -d "now" +%s) | |
days_exp=$(echo \( $exp - $datenow \) / 86400 |bc) | |
echo "Checking expiration date for $domain..." | |
#check exp date | |
if [ "$days_exp" -gt "$exp_limit" ] ; then | |
echo "The certificate is up to date, no need for renewal ($days_exp days left)." | |
else | |
echo "The certificate for $domain is about to expire soon. Starting webroot renewal script..." | |
#update cert | |
$le_path/letsencrypt-auto certonly -a webroot --agree-tos --renew-by-default --config $1 | |
#reload webserver | |
echo "Reloading $web_service" | |
/usr/sbin/service $web_service reload | |
#done | |
echo "Renewal process finished for domain $domain" | |
fi | |
else | |
echo "[ERROR] config file does not exist: $1" | |
fi | |
} | |
#loop | |
configs="$config_path*.ini" | |
for f in $configs | |
do | |
#echo $f | |
check_ssl $f | |
done | |
exit 0; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment