#!/bin/sh -e

. /usr/share/debconf/confmodule
db_version 2.0

# BUG: If you upgrade atftp and you previously configured it with debconf,
#      that is, the atftpd/configure value in the database is set to true,
#      then the config script will overwrite the config in inetd.conf with
#      all values from the database. This could be avoided (or so I thought)
#      by setting the atftpd/configure value to false in the event db_input
#      had returned false but this causes the config value to be ignored if
#      the package is being preconfigured. In such a case, the config script
#      is called twice, the first time it shows the question and returns
#      true but the second it doesn't show the question and would return
#      false, which results in the atftpd/configure value being set to false
#      and makes the config value being ignore despite the fact the user
#      answered them (#93398). I didn't find any better way to work around
#      this. Sorry.

db_beginblock
db_input high atftpd/configure || true
db_endblock
db_go

db_get atftpd/configure
if [ "$RET" = "true" ]; then

    db_beginblock
    db_input medium atftpd/use_inetd || true
    db_endblock
    db_go

    db_get atftpd/use_inetd

    if [ "$RET" = "true" ]; then
	db_beginblock
	db_input medium atftpd/tftpd-timeout || true
	db_endblock
	db_go
    fi

    db_beginblock
    db_input medium atftpd/port || true
    db_input medium atftpd/retry-timeout || true
    db_input medium atftpd/maxthread || true
    db_input medium atftpd/timeout || true
    db_input medium atftpd/tsize || true
    db_input medium atftpd/blksize || true
    db_input medium atftpd/multicast || true
    db_endblock
    db_go

    db_get atftpd/multicast
    if [ "$RET" = "true" ]; then
	db_beginblock
	db_input medium atftpd/mcast_port || true
	db_input medium atftpd/mcast_addr || true
	db_endblock
	db_go
    fi

    db_beginblock
    db_input medium atftpd/verbosity || true
    db_input medium atftpd/basedir || true
    db_input medium atftpd/logtofile || true
    db_endblock
    db_go
    
    db_get  atftpd/logtofile
    if [ "$RET" = "true" ]; then
	db_beginblock
	db_input medium atftpd/logfile || true
	db_endblock
	db_go
    fi
fi
