#!/usr/bin/env bash SCRIPT_PATH=$(realpath -s "${0}") SCRIPT_DIR=$(dirname "$SCRIPT_PATH") SCRIPT=$(basename "$SCRIPT_PATH") usage() { cat <&2 exit 1 fi config_file=$1 shift ;; -h|--help) usage ;; -i|--interactive) interactive=true ;; -j|--json) json=true ;; -J|--json-pretty) json=true json_pretty=true ;; -r|--raw) raw=true ;; -*) echo "$SCRIPT: invalid option -- '$opt'" >&2 exit 1 ;; *) args+=("$opt") if (( ${#args[@]} > 1 )); then echo "$SCRIPT: invalid argument -- '$opt'" >&2 exit 1 fi ;; esac done if $raw && $json; then echo "$SCRIPT: invalid options: --raw and --json are mutually exclusive" >&2 exit 1 fi source "$config_file" || exit 2 LIB_DIR=${LIB_DIR:-$SCRIPT_DIR/lib} source "$LIB_DIR"/dns.sh || exit 3 source "$LIB_DIR"/output.sh || exit 3 set -- "${args[@]}" zone=$1 if shift; then dns_check_zone_view "$zone" zone view || exit 10 elif $interactive; then dns_select_zone zone view || exit 11 else echo "$SCRIPT: missing argument -- ZONE[@VIEW]" >&2 exit 1 fi declare -A output if [ "${view}" == "*" ]; then json_array_to_bash views < <(dns_zone_views "$zone") else views=("$view") fi for view in "${views[@]}"; do output["$view"]=$(dns_zone "$zone" "$view" "$all") || exit 12 done if $raw; then n=0 for view in $(printf "%s\n" "${!output[@]}" | sort); do if (( ${#output[@]} > 1 )) || [ "$view" != "$NAMED_DEFAULT_VIEW" ]; then cat < 1 )) || [ "$view" != "$NAMED_DEFAULT_VIEW" ] && echo "View: $view" { (( $max_value_len <= 0 )) && max_value_len=1 while read -r name ttl rtype value; do name=$("$IDN2" --decode <<<"$name") (( ${#value} > $max_value_len )) && value="${value:0:$max_value_len} ...[TRUNCATED]" echo "$name$TAB$ttl$TAB$rtype$TAB$value" done < <("$JQ" --raw-output '.[] | "\(.name)\t\(.ttl)\t\(.type)\t\(.value)"' <<<"${output["$view"]}") } | table_output "NAME" "TTL" "TYPE" "VALUE" ((n++)) (( $n < ${#output[@]} )) && echo done