3 # this set of functions serve the main purpose of adding new domains or
4 # subdomains to the bind9 DNS server on the current host. it is currently
5 # highly specific to running a bunch of domains on a linux VM, where the VM
6 # has one IP address. note that the bind 'named' must already be configured.
7 # also, it is assumed that, if a subdomain is being added, then the containing
8 # domain has already been configured and is configured in a file similar to
9 # "blah.com.conf" in /etc/bind.
11 # Author: Chris Koeritz
13 export THISDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory.
14 export FEISTY_MEOW_APEX="$( \cd "$THISDIR/../.." && \pwd )"
16 source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
17 source "$FEISTY_MEOW_SCRIPTS/system/common_sysadmin.sh"
19 # some defaults that are convenient for current purposes.
20 # existing values will be respected over our defaults.
22 if [ -z "$IP_ADDRESS" ]; then
23 # in our scheme, the single IP address that all our domains map to.
24 IP_ADDRESS="$(get_ip_addresses | head)"
25 echo "** defaulting IP address to $IP_ADDRESS"
27 if [ -z "$SERVER_ADMIN" ]; then
28 # the email address (where first dot is replaced by @) for the administrator of the domain.
29 SERVER_ADMIN="$(logname).localhost"
30 echo "** defaulting server admin to $SERVER_ADMIN"
32 if [ -z "$MAIN_NAME_SERVER" ]; then
33 # the name of the name server for the new domains (should already be configured).
34 MAIN_NAME_SERVER="ns.localhost"
35 echo "** defaulting main name server to $MAIN_NAME_SERVER"
37 if [ -z "$MAIL_SERVER" ]; then
38 # the name of the mail server for a new domain (should already be configured).
39 MAIL_SERVER="mail.localhost"
40 echo "** defaulting mail server to $MAIL_SERVER"
42 if [ -z "$DISTRO" ]; then
43 # the distribution name to be listed in info for the new domain or subdomain.
45 echo "** defaulting distro to $DISTRO"
48 # main body of script.
50 if [[ $EUID != 0 ]]; then
51 echo "This script must be run as root or sudo."
55 new_domain="$1"; shift
57 if [ -z "$new_domain" ]; then
58 echo "This script needs a domain name to add to DNS."
62 # if domain name has three or more components, then add a subdomain.
63 # otherwise, add a full new domain.
64 if [[ $new_domain == *"."*"."* ]]; then
65 # add a subdomain to the containing domain.
66 add_new_subdomain "$new_domain"
69 # create a totally new domain in DNS.
70 write_new_domain_file "$new_domain"
71 add_zone_for_new_domain "$new_domain"