# adds imapd and pop3 entries to /etc/inetd.conf

if [ -z "$PKG_INSTALL_ROOT" ]; then
	SERVICES=/etc/services
	SSLDIR=/etc/ssl/certs
else
	SERVICES=${PKG_INSTALL_ROOT}/etc/services
	SSLDIR=${PKG_INSTALL_ROOT}/etc/ssl/certs
fi

for f in $SERVICES ; do
	if [ ! -f $f ]; then
		cp /dev/null $f
		chmod 644 $f
	fi
done

PATH=/usr/xpg4/bin:$PATH

TMP=`egrep -c -e '^pop2[[:space:]]*.*/tcp' $SERVICES`
if [ $TMP -eq 0 ]; then
	echo 'pop2		109/tcp	pop pop-2	# Post Office Protocol - Version 2' >>$SERVICES
fi
TMP=`egrep -c -e '^pop3[[:space:]]*.*/tcp' $SERVICES`
if [ $TMP -eq 0 ]; then
	echo 'pop3		110/tcp			# Post Office Protocol - Version 3' >>$SERVICES
fi
TMP=`egrep -c -e '^imap[[:space:]]*.*/tcp' $SERVICES`
if [ $TMP -eq 0 ]; then
	echo 'imap		143/tcp			# Internet Mail Access Protocol v2' >>$SERVICES
fi
TMP=`egrep -c -e '^imaps[[:space:]]*.*/tcp' $SERVICES`
if [ $TMP -eq 0 ]; then
	echo 'imaps		993/tcp			# Internet Mail Access Protocol v2 over SSL/TLS' >>$SERVICES
fi
TMP=`egrep -c -e '^pop3s[[:space:]]*.*/tcp' $SERVICES`
if [ $TMP -eq 0 ]; then
	echo 'pop3s		995/tcp			# Internet Mail Access Protocol v2 over SSL/TLS' >>$SERVICES
fi

for cert in imapd pop3d ; do
	echo " "
	if [ ! -r ${SSLDIR}/${cert}.pem ]; then
		cp -p ${SSLDIR}/${cert}.pem.default ${SSLDIR}/${cert}.pem
		echo "NOTE: Installed self-signed SSL certificate for $cert as"
		echo "      ${SSLDIR}/${cert}.pem ! You should create or buy"
		echo "      your own SSL certificate, since using the default one"
		echo "      gives you not much security - anybody knows the key!!!"
	else
		echo "It seems, that you have already an SSL certificate for ${cert}."
		echo "Fine."
	fi
done

echo "
NOTE: Per default all services are disabled. To enable the service[s] you
      want, use the svcadm(1M) tool as usual, i.e.

      svcadm enable {pop2|pop3|pop3s|imap|imaps}
"
# vim: ts=4 filetype=sh
