#!/bin/sh -e

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

# source dbconfig-common shell library, and call the hook function
if [ -f /usr/share/dbconfig-common/dpkg/config.sqlite3 ]; then
    . /usr/share/dbconfig-common/dpkg/config.sqlite3
    dbc_go intelmq-api "$@"
fi

db_input high intelmq-api/setup || true
db_go || true

MATCH="false"

db_get intelmq-api/setup
if [ "$RET" = "true" ]; then
	db_input high intelmq-api/user || true
	db_go || true
	while [ "$MATCH" = "false" ]; do
		db_input high intelmq-api/password || true
		db_go || true
		db_input high intelmq-api/password-repeat || true
		db_go || true
		db_get intelmq-api/password
		PASSWORD="$RET"
		db_get intelmq-api/password-repeat
		PASSWORD_REPEAT="$RET"
		if [ "$PASSWORD" = "$PASSWORD_REPEAT" ]; then
			MATCH="true"
		fi
	done
fi
db_go || true
