#!/bin/sh -e

set -x

CONFIG_FILE="/etc/cluebringer/cluebringer.conf"
INIT_FILE="/etc/init.d/postfix-cluebringer"
DAEMON="postfix-cluebringer"

. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst

dbc_first_version="2.0.10-1"
dbc_generate_include="template:/etc/cluebringer/cluebringer.conf"
dbc_generate_include_perms="660"
dbc_generate_include_owner="root:www-data"
dbc_generate_include_args="-o template_infile=/usr/share/doc/postfix-cluebringer/templates/cluebringer.conf -U"

dbc_go postfix-cluebringer $@


case "$1" in
	configure)

		update-rc.d $DAEMON defaults >/dev/null || exit $?

		# Verify Config is there
		if [ -f $CONFIG_FILE ]; then
			echo "config file found"
		else
			echo "Config file $CONFIG_FILE not found. Not attemting start of service." >&2
			exit 0;
		fi
	

		# Start or restart the daemon
		if [ -x "/usr/sbin/invoke-rc.d" && ]; then
				invoke-rc.d $DAEMON start || true
		else
			$INIT_FILE start >/dev/null || true
		fi

		;;
	abort-upgrade|abort-remove|abort-deconfigure)
		;;

	*)
		echo "postinst called with unknown argument '$1'" >&2
		exit 1
		;;
esac

exit 0

# Automatically added by dh_installinit
if [ -x "/etc/init.d/postfix-cluebringer" ]; then
	update-rc.d postfix-cluebringer defaults >/dev/null
	if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
		invoke-rc.d postfix-cluebringer start || exit $?
	else
		/etc/init.d/postfix-cluebringer start || exit $?
	fi
fi
# End automatically added section


