Refactor start.letsencrypt.sh to improve certificate renewal logic and streamline response handling
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -60,29 +60,27 @@ start_letsencrypt() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f /acme.sh/$DOMAIN/fullchain.pem ]; 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)
|
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)
|
SUBJECT=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -text -noout | grep -w CN | grep Subject | cut -d '=' -f2)
|
||||||
|
|
||||||
if [ "$ISSUER" == "$SUBJECT" ]; then
|
if [ "$ISSUER" == "$SUBJECT" ]; then
|
||||||
echo "Self signed certificate found"
|
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
|
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=$?
|
else
|
||||||
echo "OUTPOUT: $RESPONSE"
|
sh /root/.acme.sh/acme.sh $L_S $EK $EHK --renew --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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
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
|
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
|
fi
|
||||||
|
|
||||||
if [[ "$(echo $RESPONSE)" == "1" && "$(cat $LOG_FILE | grep force)" == "" ]]; then
|
RESPONSE=$?
|
||||||
|
echo "OUTPOUT: $RESPONSE"
|
||||||
|
|
||||||
|
if [ "$(echo $RESPONSE)" == "1" ]; then
|
||||||
for retries in $(seq 0 $((RESTART + 1))); do
|
for retries in $(seq 0 $((RESTART + 1))); do
|
||||||
if [[ $retries -le $RESTART ]]; then
|
if [[ $retries -le $RESTART ]]; then
|
||||||
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
|
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=$?
|
RESPONSE=$?
|
||||||
if [ "$(echo $RESPONSE)" == "1" ]; then
|
if [[ "$(echo $RESPONSE)" == "1" && "$(cat $LOG_FILE | grep force)" == "" ]]; then
|
||||||
sleep $TIMEOUT
|
sleep $TIMEOUT
|
||||||
echo "Restarting number is only: "$retries" so try again"
|
echo "Restarting number is only: "$retries" so try again"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user