#!/bin/bash

echo -n "Please enter the IP address of this server: "
read IPAddress
echo -n "Please enter the hostname of this server: "
read HOST
echo -n "Plase enter the domain name for this environment: "
read DOMAIN
echo ""

ZoneFileHeader=$"\$TTL 1D
@       IN SOA  @ $HOST.$DOMAIN. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
\$ORIGIN $DOMAIN.
$DOMAIN.     IN      NS      $HOST.$DOMAIN.
$HOST        IN      A       $IPAddress"

echo "$ZoneFileHeader" > /var/named/$DOMAIN.zone

/usr/local/nmis8/admin/model_audit.pl > hostData.csv

zulu=0
cat hostData.csv | while read i; do
	doorLight='GREEN'
	let "zulu++"
	#echo $zulu
        name=$(echo $i | awk -F ',' '{print $1}' | tr '"' ' ' | awk '{print $1}')
        address=$(echo $i | awk -F ',' '{print $2}' | tr '"' ' ' | awk '{print $1}')
	if [ $zulu -eq 1 ] || [ $name == 'localhost' ] ; then
		doorLight='RED'
	fi
	if [ $doorLight == 'GREEN' ]; then
        	echo "$name     IN      A       $address" >> /var/named/$DOMAIN.zone
	fi
done

echo "Zone file created.  Please review /var/named/$DOMAIN.zone"

