pushing down some cakelampvm details
[feisty_meow.git] / scripts / system / remove_domain.sh
1 #!/bin/bash
2
3 # performs the inverse function of add_domain by deconfiguring a domain
4 # in bind.  the domain needs to have been set up by add_domain, or this will
5 # not succeed.
6 #
7 # Author: Chris Koeritz
8
9 export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
10 export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )"
11
12 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
13 source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh"
14
15 # some defaults that are convenient for current purposes.
16 # existing values will be respected over our defaults.
17
18 # main body of script.
19
20 if [[ $EUID != 0 ]]; then
21   echo "This script must be run as root or sudo."
22   exit 1
23 fi
24
25 old_domain="$1"; shift
26
27 if [ -z "$old_domain" ]; then
28   echo "This script needs a domain name to remove from DNS." 
29   exit 1
30 fi
31
32 # if domain name has three or more components, then remove a subdomain.
33 # otherwise, remove a full domain.
34 if [[ $old_domain == *"."*"."* ]]; then
35   # remove a subdomain from the containing domain.
36   remove_subdomain "$old_domain"
37   restart_bind
38 else
39   # remove the full domain in DNS.
40   remove_domain_file "$old_domain"
41   remove_zone_for_domain "$old_domain"
42   restart_bind
43 fi
44
45