diff --git a/cm.sh b/cm.sh index dc1ce0060faf91cb123792f317780f805b3aa73f..b560bcfd54d982b7718e18e02e456d97e4afb72e 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 }