From 45d0a9ed5cff820773193ba75992ebff27fac69b Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Wed, 7 Feb 2024 12:08:35 -0800 Subject: [PATCH] rework thisfilename, add parent option, in advance of vpanel scripts --- bin/pdns-ptr-set.sh | 2 -- bin/pdns-rr-del.sh | 2 -- bin/pdns-rr-rep.sh | 2 -- bin/pdns-search.sh | 6 +----- bin/pdns-zone-add.sh | 2 -- bin/pdns-zone-del.sh | 2 -- bin/pdns-zone-exp.sh | 2 -- bin/pdns-zone-ext.sh | 2 -- bin/pdns-zone-ttl.sh | 2 -- bin/pdns.sh | 15 ++++++++++++++- 10 files changed, 15 insertions(+), 22 deletions(-) diff --git a/bin/pdns-ptr-set.sh b/bin/pdns-ptr-set.sh index 8a69153..3d84d49 100755 --- a/bin/pdns-ptr-set.sh +++ b/bin/pdns-ptr-set.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Set/update PTR Record." echo "" echo "usage: $thisfilename -i [-r ] [-l ] [-s ] [-c ] [-a ] [-h]" diff --git a/bin/pdns-rr-del.sh b/bin/pdns-rr-del.sh index b0ddf10..0109b7f 100755 --- a/bin/pdns-rr-del.sh +++ b/bin/pdns-rr-del.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Delete Resource Record set in zone." echo "" echo "usage: $thisfilename -z -n -t [-h]" diff --git a/bin/pdns-rr-rep.sh b/bin/pdns-rr-rep.sh index 7e478ce..d86721a 100755 --- a/bin/pdns-rr-rep.sh +++ b/bin/pdns-rr-rep.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Replace Resource Record set in zone." echo "" echo "usage: $thisfilename -z -n -t -r [-l ] [-s ] [-c ] [-a ] [-h]" diff --git a/bin/pdns-search.sh b/bin/pdns-search.sh index 1570d42..3b6133e 100755 --- a/bin/pdns-search.sh +++ b/bin/pdns-search.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Search data in Zones, Comments and RRSets." echo "" echo "usage: $thisfilename -q [-e ] [-o ] [-c] [-h]" @@ -52,10 +50,8 @@ if [[ $zone_status = 200 ]]; then # column output dasel -r json -w csv -f $tmpfile|sed -e 's/"""/"/g'|column -t -s ',' fi -elif [[ $zone_status = 404 ]]; then - echo 404 Not Found, $zone does not exist else - echo Unexecpted http response checking for existence of zone $zone: $zone_status + echo Unexecpted http response seraching for $query: $zone_status fi rm $tmpfile diff --git a/bin/pdns-zone-add.sh b/bin/pdns-zone-add.sh index 1bf58dd..b3e944d 100755 --- a/bin/pdns-zone-add.sh +++ b/bin/pdns-zone-add.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Add new zone to DNS" echo "" echo "usage: $thisfilename -z [-m ] [-t ] [-a ] [-w ] [-b] [-h]" diff --git a/bin/pdns-zone-del.sh b/bin/pdns-zone-del.sh index 2f59b1b..f8582c4 100755 --- a/bin/pdns-zone-del.sh +++ b/bin/pdns-zone-del.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Delete a zone and all of it's records." echo "" echo "usage: $thisfilename -z [-x] [-h]" diff --git a/bin/pdns-zone-exp.sh b/bin/pdns-zone-exp.sh index 43fdb5a..d66f08a 100755 --- a/bin/pdns-zone-exp.sh +++ b/bin/pdns-zone-exp.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Export full DNS zone in AXFR format." echo "" echo "usage: $thisfilename -z [-h]" diff --git a/bin/pdns-zone-ext.sh b/bin/pdns-zone-ext.sh index 955967d..b96bb61 100755 --- a/bin/pdns-zone-ext.sh +++ b/bin/pdns-zone-ext.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Check if Zone is extant (exits)." echo "" echo "usage: $thisfilename -z [-h]" diff --git a/bin/pdns-zone-ttl.sh b/bin/pdns-zone-ttl.sh index 04e6d03..92133bc 100755 --- a/bin/pdns-zone-ttl.sh +++ b/bin/pdns-zone-ttl.sh @@ -10,8 +10,6 @@ source $(dirname $0)/pdns.sh help() { - thisfilename=$(basename -- "$0") - echo "$thisfilename" echo "Replace Resource Record set in zone." echo "" echo "usage: $thisfilename -z -n -t -r [-l ] [-s ] [-c ] [-a ] [-h]" diff --git a/bin/pdns.sh b/bin/pdns.sh index a5b6cfc..65b4019 100755 --- a/bin/pdns.sh +++ b/bin/pdns.sh @@ -30,6 +30,10 @@ fi # Defaults to IP of server script is run from [[ -z $default_ip ]] && default_ip=$(hostname --ip-address) +# Hostname of this server. +# Should normally just use the server configured hostname. +[[ -z $hostname ]] && hostname=$(hostname --fqdn) + # Array of allowed Resource Record Types [[ -z $rr_types ]] && declare -a rr_types=(A AAAA CNAME MX NS PTR SRV TXT) @@ -141,9 +145,15 @@ function pdns::yesno() { function pdns:getoptions () { local OPTIND - while getopts "ha:bcd:e:i:l:m:n:o:q:r:s:t:w:xz:" opt ; do + while getopts "ha:bcd:e:i:l:m:n:o:p:q:r:s:t:w:xz:" opt ; do case "${opt}" in h ) # display help and exit + # set thisfilename=$(basename -- "$0") + if [[ -n $parent ]]; then + thisfilename=$parent + else + thisfilename=$(basename -- "$0") + fi help exit ;; @@ -189,6 +199,9 @@ function pdns:getoptions () { o ) # object_type - Type of data to search for, one of 'all', 'zone', 'record', 'comment' object=${OPTARG,,} ;; + p ) # parent - name of parent script ("hidden" option used by vdns-* scripts) + parent=${OPTARG,,} + ;; q ) # query - The string to search for query=${OPTARG} ;;