Skip to content

Instantly share code, notes, and snippets.

@Zash
Last active June 1, 2023 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zash/dc29ab38f31597cdb62d4b7f3d266f62 to your computer and use it in GitHub Desktop.
Save Zash/dc29ab38f31597cdb62d4b7f3d266f62 to your computer and use it in GitHub Desktop.
nsupdate wrapper thing
#!/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