vdns-stack/bin/vdns-zone-def.sh

61 lines
1.5 KiB
Bash
Raw Permalink Normal View History

2024-02-22 15:02:16 -08:00
#!/bin/bash
#
# vdns-stack
# https://git.stack-source.com/msb/vdns-stack
# Copyright (c) 2024 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# load include file
source $(dirname $0)/vdns.sh
help()
{
echo "Show default records for given domain."
echo ""
echo "usage: $thisfilename -z <zone> [-c] [-h]"
echo ""
echo " -h Print this help."
echo " -z <zone> Zone (domain name) to display default records for."
echo " -c Output in csv format instead of columns."
}
vdns:getoptions "$@"
# check for zone
if [[ -z $zone ]]; then
echo "zone is required"
exit 1
fi
output="name,type,content"
# add SOA to output
output="$output\n$zone,SOA,$zone_default_ns $zone_defaults_mbox $serial $zone_defaults_refresh $zone_defaults_retry $zone_defaults_expire $zone_defaults_minimum"
# add each additiona record to output
for record in "${default_records[@]}"; do
# replace @ with zone
record=$(echo ${record} | sed -e "s/@/$zone/g")
# turn record row info in to array
orig_ifs="$IFS"
IFS='|'
read -r -a recordArray <<< "$record"
IFS="$orig_ifs"
# extract record info from array
rr_name=${recordArray[0]}
rr_type=${recordArray[1]}
rr_content=${recordArray[2]}
if [[ $rr_type = TXT ]]; then
rr_content="\"$rr_content\""
fi
output="$output\n$rr_name,$rr_type,$rr_content"
done
if [[ $csv ]]; then
echo -e $output
else
echo -e $output | column -t -s ,
fi