Refactor start.letsencrypt.sh to improve domain handling and installation checks
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
gyurix
2025-03-29 22:50:01 +01:00
parent 3f2d75c086
commit 7274cab64f

View File

@@ -54,7 +54,10 @@ create_json() {
start_letsencrypt() { start_letsencrypt() {
cd /root cd /root
curl https://get.acme.sh | sh -s email=$EMAIL if [ "$LETSENCRYPT_INSTALLED" == "true" ]; then
curl https://get.acme.sh | sh -s email=$EMAIL
LETSENCRYPT_INSTALLED=true
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 /etc/ssl/keys/$DOMAIN/cert.pem --key-file /etc/ssl/keys/$DOMAIN/key.pem --fullchain-file /etc/ssl/keys/$DOMAIN/fullchain.pem >$LOG_FILE)
@@ -106,7 +109,9 @@ check_new_cert() {
fi fi
} }
LETSENCRYPT_FILE=$(find /etc/ssl/keys/ -type f -name letsencrypt) LETSENCRYPT_FILES=$(find /etc/ssl/keys/ -type f -name letsencrypt)
echo "letsencrypt files exist"
if [ "$DOMAIN" != "localhost" ]; then if [ "$DOMAIN" != "localhost" ]; then
if [ ! -f $LETSENCRYPT_OUTPUT ]; then if [ ! -f $LETSENCRYPT_OUTPUT ]; then
install -m 664 -g 65534 /dev/null $LETSENCRYPT_OUTPUT install -m 664 -g 65534 /dev/null $LETSENCRYPT_OUTPUT
@@ -114,29 +119,42 @@ if [ "$DOMAIN" != "localhost" ]; then
fi fi
if [ "$DOMAIN" != "" ]; then if [ "$DOMAIN" != "" ]; then
ORIGINAL=$(openssl x509 -in /etc/ssl/keys/$DOMAIN/fullchain.pem -fingerprint -noout) echo "DOMAIN: $DOMAIN"
echo "domain exists"
ORIGINAL=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
if [ "$DOMAIN" != "localhost" ]; then if [ "$DOMAIN" != "localhost" ]; then
start_letsencrypt start_letsencrypt
check_new_cert check_new_cert
fi fi
elif [ -n "$LETSENCRYPT_FILE" ]; then elif [ -n "$LETSENCRYPT_FILES" ]; then
DOMAINS=$(jq -r .DOMAIN $LETSENCRYPT_FILE) for LETSENCRYPT_FILE in $(echo $LETSENCRYPT_FILES); do
for DOMAIN in $(echo $DOMAINS); do DOMAIN=$(jq -r .DOMAIN $LETSENCRYPT_FILE)
ORIGINAL=$(openssl x509 -in /etc/ssl/keys/$DOMAIN/fullchain.pem -fingerprint -noout) echo "DOMAIN: $DOMAIN"
start_letsencrypt $DOMAIN for DOMAIN in $(echo $DOMAIN); do
check_new_cert ORIGINAL=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
start_letsencrypt $DOMAIN
check_new_cert
DOMAIN=""
done
done done
else else
cd /domains DOMAIN_FILE=""
for i in $(ls); do echo "no any new created domain exists try renew all"
DOMAIN=$(jq -r .DOMAIN $i) for D in $(ls /domains); do
echo "D: $D"
DOMAIN_FILE=$(basename $D)
echo "DOMAIN_FILE: $DOMAIN_FILE"
DOMAIN=$(jq -r .DOMAIN $DOMAIN_FILE)
echo "DOMAIN: $DOMAIN"
if [ "$DOMAIN" != "localhost" ]; then if [ "$DOMAIN" != "localhost" ]; then
ORIGINAL=$(openssl x509 -in /etc/ssl/keys/$DOMAIN/fullchain.pem -fingerprint -noout) ORIGINAL=$(openssl x509 -in /acme.sh/$DOMAIN/fullchain.pem -fingerprint -noout)
start_letsencrypt $DOMAIN start_letsencrypt $DOMAIN
check_new_cert check_new_cert
fi fi
DOMAIN=""
DOMAIN_FILE=""
done done
fi fi
fi fi