#check for existing sendmail
ls /var/log/packages/sendmail* 2> /dev/null 
if [ $? -eq 0 ]		;then
	echo "found an installed sendmail package"
	echo "renaming sendmail to /usr/sbin/sendmail.old"
	mv /usr/sbin/sendmail /usr/sbin/sendmail.old
	if [ -x /etc/rc.d/rc.sendmail ]	;then
		echo "stopping sendmail and renaming rc.sendmail to /etc/rc.d/rc.sendmail.old"
		/etc/rc.d/rc.sendmail stop > /dev/null 2>&1
		mv /etc/rc.d/rc.sendmail /etc/rc.d/rc.sendmail.old
	fi
fi

#create qmail users and groups and sort file ownerships
/var/qmail/bin/qmailctl user
/var/qmail/bin/qmailctl perms

#sort the control files
fqdn=`cat /etc/HOSTNAME`
echo "Getting your fully qualified host name from /etc/HOSTNAME"
echo "If $fqdn is wrong you will have to edit the /var/qmail/control files"

echo "Putting $fqdn into control/me..."
echo "$fqdn" > /var/qmail/control/me
chmod 644 /var/qmail/control/me

echo "Putting $fqdn into control/locals..."
echo "$fqdn" >> /var/qmail/control/locals
chmod 644 /var/qmail/control/locals

dom=${fqdn:`expr index "$fqdn" .`}
echo "Putting $dom into control/defaultdomain..."
echo "$dom" > /var/qmail/control/defaultdomain
chmod 644 /var/qmail/control/defaultdomain	

echo "Putting $fqdn into control/rcpthosts..."
echo "$fqdn" >> /var/qmail/control/rcpthosts
chmod 644 /var/qmail/control/rcpthosts
echo "Now qmail will refuse to accept SMTP messages except to $fqdn."
echo "Make sure to change rcpthosts if you add hosts to locals or virtualdomains!"
echo

#make soft links
( cd etc/qmail ; rm -rf control )
( cd etc/qmail ; ln -sf /var/qmail/control control )
( cd etc/rc.d ; rm -rf rc.sendmail.new )
( cd etc/rc.d ; ln -sf rc.qmail rc.sendmail.new )
( cd usr/sbin ; rm -rf sendmail )
( cd usr/sbin ; ln -sf /var/qmail/bin/sendmail sendmail )
( cd usr/doc/netqmail-1.05 ; ln -sf /var/qmail/doc/* ./ )
( cd usr/man/man1 ; ln -sf /var/qmail/man/man1/* ./ )
( cd usr/man/man5 ; ln -sf /var/qmail/man/man5/* ./ )
( cd usr/man/man7 ; ln -sf /var/qmail/man/man7/* ./ )
( cd usr/man/man8 ; ln -sf /var/qmail/man/man8/* ./ )
( cd var/qmail/service/qmail-send/log/main ; rm -rf main )
( cd var/qmail/service/qmail-send/log/main ; ln -sf /var/qmail/service/qmail-send/log/main main )
( cd var/qmail/service/qmail-smtpd/log/main ; rm -rf main )
( cd var/qmail/service/qmail-smtpd/log/main ; ln -sf /var/qmail/service/qmail-smtpd/log/main main )
( cd var/qmail/service/qmail-pop3d/log/main ; rm -rf main )
( cd var/qmail/service/qmail-pop3d/log/main ; ln -sf /var/qmail/service/qmail-pop3d/log/main main )
( cd var/qmail/service/qmail-qmqpd/log/main ; rm -rf main )
( cd var/qmail/service/qmail-qmqpd/log/main ; ln -sf /var/qmail/service/qmail-qmqpd/log/main main )
( cd var/qmail/service/qmail-qmtpd/log/main ; rm -rf main )
( cd var/qmail/service/qmail-qmtpd/log/main ; ln -sf /var/qmail/service/qmail-qmtpd/log/main main )

echo "If there are no problems above *and* you use maildir format (kmail, thunderbird, sylpheed, etc)"
echo "root should be able to start qmail with /etc/rc.d/rc.qmail start"
echo "if you use mbox format please first read the faq in the docs, http://www.lifewithqmail.org, etc"
echo
echo "To start qmail automatically at boot, remove <.new> from /etc/rc.d/rc.sendmail.new"


