#!/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 [-x] [-h]" echo "" echo " -h Print this help." echo " -z 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 /tmp/$zone --write-out "%{http_code}" --request DELETE --header "X-API-Key: $api_key" $api_base_url/zones/$zone) rm /tmp/$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