#!/bin/sh
set -e
. /usr/share/debconf/confmodule

# Every question has a default, so a non-interactive install with nothing
# preseeded completes without prompting. The defaults are platform "none" and
# mode "manual", which together mean: install the files, configure nothing.

db_input high vpn-router/platform || true
db_go || true

db_get vpn-router/platform
if [ "$RET" = "none" ]; then
    # Configuration is deferred. Asking anything else would collect answers
    # that nothing is going to apply.
    exit 0
fi

db_input high vpn-router/mode || true
db_go || true

# The mode says how much the operator supplies, so it decides which interface
# and address questions are worth asking.
db_get vpn-router/mode
case "$RET" in
    manual)
        db_input high vpn-router/external_interface || true
        db_input high vpn-router/internal_interface || true
        db_input high vpn-router/int_addr || true
        db_input high vpn-router/int_gateway_ip || true
        ;;
    interfaces)
        db_input high vpn-router/external_interface || true
        db_input high vpn-router/internal_interface || true
        ;;
    auto)
        ;;
esac
db_go || true

db_input high vpn-router/local_fqdn || true
db_input high vpn-router/local_id_mode || true
db_input high vpn-router/local_cidrs || true
db_input high vpn-router/remote_addrs || true
db_input high vpn-router/remote_id || true
db_input high vpn-router/remote_cidrs || true
db_input high vpn-router/psk || true
db_input high vpn-router/p2s_enabled || true
db_input high vpn-router/wg_enabled || true
db_go || true

db_get vpn-router/p2s_enabled
if [ "$RET" = "true" ]; then
    db_input high vpn-router/p2s_address_pool || true
    db_input high vpn-router/p2s_ca_name || true
    db_go || true
fi

db_get vpn-router/wg_enabled
if [ "$RET" = "true" ]; then
    db_input high vpn-router/wg_address || true
    db_input high vpn-router/wg_listen_port || true
    db_go || true
fi
