postfix revision 1.13
11.1Sthorpej#!/bin/sh
21.1Sthorpej#
31.13Schristos# $NetBSD: postfix,v 1.13 2006/09/07 15:26:08 christos Exp $
41.1Sthorpej#
51.1Sthorpej
61.1Sthorpej# 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.4Slukemload_rc_config $name
731.3Slukemrun_rc_command "$1"
74