From e697c663dfc5fd03dfbe4e00eeefd34f5f62c36e Mon Sep 17 00:00:00 2001 From: Marco Spinosa Date: Tue, 21 Aug 2018 13:29:12 +0200 Subject: [PATCH] Dockerfile updated to install bind-tools (nsupdate). Added the possibility to specify a zone through NSUPDATE_ZONE variables when using dns_nsupdate.sh --- Dockerfile | 1 + dnsapi/dns_nsupdate.sh | 46 +++++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5a64c720..84fc658f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,7 @@ RUN apk update -f \ coreutils \ curl \ socat \ + bind-tools \ && rm -rf /var/cache/apk/* ENV LE_CONFIG_HOME /acme.sh diff --git a/dnsapi/dns_nsupdate.sh b/dnsapi/dns_nsupdate.sh index 555f4d29..d8086b37 100755 --- a/dnsapi/dns_nsupdate.sh +++ b/dnsapi/dns_nsupdate.sh @@ -1,6 +1,9 @@ #!/usr/bin/env sh ######## Public functions ##################### +ECHO=$(command -v echo) +NSUPDATE=$(command -v nsupdate) +NSUPDATE_COMMANDS_FILE="/tmp/nsupdate" #Usage: dns_nsupdate_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs" dns_nsupdate_add() { @@ -13,17 +16,26 @@ dns_nsupdate_add() { _saveaccountconf NSUPDATE_SERVER "${NSUPDATE_SERVER}" _saveaccountconf NSUPDATE_SERVER_PORT "${NSUPDATE_SERVER_PORT}" _saveaccountconf NSUPDATE_KEY "${NSUPDATE_KEY}" + if ! [ -z "$NSUPDATE_ZONE" ]; then + _saveaccountconf NSUPDATE_ZONE "${NSUPDATE_ZONE}" + fi _info "adding ${fulldomain}. 60 in txt \"${txtvalue}\"" - nsupdate -k "${NSUPDATE_KEY}" < ${NSUPDATE_COMMANDS_FILE} + if ! [ -z "$NSUPDATE_ZONE" ]; then + $ECHO "zone ${NSUPDATE_ZONE}" >> ${NSUPDATE_COMMANDS_FILE} + fi + $ECHO "update add ${fulldomain}. 60 in txt \"${txtvalue}\"" >> ${NSUPDATE_COMMANDS_FILE} + $ECHO "send" >> ${NSUPDATE_COMMANDS_FILE} + + _debug "$(cat ${NSUPDATE_COMMANDS_FILE})" + + if ! $NSUPDATE -k "${NSUPDATE_KEY}" -v ${NSUPDATE_COMMANDS_FILE}; then _err "error updating domain" + rm ${NSUPDATE_COMMANDS_FILE} return 1 fi - + rm ${NSUPDATE_COMMANDS_FILE} return 0 } @@ -34,16 +46,22 @@ dns_nsupdate_rm() { [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost" [ -n "${NSUPDATE_SERVER_PORT}" ] || NSUPDATE_SERVER_PORT=53 _info "removing ${fulldomain}. txt" - nsupdate -k "${NSUPDATE_KEY}" < ${NSUPDATE_COMMANDS_FILE} + if ! [ -z "$NSUPDATE_ZONE" ]; then + $ECHO "zone ${NSUPDATE_ZONE}" >> ${NSUPDATE_COMMANDS_FILE} + fi + $ECHO "update delete ${fulldomain}. txt" >> ${NSUPDATE_COMMANDS_FILE} + $ECHO "send" >> ${NSUPDATE_COMMANDS_FILE} + + _debug "$(cat ${NSUPDATE_COMMANDS_FILE})" + + if ! $NSUPDATE -k "${NSUPDATE_KEY}" -v ${NSUPDATE_COMMANDS_FILE}; then _err "error updating domain" + rm ${NSUPDATE_COMMANDS_FILE} return 1 fi - + rm ${NSUPDATE_COMMANDS_FILE} return 0 }