<?xml version="1.0"?>

<encap_profile
	profile_ver="1.0"
	pkgspec="sendmail-8.12.10tcb1"
>

<prereq package="m4-1.4" use_bin="yes" />
<prereq package="nph-1.2.2" use_lib="yes" />
<prereq package="db-4.1.25" />
<prereq package="cyrus_sasl-2.1.15" />

PLATFORM_IF_MATCH(solaris9\|aix5)
<prereq package="fileutils-4.1" use_bin="yes" />
PLATFORM_ENDIF

PLATFORM_IF_MATCH(solaris9)
<prereq package="binutils-2.12.1" use_bin="yes" />
<prereq package="gcc-3.2" use_bin="yes" />
PLATFORM_ELSE_IF_MATCH(solaris8)
<prereq package="gcc-2.95.3" use_bin="yes" />
PLATFORM_ENDIF


<source
   url="ftp://uiarchive.uiuc.edu/mirrors/ftp/ftp.sendmail.org/pub/sendmail/sendmail.8.12.10.tar.gz ftp://ftp.sendmail.org/pub/sendmail/sendmail.8.12.10.tar.gz"
   subdir="sendmail-8.12.10"
>

<configure><![CDATA[
echo "dnl ### Site Configuration" > site.config.m4
echo "APPENDDEF(\`confINCDIRS', \`${CPPFLAGS}')" >> site.config.m4
echo "APPENDDEF(\`confLIBDIRS', \`${LDFLAGS}')" >> site.config.m4
echo "APPENDDEF(\`confLIBDIRS', \`-L/usr/local/lib')" >> site.config.m4
echo "" >> site.config.m4
echo "dnl ### OpenSSL stuff" >> site.config.m4
echo "define(\`confSTDIO_TYPE', \`portable')" >> site.config.m4
echo "APPENDDEF(\`conf_sendmail_ENVDEF', \`-DSTARTTLS -DHASURANDOMDEV -D_FFR_SMTP_SSL')" >> site.config.m4
echo "APPENDDEF(\`conf_sendmail_LIBS', \`-lssl -lcrypto')" >> site.config.m4
echo "APPENDDEF(\`confLIBDIRS', \`-L/usr/local/ssl/lib')" >> site.config.m4
echo "APPENDDEF(\`confINCDIRS', \`-I/usr/local/ssl/include')" >> site.config.m4
echo "" >> site.config.m4
echo "dnl ### libphclient" >> site.config.m4 
echo "PREPENDDEF(\`confMAPDEF', \`-DPH_MAP -DNPH_VERSION=10200')" >> site.config.m4
echo "APPENDDEF(\`confLIBS', \`-lphclient')" >> site.config.m4
echo "" >> site.config.m4
echo "dnl ### SASL Support" >> site.config.m4
echo "APPENDDEF(\`confENVDEF', \`-DSASL=20115')" >> site.config.m4
echo "APPENDDEF(\`conf_sendmail_LIBS', \`-lsasl2')" >> site.config.m4
echo "APPENDDEF(\`confLIBDIRS', \`-L/usr/local/lib/sasl2')" >> site.config.m4
echo "APPENDDEF(\`confINCDIRS', \`-I/usr/local/lib/sasl2')" >> site.config.m4
echo "" >> site.config.m4
echo "dnl ### Other Stuff" >> site.config.m4
PLATFORM_IF_MATCH(linux)
echo "APPENDDEF(\`confMAPDEF', \`-DMAP_REGEX')" >> site.config.m4
PLATFORM_ELSE_IF_MATCH(sparc-solaris)
echo "APPENDDEF(\`confMAPDEF', \`-DNDBM -DNIS -DNISPLUS -DMAP_REGEX')" >> site.config.m4
PLATFORM_ENDIF
PLATFORM_IF_MATCH(irix)
PLATFORM_ELSE
echo "APPENDDEF(\`conf_sendmail_ENVDEF', \`-DMILTER')" >> site.config.m4
echo "APPENDDEF(\`conf_libmilter_ENVDEF', \`-D_FFR_MILTER_ROOT_UNSAFE')" >> site.config.m4
PLATFORM_ENDIF
]]></configure>

<build><![CDATA[
cd ${srcdir} && LD_RUN_PATH=/usr/local/lib:/usr/lib:/lib ./Build -O ${builddir} -f ${builddir}/site.config.m4
PLATFORM_IF_MATCH(irix)
PLATFORM_ELSE
cd ${srcdir}/libmilter && ./Build -O ${builddir} -f ${builddir}/site.config.m4
PLATFORM_ENDIF
]]></build>

<clean><![CDATA[
cd ${srcdir} && ./Build -O ${builddir} clean
]]></clean>

<install><![CDATA[
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/adm/sm.bin
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/bin
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/etc/mail
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/libexec
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man1
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man5
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin

echo install -m 2555 -g smmsp `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/sendmail ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 2555 -g smmsp `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/sendmail ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/sendmail.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8
install -m 644 `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/aliases.5 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man5
install -m 644 `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/mailq.1 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man1
install -m 644 `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/newaliases.1 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man1
install -m 644 `cd ${srcdir}/sendmail && ./Build -M -O ${builddir}`/helpfile ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/etc/mail

install -m 555 `cd ${srcdir}/editmap && ./Build -M -O ${builddir}`/editmap ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 `cd ${srcdir}/editmap && ./Build -M -O ${builddir}`/editmap.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 `cd ${srcdir}/mail.local && ./Build -M -O ${builddir}`/mail.local ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 `cd ${srcdir}/mail.local && ./Build -M -O ${builddir}`/mail.local.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 `cd ${srcdir}/mailstats && ./Build -M -O ${builddir}`/mailstats ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 `cd ${srcdir}/mailstats && ./Build -M -O ${builddir}`/mailstats.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 `cd ${srcdir}/makemap && ./Build -M -O ${builddir}`/makemap ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 `cd ${srcdir}/makemap && ./Build -M -O ${builddir}`/makemap.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 `cd ${srcdir}/praliases && ./Build -M -O ${builddir}`/praliases ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 `cd ${srcdir}/praliases && ./Build -M -O ${builddir}`/praliases.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 `cd ${srcdir}/smrsh && ./Build -M -O ${builddir}`/smrsh ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/libexec
install -m 644 `cd ${srcdir}/smrsh && ./Build -M -O ${builddir}`/smrsh.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 `cd ${srcdir}/vacation && ./Build -M -O ${builddir}`/vacation ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/bin
install -m 644 `cd ${srcdir}/vacation && ./Build -M -O ${builddir}`/vacation.1 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man1

PLATFORM_IF_MATCH(irix)
PLATFORM_ELSE
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/lib
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/include/libmilter
mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/libmilter
install -m 644 `cd ${srcdir}/libmilter && ./Build -M -O ${builddir}`/libmilter.a ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/lib
install -m 644 ${srcdir}/include/libmilter/mfapi.h ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/include/libmilter
install -m 644 ${srcdir}/include/libmilter/mfdef.h ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/include/libmilter
(cd ${srcdir}/libmilter/docs && tar -cf - .) | (cd ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/libmilter && tar -xvvf -)
chown -R 0:0 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/libmilter
PLATFORM_ENDIF

install -m 555 ${srcdir}/contrib/qtool.pl ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin
install -m 644 ${srcdir}/contrib/qtool.8 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/man/man8

install -m 555 ${srcdir}/contrib/cidrexpand ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin

mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail
(cd ${srcdir}/cf && tar -cf - .) | (cd ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail && tar -xvvf -)
chown -R 0:0 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail

install -m 644 ${srcdir}/contrib/domainmap.m4 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/feature

mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/sendmail
install -m 644 ${srcdir}/doc/op/op.me ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/sendmail
echo "install -m 644 ${srcdir}/doc/op/op.ps ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/sendmail"
install -m 644 ${srcdir}/doc/op/op.ps ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/doc/sendmail

mkdir -p ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/lib/sasl2
touch ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/lib/sasl2/Sendmail.conf
echo "pwcheck_method: saslauthd" >> ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/lib/sasl2/Sendmail.conf

install -m 644 ${srcdir}/site.config.m4 ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/etc/mail
]]></install>

</source>


<include_file name="README"><![CDATA[
INSTALLING
----------

You must have the Encaps of procmail-3.22 and m4-1.4 (or more recent)
installed before installing this sendmail Encap.

BUILD INFORMATION
-----------------

This Encap of sendmail was built from the stock sendmail-8.12.9 source
code.  It was built with support for the PH map class, OpenSSL, and SASL.  
It was based on the UIUC encap build of sendmail - please see:

   http://www-psg.cites.uiuc.edu/sendmail/
   http://www.encap.org/
   http://www.ks.uiuc.edu/Group/Computers/Sysadmin/Mail/sendmail.html

]]></include_file>

<include_file name="preinstall" mode="0755"><![CDATA[
#!/bin/sh

# if sendmail isn't running, procede with installation
PLATFORM_IF_MATCH(linux)
SENDMAIL=`ps -efw | grep '[s]endmail' | egrep -v 'epkg|preinstall'`
PLATFORM_ELSE
SENDMAIL=`ps -ef | grep '[s]endmail' | egrep -v "epkg|preinstall|${ENCAP_PKGNAME}"`;
PLATFORM_ENDIF

if [ -n "${SENDMAIL}" ]; then
	# sendmail is currently running - output error message and abort
	cat <<EOF

ERROR: A pre-existing sendmail daemon is currently running!

To procede, you must kill the sendmail daemon and run the
installation command again.

Once the installation is complete, you will need to generate a new
sendmail configuration file.  For more information, please see:

   http://www-psg.cites.uiuc.edu/sendmail/

EOF
	exit 1
fi

echo "creating: ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/rotate_queues.sh";
sed "s|@ENCAP_TARGET@|${ENCAP_TARGET}|g" \
	"${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/rotate_queues.sh.in" \
	> "${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/rotate_queues.sh";
chmod 755 "${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/rotate_queues.sh";

]]></include_file>

<include_file name="postinstall" mode="0755"><![CDATA[
#!/bin/sh

### procedure to delete a pre-existing file, saving a backup if needed
### usage: delete_orig /path/to/src
delete_orig() {
	if [ -h "$1" ]; then
		echo "   removing link: $1";
		rm -f "$1";
	elif [ -f "$1" ]; then
		echo "   moving: $1 -> ${1}.pre.${ENCAP_PKGNAME}";
		mv "$1" "${1}.pre.${ENCAP_PKGNAME}";
	fi
}

### procedure to create a link
### usage: dolink /path/to/file ../relative/link/path
dolink() {
	delete_orig "$1";
	echo "   linking: $1 -> $2";
	ln -sf "$2" "$1";
}

### procedure to move a file
### usage: savemove /path/to/src /path/to/dest
safemove() {
	if [ -f "$1" -a ! -h "$1" ]; then
		echo "   moving: $1 -> $2";
		mv "$1" "$2";
	fi
}

### procedure to change the ownership and mode of a file or directory
### usage: setperms /path/to/file mode owner group
setperms() {
	echo "   changing permissions: $1 ($2 ${3}:${4})";
	chmod "$2" "$1";
	chown "${3}:${4}" "$1";
}


### procedure to create a group
### usage: creategroup name gid
creategroup() {
	# find next unused gid starting at $2
PLATFORM_IF_MATCH(sparc-solaris)
	NEWGID=`/bin/nawk -F: '{ gids[$3] = 1; } END { for (n='$2'; n in gids; n++); print n; }' /etc/group`;
PLATFORM_ELSE
	NEWGID=`/bin/awk -F: '{ gids[$3] = 1; } END { for (n='$2'; n in gids; n++); print n; }' /etc/group`;
PLATFORM_ENDIF

	echo "   creating group: $1 (gid $NEWGID)";
PLATFORM_IF_MATCH(rs6000-aix)
	/usr/bin/mkgroup id="$NEWGID" "$1";
PLATFORM_ELSE_IF_MATCH(irix)
	echo "${1}:*:${NEWGID}:" >> /etc/group;
PLATFORM_ELSE
	/usr/sbin/groupadd -g "$NEWGID" "$1";
PLATFORM_ENDIF
}


### procedure to create a user
### usage: createuser name uid gid home gecos
createuser() {
	# find next unused uid starting at $2
PLATFORM_IF_MATCH(sparc-solaris)
	NEWUID=`/bin/nawk -F: '{ uids[$3] = 1; } END { for (n='$2'; n in uids; n++); print n; }' /etc/passwd`;
PLATFORM_ELSE
	NEWUID=`/bin/awk -F: '{ uids[$3] = 1; } END { for (n='$2'; n in uids; n++); print n; }' /etc/passwd`;
PLATFORM_ENDIF

	echo "   creating user: $1 (id=$NEWUID/$3 home=$4)";
PLATFORM_IF_MATCH(rs6000-aix)
	/usr/bin/mkuser id="$NEWUID" pgrp="$3" home="$4" gecos="$5" "$1";
PLATFORM_ELSE_IF_MATCH(irix)
	GID=`awk -F: '$1 == "'$3'" { print $3 }' /etc/group`;
	echo "${1}:x:${NEWUID}:${GID}:${5}:${4}:" >> /etc/passwd;
	if [ -f /etc/shadow ]; then
		echo "${1}:*LK*:::::::" >> /etc/shadow;
	fi
PLATFORM_ELSE
	/usr/sbin/useradd -u "$NEWUID" -g "$3" -d "$4" -c "$5" "$1";
PLATFORM_ENDIF
}


umask 022;
PATH=/bin:/usr/bin; export PATH;


echo "Checking for smmsp user and group...";
awk -F: '$1 == "smmsp" { exit(1); }' /etc/group \
	&& creategroup smmsp 25;
awk -F: '$1 == "smmsp" { exit(1); }' /etc/passwd \
	&& createuser smmsp 25 smmsp /var/spool/clientmqueue \
		"sendmail message submission program";


echo "Setting permissions...";
setperms / 755 0 0;
setperms /etc 755 0 0;
if [ ! -d /etc/mail ]; then
	echo "   creating directory: /etc/mail";
	mkdir /etc/mail;
fi
setperms /etc/mail 755 0 0;
setperms /var 755 0 0;
setperms /var/spool 755 0 0;
if [ ! -d /var/spool/mqueue ]; then
	echo "   creating directory: /var/spool/mqueue";
	mkdir /var/spool/mqueue;
fi
setperms /var/spool/mqueue 755 0 0;
if [ ! -d /var/spool/clientmqueue ]; then
	echo "   creating directory: /var/spool/clientmqueue";
	mkdir /var/spool/clientmqueue;
fi
setperms /var/spool/clientmqueue 770 smmsp smmsp;
setperms "${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/sendmail" 2555 0 smmsp;


echo "Creating links to Encap files...";
for n in /usr/sbin/sendmail /usr/sbin/makemap /etc/mail/helpfile; do
	delete_orig ${n};
	dolink ${n} ${ENCAP_TARGET}`echo ${n}|sed 's|^/usr||'`;
done


echo "Creating links to sendmail...";
for n in /usr/lib/sendmail /usr/bin/hoststat /usr/bin/purgestat \
         /usr/bin/newaliases /usr/sbin/newaliases \
         /usr/bin/mailq /usr/sbin/mailq; do
	delete_orig ${n};
	dolink ${n} /usr/sbin/sendmail;
done

if [ ! -d /usr/lib/sasl2 ]; then
	ln -s /usr/local/lib/sasl2 /usr/lib
fi

echo "Creating links to makemap...";
delete_orig /usr/bin/makemap;
dolink /usr/bin/makemap /usr/sbin/makemap;

echo "Updating config file locations...";
# save sendmail.cf
grep "^#####  ${ENCAP_PKGNAME} " /etc/mail/sendmail.cf > /dev/null 2>&1 \
	|| delete_orig /etc/mail/sendmail.cf;
delete_orig /etc/sendmail.cf;
dolink /etc/sendmail.cf mail/sendmail.cf;

# make sure aliases file is in /etc/mail
if [ ! -f /etc/mail/aliases ]; then
	safemove /etc/aliases /etc/mail/aliases;
	if [ ! -f /etc/mail/aliases ]; then
		touch /etc/mail/aliases;
	fi
fi
dolink /etc/aliases mail/aliases

# move sendmail.st to statistics
safemove /etc/mail/sendmail.st /etc/mail/statistics;
if [ ! -f /etc/mail/statistics ]; then
	safemove /etc/sendmail.st /etc/mail/statistics;
	if [ ! -f /etc/mail/statistics ]; then
		touch /etc/mail/statistics;
	fi
fi
dolink /etc/mail/sendmail.st statistics;

# link sendmail.hf to helpfile
delete_orig /etc/mail/sendmail.hf;
dolink /etc/mail/sendmail.hf helpfile;

# move sendmail.cw to local-host-names
safemove /etc/mail/sendmail.cw /etc/mail/local-host-names;
if [ ! -f /etc/mail/local-host-names ]; then
	safemove /etc/sendmail.cw /etc/mail/local-host-names;
fi
if [ -f /etc/mail/local-host-names ]; then
	dolink /etc/mail/sendmail.cw local-host-names;
fi

# make sure smrsh admin directory exists
if [ ! -d /usr/adm ]; then
	echo "   creating directory: /usr/adm";
	mkdir /usr/adm;
fi
if [ ! -f /usr/adm/sm.bin ]; then
	dolink /usr/adm/sm.bin ${ENCAP_TARGET}/adm/sm.bin;
fi

# install config files
echo "   installing: /etc/mail/submit-base.cf";
${ENCAP_TARGET}/bin/m4 \
	${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/m4/cf.m4 \
	${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/cf/submit.mc \
	> /etc/mail/submit-base.cf
echo "   installing: /etc/mail/ks-standalone.cf";
${ENCAP_TARGET}/bin/m4 \
	${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/m4/cf.m4 \
	${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/cf/ks-standalone.mc \
	> /etc/mail/ks-standalone.cf
echo "   installing: /etc/mail/ks-submit.cf";
${ENCAP_TARGET}/bin/m4 \
	${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/m4/cf.m4 \
	${ENCAP_SOURCE}/${ENCAP_PKGNAME}/share/sendmail/cf/ks-submit.mc \
	> /etc/mail/ks-submit.cf


# set up rc scripts
PLATFORM_IF_MATCH(rs6000-aix4)
/usr/bin/nawk '{ \
	if ( $0 ~ "^start /usr/lib/sendmail" ) { \
		print "# ", $0; \
		if ( ! gotcha ) { \
			print "/usr/sbin/sendmail -bd -q20m && echo \"started sendmail (MTA)\""; \
			print "/usr/sbin/sendmail -L sm-msp -Ac -q20m && echo \"Started sendmail (MSP)\""; \
		} \
		gotcha = 1; \
	} else if ( $0 ~ "^/usr/sbin/sendmail " ) { \
		if ( ! gotcha ) { \
			print "/usr/sbin/sendmail -bd -q20m && echo \"started sendmail (MTA)\""; \
			print "/usr/sbin/sendmail -L sm-msp -Ac -q20m && echo \"Started sendmail (MSP)\""; \
		} \
		gotcha = 1; \
	} else { \
		print; \
	} \
}' < /etc/rc.tcpip > /etc/rc.tcpip.new.$$;
cmp -s /etc/rc.tcpip /etc/rc.tcpip.new.$$;
if [ $? -ne 0 ]; then
	echo "   updating rc script: /etc/rc.tcpip";
	delete_orig /etc/rc.tcpip;
	mv /etc/rc.tcpip.new.$$ /etc/rc.tcpip;
	chmod 774 /etc/rc.tcpip;
else
	rm -f /etc/rc.tcpip.new.$$;
fi
PLATFORM_ELSE_IF_MATCH(rs6000-aix5)
/usr/bin/nawk '{ \
	if ( $0 ~ "^start /usr/lib/sendmail" ) { \
		printf "# "; \
	} \
	print; \
}' < /etc/rc.tcpip > /etc/rc.tcpip.new.$$;
cmp -s /etc/rc.tcpip /etc/rc.tcpip.new.$$;
if [ $? -ne 0 ]; then
	echo "   updating rc script: /etc/rc.tcpip";
	delete_orig /etc/rc.tcpip;
	mv /etc/rc.tcpip.new.$$ /etc/rc.tcpip;
	chmod 774 /etc/rc.tcpip;
else
	rm -f /etc/rc.tcpip.new.$$;
fi

RC_DIR="/etc/rc.d";
SCRIPT_NAME="sendmail";
OFF_LINK="K01sendmail";
OFF_LEVELS="";
ON_LINK="S99sendmail";
ON_LEVELS="2";

if [ ! -d "${RC_DIR}/init.d" ]; then
	echo "   creating directory: ${RC_DIR}/init.d";
	mkdir "${RC_DIR}/init.d";
fi
PLATFORM_ELSE_IF_MATCH(hpux)
RC_DIR="/sbin";
SCRIPT_NAME="sendmail";
OFF_LINK="K460sendmail";
OFF_LEVELS="1";
ON_LINK="S540sendmail";
ON_LEVELS="2";
PLATFORM_ELSE_IF_MATCH(sparc-solaris)
RC_DIR="/etc";
SCRIPT_NAME="sendmail";
OFF_LINK="K36sendmail";
OFF_LEVELS="0 1 S";
ON_LINK="S88sendmail";
ON_LEVELS="2";
PLATFORM_ELSE_IF_MATCH(irix)
RC_DIR="/etc";
SCRIPT_NAME="mail";
OFF_LINK="K20mail";
OFF_LEVELS="0";
ON_LINK="S50mail";
ON_LEVELS="2";
PLATFORM_ELSE_IF_MATCH(linux)
RC_DIR="/etc/rc.d";
SCRIPT_NAME="sendmail";
OFF_LINK="K30sendmail";
OFF_LEVELS="0 1 6";
ON_LINK="S80sendmail";
ON_LEVELS="2 3 4 5";
PLATFORM_ENDIF

PLATFORM_IF_MATCH(rs6000-aix4)
PLATFORM_ELSE
SCRIPT="${RC_DIR}/init.d/${SCRIPT_NAME}";
cmp -s ${SCRIPT} ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sendmail.rc;
if [ $? -ne 0 ]; then
	echo "   installing: ${SCRIPT}";
	if [ -f "${SCRIPT}" ]; then
		cp ${SCRIPT} ${SCRIPT}.pre.${ENCAP_PKGNAME};
	fi
	cp ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sendmail.rc ${SCRIPT};
	chmod +x ${SCRIPT};
	for level in ${ON_LEVELS}; do
		rm -f "${RC_DIR}/rc${level}.d/${ON_LINK}";
		dolink "${RC_DIR}/rc${level}.d/${ON_LINK}" "../init.d/${SCRIPT_NAME}";
	done
	for level in ${OFF_LEVELS}; do
		rm -f "${RC_DIR}/rc${level}.d/${OFF_LINK}";
		dolink "${RC_DIR}/rc${level}.d/${OFF_LINK}" "../init.d/${SCRIPT_NAME}";
	done
fi
PLATFORM_ENDIF


# print message about configuration
cat <<EOF

Installation of sendmail support files and links is now complete!

Before you can use sendmail, you may need to create a configuration file
using the macros in the share/sendmail/ directory of the sendmail Encap.
For more information on sendmail configuration, please see:

   http://www-psg.cites.uiuc.edu/sendmail/

Two macro files which should be useful for our sysystems have bene installed in the share/sendmail/cf/ directory of the Encap:

   ks-standalone.mc	For the mail server
   ks-submit.mc		For the clients

Configuration files for each of these have been generated and put into 
/etc/mail/[filename].cf .  If you want to use them (they are reasonable 
setups), just symlink them into /etc/mail/sendmail.cf and submit.cf and 
start sendmail.

You should also start 'saslauthd -a pam' on start.  For the record.

Full documentation is available at:

   http://www.ks.uiuc.edu/Group/Computers/Sysadmin/Mail/sendmail.html

EOF

]]></include_file>


<include_file name="postremove" mode="0755"><![CDATA[
#!/bin/sh

echo "removing: ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/rotate_queues.sh";
rm -f ${ENCAP_SOURCE}/${ENCAP_PKGNAME}/sbin/rotate_queues.sh;

]]></include_file>


PLATFORM_IF_MATCH(rs6000-aix4)
PLATFORM_ELSE
<include_file name="sendmail.rc" mode="0755"><![CDATA[
#!/bin/sh

case "$1" in 
'start')
	/usr/sbin/sendmail -bd -q20m && echo "Started sendmail (MTA)"
	if [ -s /etc/mail/submit.cf ]; then
		/usr/sbin/sendmail -L sm-msp -Ac -q20m && echo "Started sendmail (MSP)"
	fi
	;;

'stop')
	PIDS=`ps -ef | awk '/[s]endmail/ { print $2 }'`
	if [ -n "${PIDS}" ]; then
		kill ${PIDS}
	fi
	;;

*)
	echo "Usage: $0 { start | stop }"
	exit 1
	;;
esac
exit 0
]]></include_file>
PLATFORM_ENDIF


<include_file name="sbin/rotate_queues.sh.in" mode="0755"><![CDATA[
#!/bin/sh

PATH=@ENCAP_TARGET@/bin:$PATH;
export PATH;

QUEUE_ROOT=/var/spool/mqueue;

# q2 - messages older than 45 mins
if [ -n "`ls ${QUEUE_ROOT}/q1`" ]; then
        @ENCAP_TARGET@/sbin/qtool \
                -s 2700 \
                ${QUEUE_ROOT}/q2 \
                ${QUEUE_ROOT}/q1;
fi

# q3 - messages older than 3 hours
if [ -n "`ls ${QUEUE_ROOT}/q2`" ]; then
        @ENCAP_TARGET@/sbin/qtool \
                -s 10800 \
                ${QUEUE_ROOT}/q3 \
                ${QUEUE_ROOT}/q2;
fi

# q4 - messages older than 1 day
if [ -n "`ls ${QUEUE_ROOT}/q3`" ]; then
        @ENCAP_TARGET@/sbin/qtool \
                -s 86400 \
                ${QUEUE_ROOT}/q4 \
                ${QUEUE_ROOT}/q3;
fi

# q5 - messages older than 3 days
if [ -n "`ls ${QUEUE_ROOT}/q4`" ]; then
        @ENCAP_TARGET@/sbin/qtool \
                -s 259200 \
                ${QUEUE_ROOT}/q5 \
                ${QUEUE_ROOT}/q4;
fi

]]></include_file>

<include_file name="share/sendmail/cf/ks-standalone.mc"><![CDATA[
VERSIONID(`sendmail-8.12.9 '__file__)dnl
OSTYPE(solaris2)dnl

dnl ### set up paths
define(`confCW_FILE', `-o /etc/mail/local-host-names')dnl
define(`confEBINDIR', `/usr/local/libexec')dnl

dnl ### Always use dbm databases
define(`DATABASE_MAP_TYPE', `dbm')dnl

dnl ### security paranoia
define(`confMAX_MESSAGE_SIZE', `10485760')dnl	### 10 MB 
define(`confPRIVACY_FLAGS', `goaway,noetrn,noreceipts,nobodyreturn,restrictqrun,restrictmailq')dnl
define(`confQUEUE_LA', `10')dnl
define(`confREFUSE_LA', `12')dnl
dnl ### define(`confBIND_OPTS', `WorkAroundBrokenAAAA')dnl

dnl ### KS configuration stuff, above the WSG things
define(`confME_TOO', `True')dnl
define(`confCT_FILE', `-o /etc/mail/sendmail.ct')dnl
MASQUERADE_AS(`ks.uiuc.edu')dnl
MASQUERADE_DOMAIN(`ks.uiuc.edu')
FEATURE(allmasquerade)dnl
EXPOSED_USER(root)dnl
FEATURE(redirect)dnl
define(`confDONT_BLAME_SENDMAIL', `GroupWritableDirPathSafe,
	GroupWritableForwardFileSafe,
        GroupWritableIncludeFileSafe,
        GroupWritableAliasFile,
        ForwardFileInGroupWritableDirPath,
        IncludeFileInGroupWritableDirPath,
        ForwardFileInUnsafeDirPath,
        IncludeFileInUnsafeDirPath,
        ForwardFileInUnsafeDirPathSafe,
        IncludeFileInUnsafeDirPathSafe')dnl

dnl ### features
FEATURE(local_procmail)dnl
FEATURE(`access_db', `DATABASE_MAP_TYPE -o -T<TMPF> /etc/mail/access')dnl
FEATURE(blacklist_recipients)dnl
FEATURE(always_add_domain)dnl
FEATURE(use_cw_file)dnl
FEATURE(`nouucp', `reject')dnl
FEATURE(use_ct_file)dnl

dnl ### set up PH redirection
define(`DOMAINMAP_ADDRTYPE', `1')dnl
FEATURE(domainmap, `uiuc.edu', `ph -D -l 30 -h phquery.uiuc.edu')dnl

dnl ### SASL configuration stuff - bad so far

define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 PLAIN LOGIN')dnl
TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 PLAIN LOGIN')dnl

dnl ### What ports should we run on?
FEATURE(`no_default_msa')dnl 	turn off default entry for MSA
DAEMON_OPTIONS(`Port=587, Name=MSA,     M=E')dnl
DAEMON_OPTIONS(`Port=465, Name=MTA-SSL, M=s')dnl
DAEMON_OPTIONS(`Port=25,  Name=MTA')dnl

dnl ### SSL stuff
define(`CERT_DIR',        `/etc/mail/certs')dnl
define(`confCACERT_PATH', `CERT_DIR')dnl
define(`confCACERT',      `CERT_DIR/CAcert.pem')dnl
define(`confSERVER_CERT', `CERT_DIR/mailhost.pem')dnl
define(`confSERVER_KEY',  `CERT_DIR/mailhost.key.pem')dnl
define(`confCLIENT_CERT', `CERT_DIR/mailhost.pem')dnl
define(`confCLIENT_KEY',  `CERT_DIR/mailhost.key.pem')dnl

dnl ### Only allow the PLAIN/LOGIN opts if we're connecting in a secure manner
define(`confAUTH_OPTIONS', `p y')dnl	

dnl ### Better compatibility with the rest of the world
define(`confTLS_SRV_OPTIONS', `V')dnl

dnl ### mailers
MAILER(`local')dnl
MAILER(`smtp')dnl
]]></include_file>

<include_file name="share/sendmail/cf/ks-submit.mc"><![CDATA[
VERSIONID(`sendmail-8.12.9 '__file__)dnl
define(`confCF_VERSION', `Submit')dnl
define(`__OSTYPE__',`')dnl dirty hack to keep proto.m4 from complaining
define(`_USE_DECNET_SYNTAX_', `1')dnl support DECnet
FEATURE(`msp',`mailhost.ks.uiuc.edu')dnl
]]></include_file>

<prepackage type="unset" />

<encapinfo>
linkdir share/sendmail
exclude sbin/rotate_queues.sh.in
prereq pkgspec >= m4-1.4
prereq pkgspec >= procmail-3.22
prereq pkgspec >= db-4.1.25
prereq pkgspec >= cyrus_sasl-2.1.15
linkname sbin/qtool.pl qtool
linkname sbin/rotate_queues.sh rotate_queues
</encapinfo>

</encap_profile>


