#!/bin/sh -e

# Use debconf.
. /usr/share/debconf/confmodule

# Establish the preliminaries.
db_version
db_title 'Lynx Configuration'

# Make sure there isn't a value already set in the config file.
already_done=''
if [ -e /etc/lynx.cfg ]; then
	if [ -z "`fgrep -n \"STARTFILE:Not-Configured-Yet\" /etc/lynx.cfg | awk -F: '{print $1;}'`" ]; then
		already_done=1
	fi
fi

if [ -z "$already_done" ]; then
	# If this is the first time we've asked this question,
	# come up with a reasonable default if we can. If not,
	# we fall back to the default that's already set in the
	# template.
	db_fget lynx/defaulturl isdefault
	if [ "$RET" = true -a ! -z "`dnsdomainname`" ]; then
		db_set lynx/defaulturl "http://`dnsdomainname`/"
	fi
	
	ok=''
	while [ -z "$ok" ]; do
	
		# Ask the user what url should be displayed by default.
		db_input medium lynx/defaulturl || true
		db_go || true
	
		# Do some syntax checking on the url and see if it's ok.
		db_get lynx/defaulturl
		
		case "$RET" in
		http:*|ftp:*|news:*|nntp:*|gopher:*|file:*|/*)
			ok=1
			;;
		*)
			# Set default flag so the user is prompted again.
			db_fset lynx/defaulturl isdefault true
			;;
		esac
	done
fi
