#!/usr/bin/env bash # - Bind configuration file containing zone definitions # - ZONE_CONF_FILE=/etc/bind/named.conf.local ## -- ## -- End: Variable definitions ## *** ## *** Don't make changes after this line *** ## *** ## --- some functions ## --- echononl(){ echo X\\c > /tmp/shprompt$$ if [ `wc -c /tmp/shprompt$$ | awk '{print $1}'` -eq 1 ]; then echo -e -n "$*\\c" 1>&2 else echo -e -n "$*" 1>&2 fi rm /tmp/shprompt$$ } fatal(){ echo "" echo -e "[ \033[31m\033[1mError\033[m ]: $*" echo "" echo -e "\t\033[31m\033[1mScript is canceled\033[m\033[m" echo "" exit 1 } warn (){ echo "" echo -e "\t[ \033[33m\033[1mWarning\033[m ]: $*" echo "" } info (){ echo "" echo -e "\t[ \033[32m\033[1mInfo\033[m ]: $*" echo "" } ok (){ echo "" echo -e "\t[ \033[36m\033[1mOk\033[m ]: $*" echo "" } error(){ echo "" echo -e "\t[ \033[31m\033[1mFehler\033[m ]: $*" echo "" } echo_ok() { echo -e "\033[75G[ \033[32mok\033[m ]" } echo_failed(){ echo -e "\033[75G[ \033[1;31mfailed\033[m ]" } echo_skipped() { echo -e "\033[75G[ \033[33m\033[1mskipped\033[m ]" } containsElement () { local e for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done return 1 } ## --- ## --- END: functions hostname=$1 echo "" # - Validate Syntax of given domain # - valid_domain_regex="^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$" echononl "\tValidate syntax of given domain.." if [[ $hostname =~ $valid_domain_regex ]]; then if [[ ! $hostname =~ \. ]]; then echo_failed error "Invalid hostname/domain given!" exit 10 else echo_ok fi else echo_failed error "Invalid hostname/domain given!" exit 10 fi _failed=false while ! grep $hostname $ZONE_CONF_FILE > /dev/null 2>&1 ; do hostname=${hostname#*.} if [[ ! $hostname =~ \. ]]; then _failed=true break fi done if $_failed ; then echo "hostname \"$1\" not supported by this nameserver!" else domain=$hostname echo "domain: $domain" fi echo exit 0