diff --git a/Dockerfile b/Dockerfile index 8edfeac..a0b96dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -71,9 +71,7 @@ RUN apk add --no-cache --virtual .deps gcc python3-dev libc-dev libffi-dev && \ COPY root / -RUN chmod +x /container-init.sh && \ - chmod +x /certbot-prepare.sh && \ - chmod +x /check-one-shot.sh && \ +RUN chmod +x /container-init.sh /certbot-prepare.sh /check-one-shot.sh /renew-function.sh && \ chown -R ${PUID}:${PGID} /app /config ENTRYPOINT [ "/init" ] diff --git a/root/certbot-prepare.sh b/root/certbot-prepare.sh index 2464296..6c4d93f 100644 --- a/root/certbot-prepare.sh +++ b/root/certbot-prepare.sh @@ -59,33 +59,7 @@ echo "#!/command/with-contenv bash date echo \"Attempting to renew certificates\" -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 - -} +source /renew-function.sh " > /config/.renew-list.sh chmod +x /config/.renew-list.sh diff --git a/root/renew-function.sh b/root/renew-function.sh new file mode 100644 index 0000000..6f342b0 --- /dev/null +++ b/root/renew-function.sh @@ -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 + +} \ No newline at end of file