#!/bin/sh
named_doc_root=/var/named/chroot;
named_conf_location=$named_doc_root/etc/named.conf;
temp_file=/tmp/named.conf.temp;
user='named';
group='named';
arg1=$1;
add_after_string='include "/etc/rndc.key";';

echo -n "Enter Domain: ";
read domain;
echo "Adding $domain to $named_conf_location";
while IFS=$'\n' read -r line; do

if [ "$line" == "$add_after_string" ]; then
echo -e "zone \"$domain\" {type slave; file \"sec.$domain\"; masters { 207.36.180.31; }; };\n" >>$temp_file;
fi

echo "${line}" >>$temp_file;
done < $named_conf_location;
chown $user:$group $temp_file;
#mv $temp_file $named_conf_location;
echo "Testing our new $named_conf_location";
/usr/sbin/named-checkconf -t $named_doc_root;
if [ -s $temp_file ]; then
rm -f $temp_file;
fi
