Last active
June 1, 2023 14:27
-
-
Save Zash/dc29ab38f31597cdb62d4b7f3d266f62 to your computer and use it in GitHub Desktop.
nsupdate wrapper thing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
ZONE="$1"; | |
if ! shift; then | |
echo "Usage: $0 ZONE" | |
exit | |
fi | |
UPDATES="$(mktemp --suffix .nsupdate)" | |
trap 'rm -- "$UPDATES"' EXIT | |
{ | |
SOA="$(dig +noall +short "$ZONE" IN SOA)" | |
echo "server ${SOA%% *}" | |
echo "zone $ZONE" | |
echo "ttl ${SOA##* }" | |
echo "prereq yxrrset $ZONE IN SOA $SOA" | |
echo "" | |
case "$1" in | |
*.*) | |
echo "update delete" "$@" | |
dig +noall +nottl +answer "$@" | sed "s/^/update add /" | |
;; | |
update|add|del|delete|prereq) | |
echo "$@" | |
;; | |
esac | |
echo "" | |
echo "show" | |
echo "send" | |
echo "answer" | |
} > "$UPDATES" | |
sensible-editor "$UPDATES" | |
nsupdate -k "$HOME/.config/nsupdate/$ZONE.key" "$UPDATES" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment