powerdns-tools/sbin/pdns-zone-del.sh

41 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2022-01-21 13:38:32 -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-21 13:38:32 -08:00
# load include file
source $(dirname $0)/pdns.sh
help()
{
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
2022-01-29 11:54:12 -08:00
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)
2022-01-21 13:38:32 -08:00
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