Refactor start.letsencrypt.sh to update file paths for certificate handling
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
gyurix
2025-03-29 22:55:27 +01:00
parent 7274cab64f
commit 8fa324553d

View File

@@ -60,16 +60,16 @@ start_letsencrypt() {
fi fi
cd /root/.acme.sh cd /root/.acme.sh
chmod a+x ./acme.sh chmod a+x ./acme.sh
RESPONSE=$(./acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /etc/ssl/keys/$DOMAIN/cert.pem --key-file /etc/ssl/keys/$DOMAIN/key.pem --fullchain-file /etc/ssl/keys/$DOMAIN/fullchain.pem >$LOG_FILE) RESPONSE=$(./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)
if [[ "$(echo $?)" == "1" ]]; then if [[ "$(echo $?)" == "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
# Check certificate issuer # Check certificate issuer
ISSUER=$(openssl x509 -in /etc/ssl/keys/$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 /etc/ssl/keys/$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"
RESPONSE=$(./acme.sh $L_S $EK $EHK --issue --standalone --keylength 4096 -d $DOMAIN --cert-file /etc/ssl/keys/$DOMAIN/cert.pem --key-file /etc/ssl/keys/$DOMAIN/key.pem --fullchain-file /etc/ssl/keys/$DOMAIN/fullchain.pem >>$LOG_FILE) RESPONSE=$(./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)
if [[ "$(echo $?)" != "1" ]]; then if [[ "$(echo $?)" != "1" ]]; then
sleep $TIMEOUT sleep $TIMEOUT
echo "Restarting number is only: "$retries" so try again" echo "Restarting number is only: "$retries" so try again"
@@ -96,20 +96,20 @@ start_letsencrypt() {
check_new_cert() { check_new_cert() {
#DATE=$(date +%s) #DATE=$(date +%s)
if [[ -f /etc/ssl/keys/$DOMAIN/key.pem && -f /etc/ssl/keys/$DOMAIN/fullchain.pem && -f /etc/ssl/keys/$DOMAIN/cert.pem ]]; then if [[ -f /acme.sh/$DOMAIN/key.pem && -f /acme.sh/$DOMAIN/fullchain.pem && -f /acme.sh/$DOMAIN/cert.pem ]]; then
#D1=$(date -r /etc/ssl/keys/$DOMAIN/fullchain.pem +%s) #D1=$(date -r /acme.sh/$DOMAIN/fullchain.pem +%s)
#DIFF=$(expr $DATE - $D1); #DIFF=$(expr $DATE - $D1);
#if [ $DIFF < 3600 ]; then touch /etc/ssl/keys/$DOMAIN/new_certificate; fi #if [ $DIFF < 3600 ]; then touch /acme.sh/$DOMAIN/new_certificate; fi
NEW=$(openssl x509 -in /etc/ssl/keys/$DOMAIN/fullchain.pem -fingerprint -noout) NEW=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
if [ "$ORIGINAL" != "$NEW" ]; then if [ "$ORIGINAL" != "$NEW" ]; then
touch /etc/ssl/keys/$DOMAIN/new_certificate touch /acme.sh/$DOMAIN/new_certificate
fi fi
else else
sending_error_msg $DOMAIN $DATE sending_error_msg $DOMAIN $DATE
fi fi
} }
LETSENCRYPT_FILES=$(find /etc/ssl/keys/ -type f -name letsencrypt) LETSENCRYPT_FILES=$(find /acme.sh/ -type f -name letsencrypt)
echo "letsencrypt files exist" echo "letsencrypt files exist"
if [ "$DOMAIN" != "localhost" ]; then if [ "$DOMAIN" != "localhost" ]; then