f734878a3aa026635321fe596d0ea237dbda271b
[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 WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
10 export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \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 #if [ -z "$IP_ADDRESS" ]; then
19 #  # in our scheme, the single IP address that all our domains map to.
20 #  IP_ADDRESS="10.28.42.20"
21 #fi
22 #if [ -z "$SERVER_ADMIN" ]; then
23 #  # the email address (where first dot is replaced by @) for the administrator of the domain.
24 #  SERVER_ADMIN="developer.cakelampvm.com"
25 #fi
26 #if [ -z "$MAIN_NAME_SERVER" ]; then
27 #  # the name of the name server for the new domains (should already be configured).
28 #  MAIN_NAME_SERVER="ns.cakelampvm.com"
29 #fi
30 #if [ -z "$MAIL_SERVER" ]; then
31 #  # the name of the mail server for a new domain (should already be configured).
32 #  MAIL_SERVER="mail.cakelampvm.com"
33 #fi
34 #if [ -z "$DISTRO" ]; then
35 #  # the distribution name to be listed in info for the new domain or subdomain.
36 #  DISTRO="ubuntu"
37 #fi
38
39 # main body of script.
40
41 if [[ $EUID != 0 ]]; then
42   echo "This script must be run as root or sudo."
43   exit 1
44 fi
45
46 old_domain="$1"; shift
47
48 if [ -z "$old_domain" ]; then
49   echo "This script needs a domain name to remove from DNS." 
50   exit 1
51 fi
52
53 # if domain name has three or more components, then remove a subdomain.
54 # otherwise, remove a full domain.
55 if [[ $old_domain == *"."*"."* ]]; then
56   # remove a subdomain from the containing domain.
57   remove_subdomain "$old_domain"
58   restart_bind
59 else
60   # remove the full domain in DNS.
61   remove_domain_file "$old_domain"
62   remove_zone_for_domain "$old_domain"
63   restart_bind
64 fi
65
66