]> git.ipfire.org Git - thirdparty/dehydrated.git/commitdiff
Support reading domains from drop-in snippets in `domains.txt.d`
authorMarc Schütz <schuetz@yoocon.de>
Fri, 19 Mar 2021 17:26:39 +0000 (18:26 +0100)
committerLukas Schauer <lukas@schauer.dev>
Sun, 31 Oct 2021 18:48:28 +0000 (19:48 +0100)
dehydrated
docs/domains_txt.md

index b948c48d9a01904857d1b053484bf709391f5864..c5b7e43f2c3c35aeaee6b570bb40fc71401d6150 100755 (executable)
@@ -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)"
index f4090d83cf516d78a1ec27358c996931fddc12b6..e0c7e0bfe0fe16a1dffbd54b3bac54d49e665b14 100644 (file)
@@ -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.