X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=scripts%2Fsystem%2Fadd_domain.sh;h=80ebb2f37d0563e6d0d9b0d768d1e9b80a0797c3;hb=f3e2e0d8a7bb96505d0dded3bfab99f1cd2a4a99;hp=00cf6de043a739083202e0a9a4757e5cdae1d69b;hpb=f15007a6d97cb4158fed81ab2d996f8d8df1b7c3;p=feisty_meow.git diff --git a/scripts/system/add_domain.sh b/scripts/system/add_domain.sh index 00cf6de0..80ebb2f3 100644 --- a/scripts/system/add_domain.sh +++ b/scripts/system/add_domain.sh @@ -8,13 +8,19 @@ # # Author: Chris Koeritz +export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. +export FEISTY_MEOW_APEX="$( \cd "$WORKDIR/../.." && \pwd )" + +source "$FEISTY_MEOW_APEX/scripts/core/launch_feisty_meow.sh" + # some defaults that are convenient for current purposes. -# hmmm: these would need to be parameterized somehow for this script to become really general. + +# hmmm: !!! these would need to be parameterized somehow for this script to become really general. # in our scheme, the single IP address that all our domains map to. IP_ADDRESS="10.28.42.20" # the email address (where first dot is replaced by @) for the administrator of the domain. -SERVER_ADMIN="fred.cakelampvm.com" +SERVER_ADMIN="developer.cakelampvm.com" # the name of the name server for the new domains (should already be configured). MAIN_NAME_SERVER="ns.cakelampvm.com" # the name of the mail server for a new domain (should already be configured). @@ -33,11 +39,13 @@ function write_new_domain_file() echo "using the config file: $domain_file" if [ -f $domain_file ]; then + echo echo "The domain configuration file already exists at:" echo " $domain_file" - echo "Please remove this file before proceeding, if it is junk. For example:" - echo " sudo rm $domain_file" - exit 1 + echo "Since we don't want to tear that down if it has specialized configuration" + echo "data in it, we will just leave it in place and consider our job done." + echo + exit 0 fi echo " @@ -52,13 +60,16 @@ function write_new_domain_file() IN NS ${MAIN_NAME_SERVER}. IN MX 10 ${MAIL_SERVER}. -${domain}. IN A ${IP_ADDRESS} +${domain_name}. IN A ${IP_ADDRESS} IN HINFO \"linux server\" \"${DISTRO}\" -" -#fix -# >"$domain_file" +" >"$domain_file" + + # our personalized configuration approach wants the real owner to own the file. + chown "$(logname):$(logname)" $domain_file + test_or_die "setting ownership on: $domain_file" } +# hooks up a new config file into bind's list of zones. function add_zone_for_new_domain() { local domain_name="$1"; shift @@ -68,17 +79,21 @@ function add_zone_for_new_domain() echo "adding a new domain configured by ${domain_file} into" echo "the named.conf.local configuration file." -# need to write the reference to the new conf file in the zone list. - -echo " + # append the reference to the new conf file in the zone list. + echo " zone \"${domain_name}\" in { file \"${domain_file}\"; type master; allow-query { any; }; }; -" -#fix -#>> /etc/bind9/named.conf.local + +//////////////////////////////////////////////////////////////////////////// + +" >> /etc/bind/named.conf.local + + # keep ownership for the real user. + chown "$(logname):$(logname)" /etc/bind/named.conf.local + test_or_die "setting ownership on: /etc/bind/named.conf.local" } @@ -115,10 +130,11 @@ function add_new_subdomain() echo " ${subdomain}.${containing_domain}. IN A ${IP_ADDRESS} IN HINFO \"linux server\" \"${DISTRO}\" -" -#fix -#>> /etc/bind/${containing_domain}.conf +" >> /etc/bind/${containing_domain}.conf + # keep ownership for real user. + chown "$(logname):$(logname)" "/etc/bind/${containing_domain}.conf" + test_or_die "setting ownership on: /etc/bind/${containing_domain}.conf" } function restart_bind() @@ -134,7 +150,7 @@ function restart_bind() # main body of script. -if (( $EUID != 0 )); then +if [[ $EUID != 0 ]]; then echo "This script must be run as root or sudo." exit 1 fi