#!/bin/sh

# Must remove the area-specific envs - debconf chokes on them.
egrep "^[a-zA-Z0-9_]+=" /etc/hobbit/hobbitserver.cfg >/etc/hobbit/hobbitserver.cfg.dbinst
CONFIGFILE=/etc/hobbit/hobbitserver.cfg.dbinst

set -e
. /usr/share/debconf/confmodule

if [ -e $CONFIGFILE ]; then
   . $CONFIGFILE || true
fi

if [ "$BBSERVERHOSTNAME" != "" -a "$BBSERVERHOSTNAME" != "localhost" ]; then
   db_set hobbit/BBSERVERHOSTNAME $BBSERVERHOSTNAME
else
   db_set hobbit/BBSERVERHOSTNAME `hostname`
fi

if [ "$BBSERVERIP" != "" -a "$BBSERVERIP" != "127.0.0.1" ]; then
   db_set hobbit/BBSERVERIP $BBSERVERIP
else
   db_set hobbit/BBSERVERIP 127.0.0.1
fi

if [ "$BBSERVERWWWNAME" != "" -a "$BBSERVERWWWNAME" != "localhost" ]; then
   db_set hobbit/BBSERVERWWWNAME $BBSERVERWWWNAME
else
   db_set hobbit/BBSERVERWWWNAME `hostname`
fi

db_input medium hobbit/BBSERVERHOSTNAME || true
db_input medium hobbit/BBSERVERIP || true
db_input medium hobbit/BBSERVERWWWNAME || true
db_go || true

rm -f /etc/hobbit/hobbitserver.cfg.dbinst

