From: Frank Brehm Date: Tue, 21 Apr 2020 11:22:22 +0000 (+0200) Subject: Extending bin/get-dns-zonefiles X-Git-Tag: 0.4.1~6^2~6 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=e1fbfb3cc5ab5065f5f55ffc16056693a88bc75f;p=pixelpark%2Fpp-admin-tools.git Extending bin/get-dns-zonefiles --- diff --git a/bin/get-dns-zonefiles b/bin/get-dns-zonefiles index c2f2bcd..1b5010f 100755 --- a/bin/get-dns-zonefiles +++ b/bin/get-dns-zonefiles @@ -101,15 +101,46 @@ get_options() { } +#------------------------------------------------------------------------------ +cur_ts() { + date +'%Y-%m-%d_%H-%M-%S' +} + +#------------------------------------------------------------------------------ +get_zone() { + + local zone="$1" + + echo >&2 + info "Get zone '${GREEN}${zone}${NORMAL}' ..." + + local tmpfile=$( mktemp "${zone}.XXXXXXXXXX.zone" ) + + dig axfr "${zone}" >"${tmpfile}" + if grep -i 'Transfer failed' "${tmpfile}" >/dev/null ; then + error "Could not transfer zone '${RED}${zone}${NORMAL}'." + else + if type -p named-compilezone >/dev/null ; then + named-compilezone -o - -s relative "${zone}" "${tmpfile}" + else + cat "${tmpfile}" | grep -P -v '^\s*(;|$)' + fi + fi + + RM "${tmpfile}" +} + #------------------------------------------------------------------------------ main() { get_options "$@" + umask 0022 + local the_zone= - for zone in "${ZONES[@]}" ; do - echo >&2 - info "Get zone '${GREEN}${zone}${NORMAL}' ..." + set_locale "en_US.utf8" + for the_zone in "${ZONES[@]}" ; do + get_zone "${the_zone}" done }