#!/bin/sh -e

# Source debconf library.
. /usr/share/debconf/confmodule

db_version 2.0

if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
    # we support pgsql
    dbc_dbtypes="pgsql"
    dbc_dbuser="www-data"
    dbc_dbname='openacs'
    dbc_first_version="5.7.0+dfsg-1"

    # Old values
    if [ -f /etc/openacs/config.tcl ]; then
        # dbc_load_include doesn't recognize tcl file format, so we'll create a sh temp file with values from the config.tcl file
        confile=$(mktemp)
        sed -n '/## Debconf changes/,/## End Debconf/p;' /etc/openacs/config.tcl | sed 's/^[ \t]*set\ //;/^\#/d;s/db_host/dbserver=/;s/db_password/dbpass=/;s/db_port/dbport=/;s/db_user/dbuser=/;s/=[ \t]*/=/' > $confile
        dbc_load_include="sh:$confile"
        dbc_load_include_args="-u -s -p -P"
        rm -f $confile
    fi

    # source dbconfig-common stuff
    . /usr/share/dbconfig-common/dpkg/config
    dbc_go openacs $@
fi

# The actual configuration

OLDVERSION="$2"

db_stop

exit 0
