diff --git a/start.letsencrypt.sh b/start.letsencrypt.sh index 2adc024..c78bf68 100755 --- a/start.letsencrypt.sh +++ b/start.letsencrypt.sh @@ -2,6 +2,13 @@ email=$EMAIL +sending_error_msg() { + $1="DOMAIN" + $2="DATE" + + echo "there was unsucessfuly created "$DOMAIN" at date: "$DATE; +} + start_letsencrypt() { mkdir -p /acme.sh/$DOMAIN/ ; @@ -22,30 +29,37 @@ start_letsencrypt() { LETSENCRYPT_FILE=$(find /acme.sh/ -type f -name letsencrypt); if [ -n "$LETSENCRYPT_FILE" ] ; then DOMAIN=$(jq -r .DOMAIN $LETSENCRYPT_FILE) ; + DATE=$(date +%m%d%m%H) + echo $DATE start_letsencryp $DOMAIN; rm $LETSENCRYPT_FILE; - touch /acme.sh/$DOMAIN/renew_certificate; + + if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]] ; then + + if [[ "$(date -r /acme.sh/$DOMAIN/key.pem +%m%d%m%H)" == "$DATE" && "$(date -r /acme.sh/$DOMAIN/fullchain.pem +%m%d%m%H)" == "$DATE" && "$(date -r /acme.sh/$DOMAIN/cert.pem +%m%d%m%H)" == "$DATE" ]] ; then + + touch /acme.sh/$DOMAIN/new_certificate; + else + sending_error_msg $DOMAIN $DATE; + fi + fi else cd /domains for i in `ls` ; do DOMAIN=$(jq -r .DOMAIN $i) ; + DATE=$(date +%m%d%m%H) + echo $DATE + start_letsencrypt $DOMAIN; + if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]] ; then - start_letsencrypt $DOMAIN; - touch /acme.sh/$DOMAIN/renew_certificate; - else - start_letsencrypt; - if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]] ; then + + if [[ "$(date -r /acme.sh/$DOMAIN/key.pem +%m%d%m%H)" == "$DATE" && "$(date -r /acme.sh/$DOMAIN/fullchain.pem +%m%d%m%H)" == "$DATE" && "$(date -r /acme.sh/$DOMAIN/cert.pem +%m%d%m%H)" == "$DATE" ]] ; then + touch /acme.sh/$DOMAIN/new_certificate; - - else - while [[ ! -f /acme.sh/$DOMAIN/key.pem || ! -f /acme.sh/$DOMAIN/fullchain.pem || ! -f /acme.sh/$DOMAIN/cert.pem ]] ; do - sleep 10; - start_letsencrypt $DOMAIN; - if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]] ; then - touch /acme.sh/$DOMAIN/new_certificate; - fi - done + else + sending_error_msg $DOMAIN $DATE; fi + fi done ; fi