]> git.donarmstrong.com Git - neurodebian.git/blob - debian/neurodebian-repository.config
ENH: initial debconf .config and few tune ups for that in the nd-aptenable
[neurodebian.git] / debian / neurodebian-repository.config
1 #!/bin/bash
2 set -e
3
4 . /usr/share/debconf/confmodule
5
6 db_capb backup # allow to go back, for that we implement that STATE loop
7
8 debug()
9 {
10     [ "${DEBCONF_DEBUG:-}" != "developer" ] || echo -e "D: $*" >&2
11 }
12
13 db_settitle neurodebian-repository/title
14
15 if [ "$1" = "configure" ]; then
16     # Must have been called in preinst state, so no nd-aptenable
17     # tool is yet installed, thus delay asking questions to
18     # whenever will be called in postinst state
19     which nd-aptenable 1>/dev/null 2>&1 || exit 0
20 fi
21
22 # Create temporary directory which will be reused
23 export ND_AE_TEMPDIR=$(mktemp -d)
24 trap "rm -rf \"$ND_AE_TEMPDIR\"" TERM INT EXIT
25
26 neurodebian_releases="auto"
27
28 # This implements a simple state machine so the back button can be handled.
29 # taken from debconf demo example
30 STATE=1
31 while [ "$STATE" != 0 -a "$STATE" != 8 ]; do
32     case $STATE in
33         1)
34                         export neurodebian_releases="$(ND_IFS=', ' nd-aptenable --print-releases)"
35                         debug "releases: $neurodebian_releases"
36                         db_subst neurodebian-repository/release releases "$neurodebian_releases"
37                         db_input medium neurodebian-repository/release || true
38                         ;;
39         2)
40                         export neurodebian_mirrors="$(ND_IFS=', ' nd-aptenable --print-mirrors)"
41                         debug "mirrors: $neurodebian_mirrors"
42                         db_subst neurodebian-repository/mirror mirrors "$neurodebian_mirrors"
43                         db_input medium neurodebian-repository/mirror || true
44                         mirror_selection_ret="$RET"
45                         debug "mirror select return: <$mirror_selection_ret>"
46                         ;;
47         3)  db_input medium neurodebian-repository/flavor || true ;;
48         4)  db_input medium neurodebian-repository/components || true ;;
49         5)  db_input low neurodebian-repository/overwrite || true ;;
50         6)  db_input low neurodebian-repository/suffix || true ;;
51         7)  db_input low neurodebian-repository/apt-update || true ;;
52     esac
53
54     if db_go; then
55                 case $STATE in
56                         2)
57                                 db_metaget neurodebian-repository/mirror value
58                                 selected_mirror="$RET"
59                                 # TODOs:
60                                 # - handle custom
61                                 # - separate out alias from url
62                                 debug "selected mirror: $selected_mirror"
63                                 if [ "$selected_mirror" = "best" ] && ! which netselect &>/dev/null; then
64                                         if [ "$mirror_selection_ret" = "30 question skipped" ]; then
65                                                 # if the question was not even shown, we would
66                                                 # not get a chance to specify mirror, thus
67                                                 # better just fail altogether and demand intervention
68                                                 db_input high neurodebian-repository/netselect-cannot-be-used
69                                                 exit 1
70                                         else
71                                                 db_input high neurodebian-repository/netselect-not-found
72                                                 continue;
73                                         fi
74                                 fi
75                 esac
76         STATE=$(($STATE + 1))
77     else
78         STATE=$(($STATE - 1))
79     fi
80 done
81
82 db_stop
83