From: Frank Brehm Date: Tue, 21 Apr 2020 09:02:23 +0000 (+0200) Subject: Adding bin/get-dns-zonefiles X-Git-Tag: 0.4.1~6^2~7 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=1aea10369777d1363020470f5b55e739a2ab5d56;p=pixelpark%2Fpp-admin-tools.git Adding bin/get-dns-zonefiles --- diff --git a/bin/get-dns-zonefiles b/bin/get-dns-zonefiles new file mode 100755 index 0000000..c2f2bcd --- /dev/null +++ b/bin/get-dns-zonefiles @@ -0,0 +1,123 @@ +#!/bin/bash + +set -e +set -u + +BASE_NAME="$( basename ${0} )" +MY_REAL_NAME=$( readlink -f $0 ) +BIN_DIR=$( dirname "${MY_REAL_NAME}" ) +BASE_DIR=$( dirname "${BIN_DIR}" ) +LIB_DIR="${BASE_DIR}/lib" +CONF_DIR="${BASE_DIR}/etc" + +if [[ -f "${LIB_DIR}/functions.rc" ]] ; then + . "${LIB_DIR}/functions.rc" +else + echo "Bash resource file '${LIB_DIR}/functions.rc' not found" >&2 + exit 5 +fi + +declare -a ZONES=() + +detect_color + +DESCRIPTION=$( cat <<-EOF + Gets via zone transfer the complete content of a DNS zone and generates + a normalized zone file for this zone. + + EOF +) + +#------------------------------------------------------------------------------ +usage() { + cat <<-EOF + Usage: ${BASE_NAME} [Common Options] [ ...] + ${BASE_NAME} [-h|--help] + ${BASE_NAME} [-V|--version] + + Mandatory Parameter(s): + ZONE: The name of the zone (a.k.a. domain), which you want to retrieve + completely. My by given for multiple zones. + + It generates in current directory zone files for each given zone + with a timestamp and a sequential number included in the file name. + + Common Options: + ${STD_USAGE_MSG} + EOF + +} + +get_options() { + + local tmp= + local base_dir= + + set +e + tmp=$( getopt -o ${STD_SHORT_OPTIONS} --long ${STD_LONG_OPTIONS} -n "${BASE_NAME}" -- "$@" ) + if [[ $? != 0 ]] ; then + echo "" >&2 + usage >&2 + exit 1 + fi + set -e + + # Note the quotes around `$TEMP': they are essential! + eval set -- "${tmp}" + eval_common_options "$@" + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p REMAINING_OPTS + declare -p REMAINING_ARGS + fi + + if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then + error "Unknown options: ${REMAINING_OPTS[*]}" + echo >&2 + usage >&2 + exit 2 + fi + + if [[ "${#REMAINING_ARGS[@]}" == "0" ]] ; then + error "No zones given to retrieve." + echo >&2 + usage >&2 + exit 2 + fi + + local i=0 + local zone= + for zone in "${REMAINING_ARGS[@]}" ; do + if [[ "$i" == 0 ]]; then + i=1 + continue + fi + ZONES+=(${zone}) + i=$(( $i + 1 )) + done + + if [[ "${DEBUG}" == 'y' ]] ; then + declare -p ZONES + fi + +} + +#------------------------------------------------------------------------------ +main() { + + get_options "$@" + + for zone in "${ZONES[@]}" ; do + echo >&2 + info "Get zone '${GREEN}${zone}${NORMAL}' ..." + + done + +} + +main "$@" + + + +exit 0 + +# vim: et list