powerdns-tools/bin/pdns-zone-ext.sh

47 lines
1.1 KiB
Bash
Raw Normal View History

2022-01-31 12:37:19 -08:00
#!/bin/bash
#
# pdns-tools
# https://git.stack-source.com/msb/pdns-tools
2022-08-22 13:45:17 -07:00
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
2022-01-31 12:37:19 -08:00
# load include file
source $(dirname $0)/pdns.sh
help()
{
echo "Check if Zone is extant (exits)."
echo ""
echo "usage: $thisfilename -z <zone> [-h]"
echo ""
echo " -h Print this help."
echo " -z <zone> Zone to get."
echo
2023-08-08 13:22:11 -07:00
echo " Echoes 'true' if zone exists with exit code 0, 'false' if zone does not exist with exit code 1, 'error' with exit code 2 on error."
2022-01-31 12:37:19 -08:00
}
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
2023-08-08 13:22:11 -07:00
exit 0
2022-01-31 12:37:19 -08:00
elif [[ $zone_status = 404 ]]; then
# zone does not exist
echo false
2023-08-08 13:22:11 -07:00
exit 1
2022-01-31 12:37:19 -08:00
else
# error, unexpected response code
echo error
2023-08-08 13:22:11 -07:00
exit 2
2022-01-31 12:37:19 -08:00
fi