#!/bin/sh -e
# Debconf interface, see debconf-devel(7) for details.
# Written by Joachim Nilsson <joachim!nilsson()member!fsf!org>

# Source debconf library.
. /usr/share/debconf/confmodule

# configure or reconfigure
MODE=$1
# currently installed version
OLD_VERSION=$2

# Setup default values
db_get alive/login_server
LOGIN_SERVER=$RET
db_get alive/username
USERNAME=$RET
db_get alive/password
PASSWORD=$RET

# Set title
db_title "GNU Alive Configuration"

# Pop the question...
db_input medium alive/use_debconf || true
db_go || true
db_get alive/use_debconf
if [ "$RET" = "true" ]; then
    # Make sure we only get this question once!
    db_fget alive/reuse_qadsl_conf_values seen
    if [ -f /etc/qadsl.conf -a "$RET" != "true" ]; then
        db_input medium alive/reuse_qadsl_conf_values || true
        db_go || true
        db_get alive/reuse_qadsl_conf_values
        if [ "$RET" = "true" ]; then
            # Get current settings
            . /etc/qadsl.conf

            if [ "$USER" != "" ]; then
                USERNAME=$USER
            fi
            if [ "$PASS" != "" ]; then
                PASSWORD=$PASS
            fi
            if [ "$SERV" != "" ]; then
                LOGIN_SERVER=$SERV
            else
                if [ "$SERVER" != "" ]; then
                    LOGIN_SERVER=$SERVER
                fi
            fi
        fi
    fi

    db_set alive/login_server $LOGIN_SERVER
    db_set alive/username $USERNAME
    db_set alive/password $PASSWORD

    db_beginblock
    db_input medium alive/login_server || true
    db_input medium alive/username || true
    db_input medium alive/password || true
    db_endblock

    db_go || true
fi
