diff --git a/start.letsencrypt.sh b/start.letsencrypt.sh index 75704dc..b8486c8 100755 --- a/start.letsencrypt.sh +++ b/start.letsencrypt.sh @@ -59,33 +59,40 @@ start_letsencrypt() { LETSENCRYPT_INSTALLED=true fi - sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >$LOG_FILE 2>&1 - RESPONSE=$? - echo "OUTPOUT: $RESPONSE" - if [[ "$(echo $RESPONSE)" == "1" ]]; then + if [ -f /acme.sh/$DOMAIN/fullchain.pem ]; then + + ISSUER=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Issuer | cut -d '=' -f2) + SUBJECT=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Subject | cut -d '=' -f2) + + if [ "$ISSUER" == "$SUBJECT" ]; then + echo "Self signed certificate found" + sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >$LOG_FILE 2>&1 + RESPONSE=$? + echo "OUTPOUT: $RESPONSE" + fi + + else + sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >$LOG_FILE 2>&1 + RESPONSE=$? + echo "OUTPOUT: $RESPONSE" + fi + + if [[ "$(echo $RESPONSE)" == "1" && "$(cat $LOG_FILE | grep force)" == "" ]]; then for retries in $(seq 0 $((RESTART + 1))); do if [[ $retries -le $RESTART ]]; then - # Check certificate issuer - ISSUER=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Issuer | cut -d '=' -f2) - SUBJECT=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Subject | cut -d '=' -f2) - if [ "$ISSUER" == "$SUBJECT" ]; then - echo "Self signed certificate found" - sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >>$LOG_FILE 2>&1 - RESPONSE=$? - if [[ "$(echo $RESPONSE)" == "1" ]]; then - sleep $TIMEOUT - echo "Restarting number is only: "$retries" so try again" - else - echo "Created or renew successfuly the certificate for $DOMAIN" - echo "Creating log json from letsencrypt output" - STATUS=success - create_json $STATUS - break - fi - else + sh /root/.acme.sh/acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /acme.sh/$DOMAIN/cert.pem --key-file /acme.sh/$DOMAIN/key.pem --fullchain-file /acme.sh/$DOMAIN/fullchain.pem >>$LOG_FILE 2>&1 + RESPONSE=$? + if [ "$(echo $RESPONSE)" == "1" ]; then sleep $TIMEOUT echo "Restarting number is only: "$retries" so try again" + else + echo "Created or renew successfuly the certificate for $DOMAIN" + echo "Creating log json from letsencrypt output" + STATUS=success + create_json $STATUS + break fi + else echo "Reached retrying limit: "$RESTART" ,giving up" echo "Creating log json from letsencrypt output"