improvements

This commit is contained in:
Dominik Chilla 2020-03-24 00:06:18 +01:00
parent 1092ac4d76
commit baaed73a91
3 changed files with 35 additions and 40 deletions

View File

@ -1,22 +1,21 @@
# ACME - snippet to obtain let´s encrpyt certificates authenticated by DNS-01
## Prerequisites
* bash
* curl
* openssl
* cron
## Dockerfile:
```
ADD ./snippets/acme/dehydrated /dehydrated/
ADD ./snippets/acme/config /dehydrated/config
ADD ./snippets/acme/get_cert_ddns01.sh /app/get_cert_ddns01.sh
ADD ./snippets/acme/zwackl_hook.sh /app/zwackl_hook.sh
ADD ./snippets/acme/cronjob.daily /etc/periodic/daily/acme
```
**Do not forget to include the cron snippet!**
## Cronjob
`/etc/periodic/daily/acme`:
```
#!/bin/bash
. /cron_env && /dehydrated/dehydrated --cron -t dns-01 -k /app/zwackl_hook.sh && ${ACME_RELOAD_CMD}
```
## Environment
* ACME_FQDNS (required)
* ACME_RELOAD_CMD (required)
@ -24,3 +23,4 @@ ADD ./snippets/acme/zwackl_hook.sh /app/zwackl_hook.sh
* STAGING_URI (optional)
* DDNS01URI (required)
* DDNS01KEY (required)
* DDNS01_ONECERT (optional)

View File

@ -10,7 +10,7 @@ if [ ! -z "${ACME_FQDNS+x}" ]; then
exit 1
fi
if [ ! -d /secrets/ssl ]; then
mkdir -p /secrets/ssl
install -d -m 775 /secrets/ssl
fi
if [ ! -z "${ACME_STAGING_ENABLED+x}" ]; then
STAGING_URI='CA="https://acme-staging-v02.api.letsencrypt.org/directory"' \
@ -40,18 +40,15 @@ if [ ! -z "${ACME_FQDNS+x}" ]; then
fi
echo -n "" > /dehydrated/domains.txt
for fqdn in ${ACME_FQDNS}; do
echo "${fqdn}"
echo "${ONELINE}" "${fqdn} " >> /dehydrated/domains.txt
if [ ! -d "/secrets/ssl/${fqdn}" ]; then
mkdir -p "/secrets/ssl/${fqdn}"
install -d -m 775 "/secrets/ssl/${fqdn}"
fi
done
if [ ! -z "${ONELINE}" ]; then
echo "" >> /dehydrated/domains.txt
fi
chmod +x /app/zwackl_hook.sh
# chmod +x /dehydrated/renew_certs
# ln -f -s /dehydrated/renew_certs /etc/periodic/daily/renew_certs
if [ -z "$(ls -A /dehydrated/accounts)" ]; then
cd /dehydrated && /dehydrated/dehydrated --register --accept-terms
fi
@ -66,7 +63,7 @@ if [ ! -z "${ACME_FQDNS+x}" ]; then
if [ ! -z "${RUN_DEHYDRATED}" ]; then
/dehydrated/dehydrated --cron -t dns-01 -k /app/zwackl_hook.sh
fi
export CROND_ENABLE='acme'
chmod -R +x /dehydrated/certs
else
echo "Directory /dehydrated not found!"
exit 1

View File

@ -1,29 +1,27 @@
#!/bin/sh
if [ ! -z "${CROND_ENABLE+x}" ]; then
# serialize ENV for cron-jobs
TMP_FILE=/tmp/cron_env
OUT_FILE=/cron_env
echo -n '' > "${OUT_FILE}"
env > "${TMP_FILE}"
while read -r line; do
echo "${line}" | grep -q "^PWD="
if [ $? = 0 ]; then
continue
fi
echo "${line}" | grep -q "\s"
if [ $? = 0 ]; then
# double-quote blank separated values for $(export)
# 1. awk: replace first(!) appearance of = with ="
# 2. awk: replace end of line with double-quotes
QUOTED=$(echo "${line}" | awk '{sub(/=/,"=\"");}1'| awk '{sub(/$/,"\"");}1')
echo "export ${QUOTED}" >> "${OUT_FILE}"
else
echo "export ${line}" >> "${OUT_FILE}"
fi
done <"${TMP_FILE}"
unlink "${TMP_FILE}"
# start crond in background
/usr/sbin/crond -b -S
fi
# serialize ENV for cron-jobs
TMP_FILE=/tmp/cron_env
OUT_FILE=/cron_env
echo -n '' > "${OUT_FILE}"
env > "${TMP_FILE}"
while read -r line; do
echo "${line}" | grep -q "^PWD="
if [ $? = 0 ]; then
continue
fi
echo "${line}" | grep -q "\s"
if [ $? = 0 ]; then
# double-quote blank separated values for $(export)
# 1. awk: replace first(!) appearance of = with ="
# 2. awk: replace end of line with double-quotes
QUOTED=$(echo "${line}" | awk '{sub(/=/,"=\"");}1'| awk '{sub(/$/,"\"");}1')
echo "export ${QUOTED}" >> "${OUT_FILE}"
else
echo "export ${line}" >> "${OUT_FILE}"
fi
done <"${TMP_FILE}"
unlink "${TMP_FILE}"
# start crond in background
/usr/sbin/crond -b -S