3 # this is a library of functions shared by scripts in the system folder.
5 # Author: Chris Koeritz
7 #export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory.
8 #export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )"
10 #source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh"
12 # creates a totally new domain config file for DNS.
13 function write_new_domain_file()
15 local domain_name="$1"; shift
17 local domain_file="/etc/bind/${domain_name}.conf"
19 echo "adding a totally new domain called $domain_name"
20 echo "using the config file: $domain_file"
22 if [ -f $domain_file ]; then
24 echo "The domain configuration file already exists at:"
26 echo "Since we don't want to tear that down if it has specialized configuration"
27 echo "data in it, we will just leave it in place and consider our job done."
34 @ IN SOA @ ${SERVER_ADMIN}. (
41 IN NS ${MAIN_NAME_SERVER}.
42 IN MX 10 ${MAIL_SERVER}.
44 ${domain_name}. IN A ${IP_ADDRESS}
45 IN HINFO \"linux server\" \"${DISTRO}\"
48 # our personalized configuration approach wants the real owner to own the file.
49 chown "$(logname):$(logname)" $domain_file
50 test_or_die "setting ownership on: $domain_file"
53 # hooks up a new config file into bind's list of zones.
54 function add_zone_for_new_domain()
56 local domain_name="$1"; shift
58 local domain_file="/etc/bind/${domain_name}.conf"
60 echo "adding a new domain configured by ${domain_file} into"
61 echo "the named.conf.local configuration file."
63 # append the reference to the new conf file in the zone list.
65 zone \"${domain_name}\" in {
66 file \"${domain_file}\";
71 ////////////////////////////////////////////////////////////////////////////
73 " >> /etc/bind/named.conf.local
75 # keep ownership for the real user.
76 chown "$(logname):$(logname)" /etc/bind/named.conf.local
77 test_or_die "setting ownership on: /etc/bind/named.conf.local"
81 # adds a new subdomain under a containing domain.
82 function add_new_subdomain()
84 local new_domain="$1"; shift
86 # split up the full domain name into subdomain portion and containing domain.
87 local subdomain="${new_domain%.*.*}"
88 local containing_domain="${new_domain#*.}"
90 echo "adding a subdomain $subdomain to containing domain $containing_domain"
92 local domain_file="/etc/bind/${containing_domain}.conf"
93 # see if config file already exists; if not, complain.
94 if [ ! -f "$domain_file" ]; then
95 echo "The domain configuration file for $new_domain is missing."
96 echo "It should already be present in: $domain_file"
97 echo "Please add the containing domain before trying to add a subdomain."
101 # see if subdomain already present in config.
102 if [ $(grep -q "$new_domain" "$domain_file") ]; then
103 echo "The subdomain $subdomain already seems to exist in the domain"
104 echo "configuration file: $domain_file"
105 echo "Please edit the config file to remove the subdomain before trying"
106 echo "to re-add the subdomain."
110 # append the new subdomain into the config file.
112 ${subdomain}.${containing_domain}. IN A ${IP_ADDRESS}
113 IN HINFO \"linux server\" \"${DISTRO}\"
114 " >> /etc/bind/${containing_domain}.conf
116 # keep ownership for real user.
117 chown "$(logname):$(logname)" "/etc/bind/${containing_domain}.conf"
118 test_or_die "setting ownership on: /etc/bind/${containing_domain}.conf"
121 function restart_bind()
123 echo restarting DNS server.
124 service bind9 restart
125 if [ $? -ne 0 ]; then
126 echo "The bind service did not restart properly. Please check the error logs."
129 echo DNS server restarted.