#!/bin/sh -e
# Called when a new interface comes up
# Written by LaMont Jones <lamont@debian.org>

# start or reload Postfix as needed
if [ ! -x /sbin/resolvconf ]; then
	cp /etc/resolv.conf $(postconf -h queue_directory)/etc/resolv.conf
	/etc/init.d/postfix reload >/dev/null 2>&1
fi

# If master is running, force a queue run to unload any mail that is
# hanging around.  Yes, sendmail is a symlink...
if [ -f /var/spool/postfix/pid/master.pid ]; then
	pid=$(sed 's/ //g' /var/spool/postfix/pid/master.pid)
	exe=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* //')
	if [ "X$exe" = "X/usr/lib/postfix/master" ]; then
		if [ -x /usr/sbin/sendmail ]; then
			/usr/sbin/sendmail -q
		fi
	fi
fi
