- get rid of bash-only syntax like ${foo:-bar}

- use sh instead of bash
- remove redundant functions _info, _err, _debug and _debug2
- get rid of mktemp, pipe commands directly to nsupdate
This commit is contained in:
Philippe Kueck 2016-10-26 16:14:47 +02:00
parent 2d279c4c5c
commit 54d61bdc4a
No known key found for this signature in database
GPG Key ID: E10E57D62DB57A3B

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env sh
######## Public functions ##################### ######## Public functions #####################
@ -8,18 +8,16 @@ dns_nsupdate_add() {
fulldomain=$1 fulldomain=$1
txtvalue=$2 txtvalue=$2
_checkKeyFile || return 1 _checkKeyFile || return 1
NSUPDATE_SERVER=${NSUPDATE_SERVER:-localhost} [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost"
# save the dns server and key to the account conf file. # save the dns server and key to the account conf file.
_saveaccountconf NSUPDATE_SERVER "${NSUPDATE_SERVER}" _saveaccountconf NSUPDATE_SERVER "${NSUPDATE_SERVER}"
_saveaccountconf NSUPDATE_KEY "${NSUPDATE_KEY}" _saveaccountconf NSUPDATE_KEY "${NSUPDATE_KEY}"
tmp=$(mktemp --tmpdir acme_nsupdate.XXXXXX) _info "adding ${fulldomain}. 60 in txt \"${txtvalue}\""
cat > ${tmp} <<EOF nsupdate -k ${NSUPDATE_KEY} <<EOF
server ${NSUPDATE_SERVER} server ${NSUPDATE_SERVER}
update add ${fulldomain}. 60 in txt "${txtvalue}" update add ${fulldomain}. 60 in txt "${txtvalue}"
send send
EOF EOF
_info "adding ${fulldomain}. 60 in txt \"${txtvalue}\""
nsupdate -k ${NSUPDATE_KEY} ${tmp}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
_err "error updating domain, see ${tmp} for details" _err "error updating domain, see ${tmp} for details"
return 1 return 1
@ -33,15 +31,13 @@ EOF
dns_nsupdate_rm() { dns_nsupdate_rm() {
fulldomain=$1 fulldomain=$1
_checkKeyFile || return 1 _checkKeyFile || return 1
NSUPDATE_SERVER=${NSUPDATE_SERVER:-localhost} [ -n "${NSUPDATE_SERVER}" ] || NSUPDATE_SERVER="localhost"
tmp=$(mktemp --tmpdir acme_nsupdate.XXXXXX) _info "removing ${fulldomain}. txt"
cat > ${tmp} <<EOF nsupdate -k ${NSUPDATE_KEY} <<EOF
server ${NSUPDATE_SERVER} server ${NSUPDATE_SERVER}
update delete ${fulldomain}. txt update delete ${fulldomain}. txt
send send
EOF EOF
_info "removing ${fulldomain}. txt"
nsupdate -k ${NSUPDATE_KEY} ${tmp}
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
_err "error updating domain, see ${tmp} for details" _err "error updating domain, see ${tmp} for details"
return 1 return 1
@ -64,31 +60,3 @@ _checkKeyFile() {
return 1 return 1
fi fi
} }
_info() {
if [ -z "$2" ] ; then
echo "[$(date)] $1"
else
echo "[$(date)] $1='$2'"
fi
}
_err() {
_info "$@" >&2
return 1
}
_debug() {
if [ -z "$DEBUG" ] ; then
return
fi
_err "$@"
return 0
}
_debug2() {
if [ "$DEBUG" ] && [ "$DEBUG" -ge "2" ] ; then
_debug "$@"
fi
return
}