From: Marc Schütz Date: Fri, 19 Mar 2021 17:26:39 +0000 (+0100) Subject: Support reading domains from drop-in snippets in `domains.txt.d` X-Git-Tag: v0.7.1~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6a84a88faa49928fdab3f89b6253c9a8e84885c;p=thirdparty%2Fdehydrated.git Support reading domains from drop-in snippets in `domains.txt.d` --- diff --git a/dehydrated b/dehydrated index b948c48..c5b7e43 100755 --- a/dehydrated +++ b/dehydrated @@ -1547,6 +1547,20 @@ command_account() { exit 0 } +# Parse contents of domains.txt and domains.txt.d +parse_domains_txt() { + # Allow globbing temporarily + [[ -n "${ZSH_VERSION:-}" ]] && set +o noglob || set +f + local inputs=("${DOMAINS_TXT}" "${DOMAINS_TXT}.d"/*.txt) + [[ -n "${ZSH_VERSION:-}" ]] && set -o noglob || set -f + + cat "${inputs[@]}" | + tr -d '\r' | + awk '{print tolower($0)}' | + _sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e 's/[[:space:]]+/ /g' -e 's/([^ ])>/\1 >/g' -e 's/> />/g' | + (grep -vE '^(#|$)' || true) +} + # Usage: --cron (-c) # Description: Sign/renew non-existent/changed/expiring certificates. command_sign_domains() { @@ -1579,7 +1593,7 @@ command_sign_domains() { # Generate certificates for all domains found in domains.txt. Check if existing certificate are about to expire ORIGIFS="${IFS}" IFS=$'\n' - for line in $(<"${DOMAINS_TXT}" tr -d '\r' | awk '{print tolower($0)}' | _sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g' -e 's/[[:space:]]+/ /g' -e 's/([^ ])>/\1 >/g' -e 's/> />/g' | (grep -vE '^(#|$)' || true)); do + for line in $(parse_domains_txt); do reset_configvars IFS="${ORIGIFS}" alias="$(grep -Eo '>[^ ]+' <<< "${line}" || true)" diff --git a/docs/domains_txt.md b/docs/domains_txt.md index f4090d8..e0c7e0b 100644 --- a/docs/domains_txt.md +++ b/docs/domains_txt.md @@ -94,3 +94,10 @@ This creates two certificates one for `service.example.com` with an **Note:** The first certificate is valid for both `service.example.com` and for `*.service.example.com` which can be a useful way to create wildcard certificates. + +### Drop-in directory + +If a directory named `domains.txt.d` exists in the same location as +`domains.txt`, the contents of `*.txt` files in that directory are appended to +the list of domains, in alphabetical order of the filenames. This is useful for +automation, as it doesn't require editing an existing file to add new domains.