]> git.donarmstrong.com Git - neurodebian.git/blob - debian/neurodebian.config
2d8968885d9595a32434765cddd66547d9c11649
[neurodebian.git] / debian / neurodebian.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/title
14
15 if [ "$1" = "configure" ]; then
16     # Must have been called in preinst state, so no nd-configurerepo
17     # tool is yet installed, thus delay asking questions to
18     # whenever will be called in postinst state
19     which nd-configurerepo 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" -lt 9 ]; do
32     case $STATE in
33                 1)
34                         # allow to be overriden by environment variable as discussed with
35                         # ftpmaster
36                         if [ ! -z "${NEURODEBIAN_ENABLE:-}" ]; then
37                                 case "${NEURODEBIAN_ENABLE}" in
38                                         true|yes|YES|1) enable=true;;
39                                         false|no|NO|0)  enable=false;;
40                                         *) echo "Non-supported value $NEURODEBIAN_ENABLE of NEURODEBIAN_ENABLE env variable. Use yes or no" >&2;
41                                                 exit 1;;
42                                 esac
43                                 db_set neurodebian/enable $enable
44                         fi
45                         db_input medium neurodebian/enable || true
46                         ;;
47         2)
48                         neurodebian_releases="$(ND_IFS=', ' nd-configurerepo --print-releases)"
49                         debian_release="$(ND_IFS=', ' nd-configurerepo --print-release)"
50                         if [ -z "$debian_release" ]; then # just a failover
51                                 debian_release="sid"
52                         fi
53                         debug "releases: $neurodebian_releases"
54                         db_subst neurodebian/release releases "$neurodebian_releases"
55                         db_subst neurodebian/release release  "$debian_release"
56                         db_input medium neurodebian/release || true
57                         ;;
58         3)
59                         neurodebian_mirrors="$(ND_IFS=', ' nd-configurerepo --print-mirrors)"
60                         debug "mirrors: $neurodebian_mirrors"
61                         db_subst neurodebian/mirror mirrors "$neurodebian_mirrors"
62                         db_input medium neurodebian/mirror || true
63                         mirror_selection_ret="$RET"
64                         debug "mirror select return: <$mirror_selection_ret>"
65                         ;;
66         4)  neurodebian_flavor="$(ND_IFS=', ' nd-configurerepo --print-flavor)"
67                         db_subst neurodebian/flavor flavor "$neurodebian_flavor"
68                         db_input medium neurodebian/flavor || true ;;
69         5)  db_input medium neurodebian/components || true ;;
70         6)  db_input low neurodebian/suffix || true ;;
71         7)  db_input low neurodebian/overwrite || true ;;
72         8)  db_input medium neurodebian/run-update-note || true ;;
73     esac
74
75     if db_go; then
76                 case $STATE in
77                         1)
78                                 db_get neurodebian/enable # get new value
79                                 if [ "$RET" = "false" ]; then
80                                         # no need to proceed with further questions
81                                         if /bin/ls /etc/apt/sources.list.d/neurodebian.sources*.list &>/dev/null; then
82                                                 # we have configuration present -- display a note about apt-get update
83                                                 STATE=8
84                                         else
85                                                 STATE=100       # just go out -- nothing to do, nothing to inform about
86                                         fi
87                                         continue
88                                 fi;;
89 # Ubuntus managed to remove netselect "to accompany apt-netselect"
90 # https://bugs.launchpad.net/ubuntu/+source/netselect/+bug/337377
91 # So for now remove this mandatory demanding of netselect for "best", and
92 # rely on logic in nd-configurerepo to select default mirror (currently origin)
93 # as the 'best'
94 #
95 #                       3)
96 #                               db_metaget neurodebian/mirror value
97 #                               selected_mirror="$RET"
98 #                               # TODOs:
99 #                               # - handle custom
100 #                               # - separate out alias from url
101 #                               debug "selected mirror: $selected_mirror"
102 #                               if [ "$selected_mirror" = "best" ] && ! which netselect &>/dev/null; then
103 #                                       if [ "$mirror_selection_ret" = "30 question skipped" ]; then
104 #                                               # if the question was not even shown, we would
105 #                                               # not get a chance to specify mirror, thus
106 #                                               # better just fail altogether and demand intervention
107 #                                               db_input high neurodebian/netselect-cannot-be-used
108 #                                               exit 1
109 #                                       else
110 #                                               db_input high neurodebian/netselect-not-found
111 #                                               continue;
112 #                                       fi
113 #                               fi
114                 esac
115         STATE=$(($STATE + 1))
116     else
117         STATE=$(($STATE - 1))
118     fi
119 done
120
121 db_stop
122