#!/bin/sh -e
# This lets debconf configure itself.

# This is to handle upgrading from old versions of debconf. If the
# file doesn't exist yet, this package is being preconfiged, and
# we might as well just exit and wait until the postinst
# runs the config script.
if [ ! -e /usr/share/debconf/confmodule ]; then
	exit
fi

. /usr/share/debconf/confmodule

# Establish the preliminaries.
db_version 2.0
db_capb backup

# Remove old question.
db_unregister debconf/preconfig || true

# debconf/helpvisible was renamed, and the value inverted
if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.9.74; then
	# It may not be present, if upgrading from long ago
	db_get debconf/helpvisible || true
	if [ "$RET" = true ]; then
		db_set debconf/terse false
	else
		db_set debconf/terse true
	fi
	db_unregister debconf/helpvisible || true
fi

# Use a state machine to allow jumping back to previous questions.
STATE=1
while [ "$STATE" != 0 -a "$STATE" != 3 ]; do
	case "$STATE" in
	1)
		# Ask about frontend and priority.
		db_beginblock
		db_input medium debconf/frontend || true
		db_input medium debconf/priority || true
		db_endblock
	;;
	
	2)
		# Ask if old questions should be shown only after
		# asking about priority, because I don't want to bother
		# people with it unless they pick low priority.
		db_beginblock
		db_input low debconf/showold || true
		db_endblock
	;;
	esac

	if db_go; then
		STATE=$(($STATE + 1))
	else
		STATE=$(($STATE - 1))
	fi
done
