diff --git a/certbotd.sh b/certbotd.sh index 5d4e2f7..5c04ddb 100755 --- a/certbotd.sh +++ b/certbotd.sh @@ -89,10 +89,27 @@ case $1 in 2>"${headers}" \ | jq --raw-output .[] \ | while read domain; do + if test -z "${domain}"; then + echo "not ok - domain is empty" >&2 + continue + fi + # Skip already existing domains - if test -f "/etc/letsencrypt/renewal/${domain}.conf"; then + if test -s "/etc/letsencrypt/renewal/${domain}.conf"; then echo "ok - ${domain} already issued" >&2 continue + else + echo "ok - ${domain} renewal conf was empty, fixing..." >&2 + + other_renewal="$(grep -l -m 1 "^authenticator = webroot$" /etc/letsencrypt/renewal/*.conf | head -1)" + + if test -z "${other_renewal}"; then + echo "not ok - ${domain} couldn't fix" >&2 + ensure 1 + fi + + other_domain="$(basename "${other_renewal}" .conf)" + sed -re "s/${other_domain}/${domain}/g" "${other_renewal}" > "/etc/letsencrypt/renewal/${domain}.conf" fi # Ignore non local domains