summaryrefslogtreecommitdiffstats
path: root/debian/kea-ctrl-agent.config
blob: 00e4013ff8136cade4da4922f067b9f1aee3540d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh

set -e

. /usr/share/debconf/confmodule

ask_for_password() {
    while :; do
        RET=""
        db_input high kea-ctrl-agent/kea_api_password || true
        db_go || true
        db_get kea-ctrl-agent/kea_api_password
        if [ -z "$RET" ]; then
            # empty passwords result in no action
            break
        fi
        API_PASSWORD="$RET"
        db_input high kea-ctrl-agent/kea_api_password_again || true
        db_go || true
        db_get kea-ctrl-agent/kea_api_password_again
        if [ "$RET" = "$API_PASSWORD" ]; then
            API_PASSWORD=""
            break
        fi
        db_fset kea-ctrl-agent/password_mismatch seen false
        db_input critical kea-ctrl-agent/password_mismatch || true
        db_set kea-ctrl-agent/kea_api_password ""
        db_set kea-ctrl-agent/kea_api_password_again ""
        db_go || true
    done
}

gen_random_pw() {
    head -c 15 /dev/urandom | base64 | tr -d '[:space:]'
}


RET=""
choice=""
reconfigure=""

if [ "${1}" = "configure" ] || [ "${1}" = "reconfigure" ]; then
    if [ "${1}" = "reconfigure" ] || [ -n "${DEBCONF_RECONFIGURE}" ]; then
        reconfigure="yes"
    fi
    # only ask questions on:
    # - reconfigure
    # - fresh install
    # - upgrade from pre-debconf package (lt: empty version is "earlier", so
    #   this covers the fresh install case too)
    if [ -n "${reconfigure}" ] || dpkg --compare-versions "$2" lt "2.2.0-5ubuntu2~"; then
        db_input high kea-ctrl-agent/make_a_choice || true
        db_go || true

        db_get kea-ctrl-agent/make_a_choice
        choice="${RET}"

        case "${choice}" in
            unconfigured)
                # nothing to do
            ;;
            configured_password)
                ask_for_password
            ;;
            configured_random_password)
                db_set kea-ctrl-agent/kea_api_password "$(gen_random_pw)"
            ;;
            *)
                # shouldn't happen, so it's the same as "unconfigured" above
            ;;
        esac
    fi
fi