#!/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'

# Use a state machine to allow jumping back to previous questions.
STATE=1
while [ "$STATE" != stop ]; 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
		if ! db_go; then
			# Going back at this point is up to the frontend,
			# since it involves jumping out of this configmodule.
			# This is just a placeholder for something not in the
			# spec.
			exit
		else
			STATE=2
		fi
	;;
	
	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/preconfig || true
		db_input low debconf/showold || true
		db_endblock
		if ! db_go; then
		echo backup hit
			# Back button
			STATE=1
			db_fset debconf/frontend isdefault true
			db_fset debconf/priority isdefault true
			db_fset debconf/showold isdefault true 
		else
			# Done.
			STATE=stop
		fi
	;;
	esac
done
