#!/bin/sh -e

if [ "$1" = "configure" ] ; then
    if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
        . /usr/share/apache2/apache2-maintscript-helper
        apache2_invoke enconf intelmq-api.conf || true

        #adduser www-data intelmq
	usermod -a -G intelmq www-data
    fi
fi

# Source debconf library.
. /usr/share/debconf/confmodule
. /usr/share/dbconfig-common/dpkg/postinst.sqlite3

dbc_dbfile_owner="www-data:www-data"

dbc_go intelmq-api "$@"

db_get intelmq-api/setup
if [ "$RET" = "true" ]; then
	db_get intelmq-api/user
	ACCOUNT=$RET
	db_get intelmq-api/password
	PASSWORD=$RET

	intelmq-api-adduser --user "$ACCOUNT" --password "$PASSWORD"
	echo "Done Configuring IntelMQ API.." >&2
fi
db_stop

chown -R intelmq:intelmq /etc/intelmq
chmod -R g+w /etc/intelmq

#DEBHELPER#
