From 7c705f3fb29e6a81665f82cece809195861231fe Mon Sep 17 00:00:00 2001 From: Eric F Crist Date: Thu, 31 Jan 2019 23:17:26 -0600 Subject: [PATCH] Better date support for BSD/GNU Signed-off-by: Eric F Crist --- easyrsa3/easyrsa | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/easyrsa3/easyrsa b/easyrsa3/easyrsa index ebb6d9f..2de1e3e 100755 --- a/easyrsa3/easyrsa +++ b/easyrsa3/easyrsa @@ -1010,9 +1010,17 @@ at: $crt_in" "$EASYRSA_OPENSSL" x509 -in "$crt_in" -noout -enddate | sed 's/^notAfter=//' ) - expire_date=$(date -d "$expire_date" +%s) - - allow_renew_date=$(date -d "+${EASYRSA_CERT_RENEW}day" +%s) + case $(uname) in + "Darwin"|*"BSD") + expire_date=$(date -j -f '%b %d %T %Y %Z' "$expire_date" +%s) + allow_renew_date=$(date -j -v"+${EASYRSA_CERT_RENEW}d" +%s) + ;; + *) + # This works on Windows, too, since uname doesn't exist and this is catch-all + expire_date=$(date -d "$expire_date" +%s) + allow_renew_date=$(date -d "+${EASYRSA_CERT_RENEW}day" +%s) + ;; + esac [ "$expire_date" -lt "$allow_renew_date" ] || die "\ Certificate expires in more than $EASYRSA_CERT_RENEW days.