#!/bin/sh
#given list stuff on stdin, create list stuff

HOME='/usr/local/nagios/lists'
SERVER_ADDR='your.nagios.fqdn'
TEMPLATE="${HOME}/LIST_TEMPLATE"

while read i
do
        #firgure out what the servername and service names are  
        SERVER=`echo $i | cut -d\  -f1`
        SERVICE=`echo $i | sed 's/\(^[^ ]\+\) \(.*\)/\2/' |tr '[:upper:]' '[:lower:]'| tr ' ' '_'`

	echo
        echo "creating ${SERVER}-${SERVICE}"

	#create the list
        ezmlm-make ${HOME}/${SERVER}-${SERVICE} \
        /var/qmail/alias/.qmail-${SERVER}-${SERVICE}\
        ${SERVER}-${SERVICE} ${SERVER_ADDR}

	#link in the template files
	for j in `ls ${TEMPLATE}`
	do
	   rm ${HOME}/${SERVER}-${SERVICE}/$j  
           ln $TEMPLATE/$j  ${HOME}/${SERVER}-${SERVICE}/$j
	done
	#add the replyto header
	echo "Reply-To: <${SERVER_ADDR}>" >> ${HOME}/${SERVER}-${SERVICE}/headeradd

	#fix the perms
	chown -R alias.qmail ${HOME}/${SERVER}-${SERVICE}/
	chmod -R g+rwX ${HOME}/${SERVER}-${SERVICE}/
done

#fix the alias perms
chown -R alias.qmail /var/qmail/alias

