#!/bin/sh

set -e

default() {
    KILLBILL_PROPERTIES=/etc/killbill/killbill-server.properties
    [ -f $KILLBILL_PROPERTIES ] && cat $KILLBILL_PROPERTIES | grep -v ^# | grep $1 | cut -d'=' -f2 | tail -1
}

. /usr/share/debconf/confmodule

# TODO Respect previous values on upgrades when default file is installed
db_input medium killbill/username || true
db_input medium killbill/groupname || true

# Set default values for Kill Bill configuration
db_set killbill/dburl "$(default org.killbill.jetty.jdbi.url)"
db_set killbill/dbusername "$(default org.killbill.jetty.jdbi.user)"
db_set killbill/dbpassword "$(default org.killbill.jetty.jdbi.password)"

db_input medium killbill/dburl || true
db_input medium killbill/dbusername || true
db_input medium killbill/dbpassword || true

db_input medium killbill/ddl || true
db_go || true
