From 1e76d8071cacc441bfc8aa6c5689d0fc52d7d6df Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Thu, 11 Feb 2021 08:17:19 +0100 Subject: [PATCH] update renew: exit code 0 if renew was skipped --- cm.sh | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/cm.sh b/cm.sh index dc1ce00..b560bcf 100755 --- a/cm.sh +++ b/cm.sh @@ -44,11 +44,16 @@ function _listCerts(){ $ACME --list } +# internal function; get a list of fqdn of all existing certs +function _listCertdomains(){ + _listCerts | sed -n '2,$p' | awk '{ print $1 }' +} + # internal function; checks if a certificate for a given FQDN already exists # used in _certMustExist, _certMustNotExist # param string FQDN function _certExists(){ - _listCerts | awk '{ print $1 }' | grep "^${CM_fqdn}$" >/dev/null + _listCertdomains | grep "^${CM_fqdn}$" >/dev/null } # internal function; a certificate of a given FQDN must exist - otherwise @@ -306,30 +311,34 @@ function public_list(){ function public_renew(){ _requiresFqdn _certMustExist - $ACME --renew -d ${CM_fqdn} $ACME_Params || exit 2 - - _certTransfer - _certMatching + $ACME --renew -d ${CM_fqdn} $ACME_Params + local _rc=$? - _update "renewed ${CM_fqdn}" + case $_rc in + 0) + _certTransfer + _certMatching + _update "renewed ${CM_fqdn}" + ;; + 2) + _wd "renew was skipped ... we need to wait a while." + ;; + *) + _wd "Error ocured." + exit $_rc + esac } # -# public function - renew al certificates (to be used in cronjon) +# public function - renew all certificates (to be used in a cronjob) # no params function public_renew-all(){ - _listCerts | sed -n '2,$p' | awk '{ print $1 }' | while read mydomain + _listCertdomains | while read mydomain do _wd "--- renew $mydomain" _setenv ${mydomain} - $ACME --renew -d ${CM_fqdn} $ACME_Params - if [ $? -eq 0 ]; then - _certTransfer - _certMatching - _update "renewed ${CM_fqdn}" - fi - + public_renew done } -- GitLab