|if [ ! -f $config_file ]; then|
|echo "[ERROR] config file does not exist: $config_file"|
|domain=`grep "^\s*domains" $config_file | sed "s/^\s*domains\s*=\s*//" | sed 's/(\s*)\|,.*$//'`|
|if [ ! -f $cert_file ]; then|
|echo "[ERROR] certificate file not found for domain $domain."|
|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..."|
|if [ "$days_exp" -gt "$exp_limit" ] ; then|
|echo "The certificate is up to date, no need for renewal ($days_exp days left)."|
|echo "The certificate for $domain is about to expire soon. Starting webroot renewal script..."|
|$le_path/letsencrypt-auto certonly -a webroot --agree-tos --renew-by-default --config $config_file|
|echo "Reloading $web_service"|
|/usr/sbin/service $web_service reload|
|echo "Renewal process finished for domain $domain"|
|# This is an example of the kind of things you can do in a configuration file.|
|# All flags used by the client can be configured here. Run Let's Encrypt with|
|# "--help" to learn more about the available options.|
|# Use a 4096 bit RSA key instead of 2048|
|rsa-key-size = 4096|
|# Always use the staging/testing server|
|# server = https://acme-staging.api.letsencrypt.org/directory|
|# Uncomment and update to register with the specified e-mail address|
|email = email@example.com|
|# Uncomment and update to generate certificates for the specified|
|domains = example.com, www.example.com|
|# Uncomment to use a text interface instead of ncurses|
|# text = True|
|# Uncomment to use the standalone authenticator on port 443|
|# authenticator = standalone|
|# standalone-supported-challenges = tls-sni-01|
|# Uncomment to use the webroot authenticator. Replace webroot-path with the|
|# path to the public_html / webroot folder being served by your web server.|
|# authenticator = webroot|
|webroot-path = /usr/share/nginx/html|
Quick 'fix' to handle multiple domains/configfiles:
if [ "$1" == "" ]; then config_file="/usr/local/etc/le-renew-webroot.ini"
If no commandline parameter is received, the script works as before with configfile /usr/local/etc/le-renew-webroot.ini
I'm also using a purely space-seperated list of domains in my config file and the second sed on line 14 did not properly match and cut ..
edit: nevermind .. apparently the letsencrypt-auto itself hiccups on a space-seperated list. I'll just use commas then ..
Thanks for the script and the tutorial!
Very Nice code tahnks.
For some reason I'm getting the following output immediately when running the script
And it doesn't seem to have worked because every time I run it, It tells me it's about to expire soon
Apparently I had a trailing space after my domain in the le-renew-webroot file. Next time I ran it, it said the cert is up to date, woo!
Nice script, but I don't understand why you call it plural - domains. It gives the impression of checking multiple domains and running the command for each of them, which is not the case. Sed 4.2.2 returns first domain only and discards the rest.
In its current form it is not all that useful as you have to run the program for several domains individually, contrary to ambiguous plural name. Would be very nice to rework it to support array of domains taken from the config file and to run the procedure on all of them.