From 9e6deb7a2a2fc418493e9da9ccf792fa325c2d5d Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Mon, 31 Jan 2022 12:37:19 -0800 Subject: [PATCH] new pdns-zone-ext.sh --- bin/pdns-zone-ext.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 bin/pdns-zone-ext.sh diff --git a/bin/pdns-zone-ext.sh b/bin/pdns-zone-ext.sh new file mode 100755 index 0000000..35da951 --- /dev/null +++ b/bin/pdns-zone-ext.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# +# pdns-tools +# https://git.stack-source.com/msb/pdns-tools +# MIT License Copyright (c) 2022 Matthew Saunders Brown + +# load include file +source $(dirname $0)/pdns.sh + +help() +{ + thisfilename=$(basename -- "$0") + echo "$thisfilename" + echo "Check if Zone is extant (exits)." + echo "" + echo "usage: $thisfilename -z [-h]" + echo "" + echo " -h Print this help." + echo " -z Zone to get." + echo + echo " Echoes 'true' if zone exists, 'false' if zone does not exist, 'error' with exit code 1 on error." +} + +pdns:getoptions "$@" + +# check for zone +if [[ -z $zone ]]; then + echo "zone is required" + exit 1 +fi + +# export zone and check http status +zone_status=$(/usr/bin/curl --silent --output /dev/null --write-out "%{http_code}" -H "X-API-Key: $api_key" $api_base_url/zones/$zone?rrsets=false) + +if [[ $zone_status = 200 ]]; then + # zone exists + echo true +elif [[ $zone_status = 404 ]]; then + # zone does not exist + echo false +else + # error, unexpected response code + echo error + exit 1 +fi