#!/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 questions.
db_unregister debconf/preconfig || true
db_unregister debconf/helpvisible || true

# 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
