powerdns-tools/bin/pdns-zone-del.sh
2022-01-29 11:54:12 -08:00

42 lines
1.1 KiB
Bash
Executable File

#!/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 "Delete a zone and all of it's records."
echo ""
echo "usage: $thisfilename -z <zone> [-x] [-h]"
echo ""
echo " -h Print this help."
echo " -z <zone> Zone (domain name) to delete."
echo " -x Execute (force) - don't prompt for confirmation."
}
pdns:getoptions "$@"
# check for zone
if [[ -z $zone ]]; then
echo "zone is required"
exit
fi
if [[ -n $execute ]] || pdns::yesno "Delete $zone now?"; then
echo
zone_status=$(/usr/bin/curl --silent --output /dev/null --write-out "%{http_code}" --request DELETE --header "X-API-Key: $api_key" $api_base_url/zones/$zone)
if [[ $zone_status = 204 ]]; then
echo Zone $zone deleted.
elif [[ $zone_status = 404 ]]; then
echo Zone $zone does not exist.
else
echo Error. http response deleting zone $zone was: $zone_status
fi
fi