Move renewal function to its own file

This commit is contained in:
MrMeeb 2024-05-30 19:26:57 +00:00 committed by MrMeeb
parent da87dcc8e3
commit 2b961950f8
3 changed files with 29 additions and 30 deletions

View File

@ -71,9 +71,7 @@ RUN apk add --no-cache --virtual .deps gcc python3-dev libc-dev libffi-dev && \
COPY root / COPY root /
RUN chmod +x /container-init.sh && \ RUN chmod +x /container-init.sh /certbot-prepare.sh /check-one-shot.sh /renew-function.sh && \
chmod +x /certbot-prepare.sh && \
chmod +x /check-one-shot.sh && \
chown -R ${PUID}:${PGID} /app /config chown -R ${PUID}:${PGID} /app /config
ENTRYPOINT [ "/init" ] ENTRYPOINT [ "/init" ]

View File

@ -59,33 +59,7 @@ echo "#!/command/with-contenv bash
date date
echo \"Attempting to renew certificates\" echo \"Attempting to renew certificates\"
function renew() { source /renew-function.sh
#Variables:
#\$1 = Certbot command
RENEWAL_DOMAINS=\$(echo \$1 | sed -r 's/.*\s-d\s(\S*).*/\1/')
CUSTOM_CA_PATH=\$(echo \$1 | sed -r 's/REQUESTS_CA_BUNDLE=(\S*)\s(.*)/\1/')
CERTBOT_COMMAND=\$(echo \$1 | sed -r 's/REQUESTS_CA_BUNDLE=(\S*)\s(.*)/\2/')
echo \"Renewing certificate for \${RENEWAL_DOMAINS}\"
echo \"REQUESTS_CA_BUNDLE=\${CUSTOM_CA_PATH} \${CERTBOT_COMMAND}\" | bash
if [ \$? = 0 ]; then
echo \"Renewal attempt of certificate for \${RENEWAL_DOMAINS} succeeded\"
if [ \"\${NOTIFY_ON_SUCCESS}\" = \"true\" ]; then
apprise -b \"Renewal of certificate for \${RENEWAL_DOMAINS} succeeded\" \${APPRISE_URL}
fi
else
echo \"Renewal attempt of certificate for \${RENEWAL_DOMAINS} failed\"
if [ \"\${NOTIFY_ON_FAILURE}\" = \"true\" ]; then
apprise -b \"Renewal of certificate for \${RENEWAL_DOMAINS} failed\" \${APPRISE_URL}
fi
fi
}
" > /config/.renew-list.sh " > /config/.renew-list.sh
chmod +x /config/.renew-list.sh chmod +x /config/.renew-list.sh

27
root/renew-function.sh Normal file
View File

@ -0,0 +1,27 @@
function renew() {
#Variables:
#$1 = Certbot command
RENEWAL_DOMAINS=$(echo $1 | sed -r 's/.*\s-d\s(\S*).*/\1/')
CUSTOM_CA_PATH=$(echo $1 | sed -r 's/REQUESTS_CA_BUNDLE=(\S*)\s(.*)/\1/')
CERTBOT_COMMAND=$(echo $1 | sed -r 's/REQUESTS_CA_BUNDLE=(\S*)\s(.*)/\2/')
echo "Renewing certificate for ${RENEWAL_DOMAINS}"
echo "REQUESTS_CA_BUNDLE=${CUSTOM_CA_PATH} ${CERTBOT_COMMAND}" | bash
if [ $? = 0 ]; then
echo "Renewal attempt of certificate for ${RENEWAL_DOMAINS} succeeded"
if [ "${NOTIFY_ON_SUCCESS}" = "true" ]; then
apprise -b "Renewal of certificate for ${RENEWAL_DOMAINS} succeeded" ${APPRISE_URL}
fi
else
echo "Renewal attempt of certificate for ${RENEWAL_DOMAINS} failed"
if [ "${NOTIFY_ON_FAILURE}" = "true" ]; then
apprise -b "Renewal of certificate for ${RENEWAL_DOMAINS} failed" ${APPRISE_URL}
fi
fi
}