use domains private key file as timestamp

This commit is contained in:
Bruno Zell 2018-10-03 05:31:43 +02:00
parent a1104ffceb
commit 642614cdad
2 changed files with 4 additions and 14 deletions

View File

@ -16,10 +16,7 @@ for domain in $(parse_domains); do
if is_renewal_required $domain; then
# Renewal required for this doman.
# Last one happened over a week ago (or never)
if get_certificate $domain $CERTBOT_EMAIL; then
# Renewal successful. Update timestamp...
update_renewal_timestamp $domain
else
if ! get_certificate $domain $CERTBOT_EMAIL; then
error "Cerbot failed for $domain. Check the logs for details."
exit_code=1
fi

View File

@ -80,8 +80,8 @@ get_certificate() {
# ran over a week ago or never happened yet), otherwise return false.
is_renewal_required() {
# If the file does not exist assume a renewal is required
last_renewal_file="/etc/letsencrypt/$1_last_renewal.txt"
[[ ! -e "$last_renewal_file" ]] && return;
last_renewal_file="/etc/letsencrypt/live/$1/privkey.pem"
[ ! -e "$last_renewal_file" ] && return;
# If the file exists, check if the last renewal was more than a week ago
one_week_sec=604800
@ -89,12 +89,5 @@ is_renewal_required() {
last_renewal_sec=$(stat -c %Y "$last_renewal_file")
last_renewal_delta_sec=$(( ($now_sec - $last_renewal_sec) ))
is_finshed_week_sec=$(( ($one_week_sec - $last_renewal_delta_sec) ))
[[ $is_finshed_week_sec -lt 0 ]]
}
# Given a domain name, set the current time as the last renewal timestamp
# as read by is_renewal_required().
update_renewal_timestamp() {
last_renewal_file="/etc/letsencrypt/$1_last_renewal.txt"
touch "$last_renewal_file"
[ $is_finshed_week_sec -lt 0 ]
}