Created
November 10, 2017 09:48
-
-
Save joltcan/cdc86e657e6c9a89ea58b9d34c03aa74 to your computer and use it in GitHub Desktop.
This file contains 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 | |
admin="<email>" | |
site="<the site we need a cert for>" | |
dest="/etc/nginx/certs" | |
remote_file="https://acme.int.<domain>/$site/fullchain.cer" | |
local_file="$dest/$site-fullchain.cer" | |
# create local file if it doesnt exist | |
[ -f $local_file ] || touch -t 8001031305 $local_file | |
# get the potential new cert | |
modified=$(curl --silent --head $remote_file | \ | |
awk '/^Last-Modified/{print $0}' | \ | |
sed 's/^Last-Modified: //') | |
remote_ctime=$(date --date="$modified" +%s) | |
local_ctime=$(stat -c %Y "$local_file") | |
if [ $local_ctime -lt $remote_ctime ] ; then | |
curl -Ls https://acme.int.flattr.net/$site/fullchain.cer -o $dest/$site-fullchain.cer | |
curl -Ls https://acme.int.flattr.net/$site/$site.key -o $dest/$site-fullchain.key | |
nginx -t > /dev/null 2>&1 | |
#reload nginx if success | |
[ $? -eq 0 ] && service nginx reload || echo "error updating $site with le-acme" | mail -s "Error doing letsencrypt on $site" "$admin" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment