#!/bin/sh -e

# Called when an interface disconnects
# Written by LaMont Jones <lamont@debian.org>

# start or reload Postfix as needed
RUNNING=""
# 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
		RUNNING="y"
	fi
fi

if [ ! -x /sbin/resolvconf ]; then
	cp /etc/resolv.conf $(postconf -h queue_directory)/etc/resolv.conf
	if [ -n "$RUNNING" ]; then
		/etc/init.d/postfix reload >/dev/null 2>&1
	fi
fi

exit 0
