#!/bin/sh
set -e

. /usr/share/debconf/confmodule
if [ -f /usr/share/dbconfig-common/dpkg/config.mysql ]; then
        . /usr/share/dbconfig-common/dpkg/config.mysql
	dbc_first_version="1.0.6-1"
	dbc_load_include="php:/etc/mantis/config.php.dpkg-old"
	dbc_go mantis $@
fi

if [ -f /etc/mailname ]; then
	MAILNAME="`cat /etc/mailname`"
fi

if [ -z "$MAILNAME" ]; then
	MAILNAME="localhost"
fi

db_set mantis/admin root@$MAILNAME
db_input medium mantis/admin || true
db_go

db_get mantis/admin
if [ ! -z "$RET" ]; then
	ADMIN="$RET"
else
	ADMIN="root@localhost"
fi

db_set mantis/from mantis@$MAILNAME
db_input medium mantis/from || true

db_set mantis/webmaster webmaster@$MAILNAME
db_input medium mantis/webmaster || true

db_set mantis/bounce $ADMIN
db_input medium mantis/bounce || true

db_input medium mantis/webserver || true

#
# If this is a fresh install, then tell the user the default administrator
# account information
#
if [ "$1" = "configure" ] && [ -z "$2" ]; then
	db_input high mantis/passwordnote || true
fi

db_go || true
