Files
letsencrypt/start.letsencrypt.sh
2022-11-04 09:08:17 +00:00

64 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
email=$EMAIL
sending_error_msg() {
echo "there was unsucessfuly created "$DOMAIN" at date: "$DATE;
}
start_letsencrypt() {
mkdir -p /acme.sh/$DOMAIN/ ;
/usr/local/bin/acme.sh -m $email --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
# 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";
/usr/local/bin/acme.sh -m $email --force --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
fi
}
LETSENCRYPT_FILE=$(find /acme.sh/ -type f -name letsencrypt);
if [ -n "$LETSENCRYPT_FILE" ] ; then
DOMAIN=$(jq -r .DOMAIN $LETSENCRYPT_FILE) ;
DATE=$(date +%y%m%d%H)
echo $DATE
start_letsencrypt;
rm $LETSENCRYPT_FILE;
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 +%y%m%d%H)" -ge "$DATE" && "$(date -r /acme.sh/$DOMAIN/fullchain.pem +%y%m%d%H)" -ge "$DATE" && "$(date -r /acme.sh/$DOMAIN/cert.pem +%y%m%d%H)" -ge "$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 +%y%m%d%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
if [[ "$(date -r /acme.sh/$DOMAIN/key.pem +%y%m%d%H)" -ge "$DATE" && "$(date -r /acme.sh/$DOMAIN/fullchain.pem +%y%m%d%H)" -ge "$DATE" && "$(date -r /acme.sh/$DOMAIN/cert.pem +%y%m%d%H)" -ge "$DATE" ]] ; then
touch /acme.sh/$DOMAIN/new_certificate;
else
sending_error_msg $DOMAIN $DATE;
fi
fi
done ;
fi