#!/bin/sh
# config maintainer script for movabletype-opensource

set -e

# source debconf stuff
. /usr/share/debconf/confmodule

if [ -n "$2" ]; then
    if dpkg --compare-versions $2 lt 4.1-5; then
        db_input high movabletype-opensource/umask_warn || true
        db_go
    fi

    UPS_VERSION=`echo $2 | sed -e 's/-.*//'`
    if dpkg --compare-versions $UPS_VERSION lt 5.1.3; then
        db_input high movabletype-opensource/schema_upgrade || true
        db_go
        if [ "$RET" = "false" ]; then
            echo "Aborting install";
            db_fset movabletype-opensource/schema_upgrade seen false
            exit 1
        fi
    fi
else
    if [ -x /usr/sbin/apache2ctl ]; then
        db_input medium movabletype-opensource/reload_apache || true
        db_go
    fi
fi

db_input high movabletype-opensource/admin_account_warn || true
db_go
db_get movabletype-opensource/admin_account_warn || true
if [ "$RET" = "false" ]; then
    echo "Aborting install";
    db_fset movabletype-opensource/admin_account_warn seen false
    exit 1
fi

# we support mysql and pgsql
dbc_dbtypes="mysql, pgsql, sqlite"
# source dbconfig-common stuff
if [ -f /usr/share/dbconfig-common/dpkg/config ]; then
    . /usr/share/dbconfig-common/dpkg/config 
    dbc_go movabletype-opensource $@
fi
