#!/bin/sh -e

. /usr/share/debconf/confmodule

# set cfg file name in default/ser file
db_input medium ser-oob/CFG_FILE || true
db_go

# configure the ser-oob.cfg file ?
db_input medium ser-oob/config || true
db_go

db_get ser-oob/config

if [ "$RET" = "false" ]; then
  exit 0
fi

db_input medium ser-oob/SERVERID || true
db_go

db_input medium ser-oob/LISTEN || true
db_go

# ask for administrative address and for replication sending addr only if listen addr was set
db_get ser-oob/LISTEN
if [ "$RET" != "" ]; then
  db_input medium ser-oob/ADMINADDR || true
  db_go
  db_input medium ser-oob/SENDADDR || true
  db_go
else
  # set admin addr to empty
  db_set ser-oob/ADMINADDR
fi

db_input medium ser-oob/DBURL || true
db_go

db_input medium ser-oob/DBURLACC || true
db_go

db_input medium ser-oob/AUTHSECRET || true
db_go

db_input medium ser-oob/RTTPPROXY || true
db_go

db_input medium ser-oob/RTP_ENABLE || true
db_go

db_input medium ser-oob/NATPING_INTERVAL || true
db_go

db_input medium ser-oob/DBMODE || true
db_go

db_input medium ser-oob/CREATE_DB || true
db_go

db_get ser-oob/CREATE_DB
if [ "$RET" = "true" ]; then
  db_input medium ser-oob/MYSQLPASS || true
  db_go
fi

db_input medium ser-oob/SERCTL_DOMAIN || true
db_go

db_get ser-oob/SERCTL_DOMAIN
if [ "$RET" != "" ]; then
  db_input medium ser-oob/SERCTL_USER || true
  db_go

  db_get ser-oob/SERCTL_USER
  if [ "$RET" != "" ]; then
    db_input medium ser-oob/SERCTL_PASS || true
    db_go
  fi
fi

