#!/bin/sh

# Written by Gerben Wierda, Oct 2001. I waive every copyright on this and
# I also do not give any warranty.

. ./defines

# Activate binaries
if [ ! -e ${POSTFIXBACKUPDIR}/sendmail ]
then
	echo "Something is wrong: there is no existing postfix binary backup"
	exit 1;
else
	echo "Restoring postfix versions of sendmail programs from backup..."
	(cd ${POSTFIXBACKUPDIR}; tar cf - sendmail) | (cd /usr/sbin; tar xf -) 
	(cd ${POSTFIXBACKUPDIR}; tar cf - newaliases) | (cd /usr/bin; tar xf -) 
	(cd ${POSTFIXBACKUPDIR}; tar cf - mailq) | (cd /usr/bin; tar xf -)
fi

if [ -e "${PSI}" ]
then
	echo "Postfix StartupItem already exists."
else
	if [ -e "${PSIDISABLED}" ]
	then
		echo "Reinstating disabled Postfix StartupItem..."
		mv "${PSIDISABLED}" "${PSI}"
	else
		echo "Installing new default Postfix StartupItem..."
		cp -R Postfix.StartupItem "${PSI}"
	fi
fi

# De-activate sendmail in /etc/hostconfig
/usr/bin/perl -pi -e 's/MAILSERVER=-YES-/MAILSERVER=-NO-/g' /etc/hostconfig
# Activate postfix in /etc/hostconfig
if /usr/bin/grep '^POSTFIX=-NO-' /etc/hostconfig >/dev/null 2>&1; then
	/usr/bin/perl -pi -e 's/POSTFIX=-NO-/POSTFIX=-YES-/g' /etc/hostconfig
else
	echo "POSTFIX=-YES-" >>/etc/hostconfig
fi

/usr/sbin/postfix start
