diff options
author | Florian Pritz <bluewind@xinu.at> | 2016-01-05 19:30:57 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2016-01-05 19:30:57 +0100 |
commit | e9d04b9993f78e9126c0ac4bee984add5385a73d (patch) | |
tree | 645fbf1bc1c6aa712dea010a4e7bda1d50309393 | |
parent | 124a94b1946f49505c056bd3e6baf58cf4ec5314 (diff) | |
download | bin-e9d04b9993f78e9126c0ac4bee984add5385a73d.tar.gz bin-e9d04b9993f78e9126c0ac4bee984add5385a73d.tar.xz |
Add certrenew
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-x | certrenew | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/certrenew b/certrenew new file mode 100755 index 0000000..8d696fa --- /dev/null +++ b/certrenew @@ -0,0 +1,34 @@ +#!/bin/bash + +set -e + +main() { + if [[ ! -d /etc/letsencrypt/live ]]; then + die "no letsencrypt dir found" + fi + + if (($#<2)); then + printf "usage: %s <webroot> <domains ...>\n" "${0##*/}" + exit 1 + fi + + local webroot=$1; shift; + local -a domains=("$@") + + local cert="/etc/letsencrypt/live/${domains[0]}/cert.pem" + + # renew if expires within 8 weeks + if ! openssl x509 -noout -checkend $((8*7*86400)) -in "${cert}"; then + letsencrypt certonly --email bluewind@xinu.at --agree-tos --renew-by-default --webroot -w "$webroot" "${domains[@]/#/-d }" + fi + + return 0 +} + +die() { + printf "%s\n" "$1" >&2 + exit 1 +} + +main "$@" + |