postfix revision 1.16
11.1Sthorpej#!/bin/sh
21.1Sthorpej#
31.16Sperry# $NetBSD: postfix,v 1.16 2009/04/15 22:11:32 perry Exp $
41.1Sthorpej#
51.1Sthorpej
61.16Sperry# PROVIDE: mail
71.1Sthorpej# REQUIRE: LOGIN
81.6Slukem#	we make mail start late, so that things like .forward's are not
91.6Slukem#	processed until the system is fully operational
101.1Sthorpej
111.9Smycroft$_rc_subr_loaded . /etc/rc.subr
121.1Sthorpej
131.3Slukemname="postfix"
141.5Slukemrcvar=$name
151.8Slukempostfix_command="/usr/sbin/${name}"
161.3Slukemrequired_files="/etc/${name}/main.cf"
171.6Slukemstart_precmd="postfix_precmd"
181.8Slukemstart_cmd="postfix_op"
191.8Slukemstop_cmd="postfix_op"
201.8Slukemreload_cmd="postfix_op"
211.5Slukemextra_commands="reload"
221.6Slukemspooletcdir="/var/spool/${name}/etc"
231.13Schristospostconf="/usr/sbin/postconf"
241.6Slukemrequired_dirs=$spooletcdir
251.12Schristos
261.12Schristos_rebuild() {
271.12Schristos	echo "${name}: rebuilding ${1} ($2 ${1}.db)"
281.13Schristos	$($postconf -h newaliases_path)
291.12Schristos}
301.6Slukem
311.6Slukempostfix_precmd()
321.6Slukem{
331.6Slukem	# As this is called after the is_running and required_dir checks
341.6Slukem	# are made in run_rc_command(), we can safely assume ${spooletcdir}
351.6Slukem	# exists and postfix isn't running at this point (unless forcestart
361.6Slukem	# is used).
371.6Slukem	#
381.6Slukem
391.6Slukem	for f in localtime resolv.conf services; do
401.6Slukem		if [ -f /etc/$f ]; then
411.6Slukem			cmp -s /etc/$f ${spooletcdir}/$f || \
421.6Slukem			    cp -p /etc/$f ${spooletcdir}/$f
431.6Slukem		fi
441.6Slukem	done
451.10Schristos
461.13Schristos	for f in $($postconf -h alias_database); do
471.12Schristos		OIFS="${IFS}"
481.12Schristos		IFS="${IFS}:"
491.12Schristos		set -- $f
501.12Schristos		IFS="${OIFS}"
511.12Schristos		case "$1" in
521.12Schristos		hash)
531.12Schristos			if [ -f "$2.db" ]; then
541.12Schristos				if [ ! "$2" -ot "$2.db" ]; then
551.12Schristos					_rebuild "$2" "out of date"
561.12Schristos				fi
571.12Schristos			else
581.12Schristos				_rebuild "$2" "missing"
591.11Schristos			fi
601.12Schristos			;;
611.12Schristos		*)
621.12Schristos			;;
631.12Schristos		esac
641.11Schristos	done
651.6Slukem}
661.1Sthorpej
671.8Slukempostfix_op()
681.8Slukem{
691.8Slukem	${postfix_command} ${rc_arg}
701.8Slukem}
711.8Slukem
721.14Spavelcheck_use_postfix()
731.14Spavel{
741.14Spavel	_mta_path=$(awk '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)
751.14Spavel	_postfix_path="/usr/libexec/postfix/sendmail"
761.14Spavel	_sendmail_path="/usr/libexec/sendmail/sendmail"
771.14Spavel
781.14Spavel	if [ "${postfix}" != "check" ]; then
791.14Spavel	    echo "${postfix}"
801.14Spavel	elif [ "${_mta_path}" = "${_postfix_path}" ]; then
811.14Spavel	    echo YES
821.14Spavel	else
831.14Spavel	    echo "WARNING: default postfix not used as not selected in mailer.conf" >&2
841.14Spavel	    if [ "${_mta_path}" = "${_sendmail_path}" -a \
851.14Spavel		! -x "${_mta_path}" ]; then
861.14Spavel		echo "WARNING: mailer.conf points to the removed sendmail" >&2
871.14Spavel		echo "update /etc/mailer.conf to get a working mailer configuration" >&2
881.14Spavel	    fi
891.14Spavel	    echo NO
901.14Spavel	fi
911.14Spavel}
921.14Spavel
931.14Spavel# force re-evaluation of /etc/rc.conf and resetting of $sendmail
941.14Spavel_rc_conf_loaded=false
951.14Spavel_rc_d_postfix=check
961.4Slukemload_rc_config $name
971.14Spavelunset _rc_d_postfix
981.14Spavelpostfix=$(check_use_postfix)
991.3Slukemrun_rc_command "$1"
100