Debian Codegraph @

share/build-scripts/debconf.d/0001-preseed-file

raw symbols SCIP
1 #!/bin/sh
2
3 # Copyright (C) 2014-2026 Daniel Baumann <[email protected]>
4 #
5 # SPDX-License-Identifier: GPL-3.0+
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20 set -e
21
22 PROJECT="open-infrastructure"
23 SOFTWARE="compute-tools"
24 PROGRAM="container"
25
26 CONFIG="/etc/${SOFTWARE}/config"
27 DEBCONF="/etc/${SOFTWARE}/debconf"
28
29 DEBCONF_NOWARNINGS="true"
30 export DEBCONF_NOWARNINGS
31
32 . /usr/share/debconf/confmodule
33
34 # debconf template hierarchy (first match wins):
35 #
36 # 1. user specified a preseed file through commandline options
37 # 2. /etc/compute-tools/debconf/${NAME}.cfg exists
38 # 3. /etc/compute-tools/debconf/links/${NAME}.cfg exists
39 # 4. /etc/compute-tools/debconf/*/${NAME}.cfg exists (only one file!)
40 # 5. /etc/compute-tools/debconf/default.cfg exists
41 # 6. user chooses from list of available (if any) *.cfg files
42 # (recursively) found in /etc/compute-tools/debconf,
43 # /etc/compute-tools/debconf/links is excluded.
44
45 if [ -n "${PRESEED_FILE}" ]
46 then
47 # user specified one or more preseed files through commandline option
48 db_set container/preseed-file "${PRESEED_FILE}"
49 db_fset container/preseed-file seen true
50 elif [ -e "${DEBCONF}/${NAME}.cfg" ]
51 then
52 # user did not specify a pressed file, but there is a matching one
53 # available on the system matching the container name
54 db_set container/preseed-file "${DEBCONF}/${NAME}.cfg"
55 db_fset container/preseed-file seen true
56 elif [ -e "${DEBCONF}/links/${NAME}.cfg" ]
57 then
58 # user did not specify a pressed file, but there is a matching one
59 # in /etc/${SOFTWARE}/debconf/links directory
60 db_set container/preseed-file "${DEBCONF}/links/${NAME}.cfg"
61 db_fset container/preseed-file seen true
62 elif [ "$(ls ${DEBCONF}/*/${NAME}.cfg 2>/dev/null | wc -l)" -eq 1 ]
63 then
64 # user did not specify a pressed file, but there is 1 (and only 1)
65 # matching in a sub-directory of /etc/${SOFTWARE}/debconf
66
67 FILE="$(ls ${DEBCONF}/*/${NAME}.cfg)"
68
69 db_set container/preseed-file "${FILE}"
70 db_fset container/preseed-file seen true
71 elif [ -e "${DEBCONF}/default.cfg" ]
72 then
73 # user did not specify a pressed file, but there is a default one
74 db_set container/preseed-file "${DEBCONF}/default.cfg"
75 db_fset container/preseed-file seen true
76 elif ls "${DEBCONF}"/*.cfg > /dev/null 2>&1 || ls "${DEBCONF}"/*/*.cfg > /dev/null 2>&1
77 then
78 # user has not specified preseed files through commandline option,
79 # showing debconf selection dialog for global preseed file.
80
81 FILES="$(cd ${DEBCONF} && find . -type f -name '*.cfg' -printf '%P\n' | grep -v '^links\/' | LC_ALL=C sort -V)"
82 PRESEED_FILES="$(for FILE in ${FILES}; do echo -n "$(echo ${FILE} | sed -e 's|.cfg$||'), "; done | sed -e 's|, $||')"
83
84 if [ -n "${PRESEED_FILES}" ]
85 then
86 db_subst container/preseed-files CHOICES "custom, exit, none, , ${PRESEED_FILES}"
87
88 db_settitle container/title
89 db_input high container/preseed-files || true
90 db_go
91
92 db_get container/preseed-files
93 PRESEED_FILE="${RET}" # select
94
95 case "${PRESEED_FILE}" in
96 custom|none)
97 ;;
98
99 exit)
100 rm -f "${CONFIG}/${NAME}.conf"
101 exit 1
102 ;;
103
104 *)
105 # user specified preseed file through debconf select
106 db_set container/preseed-file "${DEBCONF}/${PRESEED_FILE}.cfg"
107 db_fset container/preseed-file seen true
108 ;;
109 esac
110 fi
111 fi
112
113 case "${PRESEED_FILE}" in
114 none)
115 ;;
116
117 *)
118 # ask user for a preseed file
119 db_settitle container/title
120 db_input high container/preseed-file || true
121 db_go
122
123 db_get container/preseed-file
124 PRESEED_FILE="${RET}" # string (w/ empty)
125
126 echo "PRESEED_FILE=\"${PRESEED_FILE}\"" >> "${DEBCONF_TMPDIR}/debconf.default"
127 export PRESEED_FILE
128 ;;
129 esac
130
131 db_stop