#!/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 ;; -j|--json) json=true ;; -J|--json-pretty) json=true json_pretty=true ;; -r|--raw) raw=true ;; -*) echo "$SCRIPT: invalid option -- '$opt'" >&2 exit 1 ;; *) echo "$SCRIPT: invalid argument -- '$opt'" >&2 exit 1 ;; esac done if $json && $raw; 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 zones_data=$(dns_zones) || exit 10 if $raw; then "$JQ" --raw-output '.[] | "\(.zone)\t\(.view)\t\(.status)"' <<<"$zones_data" elif $json; then jq_opts="" $json_pretty || jq_opts="--compact-output" "$JQ" $jq_opts <<<"$zones_data" else while read -r zone view status; do zone=$("$IDN2" --decode <<<"$zone") echo "$zone$TAB$view$TAB$status" done < <("$JQ" --raw-output '.[] | "\(.zone)\t\(.view)\t\(.status)"' <<<"$zones_data") | table_output "ZONE" "VIEW" "STATUS" fi