Home | History | Annotate | Line # | Download | only in rc.d
      1   1.1   thorpej #!/bin/sh
      2   1.1   thorpej #
      3  1.20       kre # $NetBSD: postfix,v 1.20 2023/12/25 08:37:08 kre Exp $
      4   1.1   thorpej #
      5   1.1   thorpej 
      6  1.16     perry # PROVIDE: mail
      7   1.1   thorpej # REQUIRE: LOGIN
      8   1.6     lukem #	we make mail start late, so that things like .forward's are not
      9   1.6     lukem #	processed until the system is fully operational
     10   1.1   thorpej 
     11   1.9   mycroft $_rc_subr_loaded . /etc/rc.subr
     12   1.1   thorpej 
     13   1.3     lukem name="postfix"
     14   1.5     lukem rcvar=$name
     15   1.8     lukem postfix_command="/usr/sbin/${name}"
     16   1.3     lukem required_files="/etc/${name}/main.cf"
     17   1.6     lukem start_precmd="postfix_precmd"
     18   1.8     lukem start_cmd="postfix_op"
     19   1.8     lukem stop_cmd="postfix_op"
     20   1.8     lukem reload_cmd="postfix_op"
     21  1.17       riz status_cmd="postfix_op"
     22  1.17       riz extra_commands="reload status"
     23   1.6     lukem spooletcdir="/var/spool/${name}/etc"
     24  1.13  christos postconf="/usr/sbin/postconf"
     25   1.6     lukem required_dirs=$spooletcdir
     26  1.12  christos 
     27  1.12  christos _rebuild() {
     28  1.12  christos 	echo "${name}: rebuilding ${1} ($2 ${1}.db)"
     29  1.13  christos 	$($postconf -h newaliases_path)
     30  1.12  christos }
     31   1.6     lukem 
     32   1.6     lukem postfix_precmd()
     33   1.6     lukem {
     34   1.6     lukem 	# As this is called after the is_running and required_dir checks
     35   1.6     lukem 	# are made in run_rc_command(), we can safely assume ${spooletcdir}
     36   1.6     lukem 	# exists and postfix isn't running at this point (unless forcestart
     37   1.6     lukem 	# is used).
     38   1.6     lukem 	#
     39   1.6     lukem 
     40   1.6     lukem 	for f in localtime resolv.conf services; do
     41   1.6     lukem 		if [ -f /etc/$f ]; then
     42   1.6     lukem 			cmp -s /etc/$f ${spooletcdir}/$f || \
     43   1.6     lukem 			    cp -p /etc/$f ${spooletcdir}/$f
     44   1.6     lukem 		fi
     45   1.6     lukem 	done
     46  1.10  christos 
     47  1.18  riastrad 	OIFS="${IFS}"
     48  1.18  riastrad 	IFS="${IFS},"
     49  1.18  riastrad 	for f in $($postconf -hx alias_database); do
     50  1.18  riastrad 		IFS="${OIFS}:"
     51  1.12  christos 		set -- $f
     52  1.12  christos 		IFS="${OIFS}"
     53  1.12  christos 		case "$1" in
     54  1.12  christos 		hash)
     55  1.12  christos 			if [ -f "$2.db" ]; then
     56  1.20       kre 				if ! [ "$2" -ot "$2.db" ]; then
     57  1.12  christos 					_rebuild "$2" "out of date"
     58  1.12  christos 				fi
     59  1.12  christos 			else
     60  1.12  christos 				_rebuild "$2" "missing"
     61  1.11  christos 			fi
     62  1.12  christos 			;;
     63  1.12  christos 		*)
     64  1.12  christos 			;;
     65  1.12  christos 		esac
     66  1.11  christos 	done
     67  1.19       rin 
     68  1.19       rin 	echo "Starting ${name}."
     69   1.6     lukem }
     70   1.1   thorpej 
     71   1.8     lukem postfix_op()
     72   1.8     lukem {
     73   1.8     lukem 	${postfix_command} ${rc_arg}
     74   1.8     lukem }
     75   1.8     lukem 
     76  1.14     pavel check_use_postfix()
     77  1.14     pavel {
     78  1.14     pavel 	_mta_path=$(awk '/^sendmail[ \t]/{print$2}' /etc/mailer.conf)
     79  1.14     pavel 	_postfix_path="/usr/libexec/postfix/sendmail"
     80  1.14     pavel 	_sendmail_path="/usr/libexec/sendmail/sendmail"
     81  1.14     pavel 
     82  1.14     pavel 	if [ "${postfix}" != "check" ]; then
     83  1.14     pavel 	    echo "${postfix}"
     84  1.14     pavel 	elif [ "${_mta_path}" = "${_postfix_path}" ]; then
     85  1.14     pavel 	    echo YES
     86  1.14     pavel 	else
     87  1.14     pavel 	    echo "WARNING: default postfix not used as not selected in mailer.conf" >&2
     88  1.20       kre 	    if [ "${_mta_path}" = "${_sendmail_path}" ] &&
     89  1.20       kre 	     ! [ -x "${_mta_path}" ]; then
     90  1.14     pavel 		echo "WARNING: mailer.conf points to the removed sendmail" >&2
     91  1.14     pavel 		echo "update /etc/mailer.conf to get a working mailer configuration" >&2
     92  1.14     pavel 	    fi
     93  1.14     pavel 	    echo NO
     94  1.14     pavel 	fi
     95  1.14     pavel }
     96  1.14     pavel 
     97  1.14     pavel # force re-evaluation of /etc/rc.conf and resetting of $sendmail
     98  1.14     pavel _rc_conf_loaded=false
     99  1.14     pavel _rc_d_postfix=check
    100   1.4     lukem load_rc_config $name
    101  1.14     pavel unset _rc_d_postfix
    102  1.14     pavel postfix=$(check_use_postfix)
    103   1.3     lukem run_rc_command "$1"
    104