Debian Codegraph @

share/get-scripts/curl

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/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 SCRIPT="${0}"
27 export SCRIPT
28
29 HOOKS="/etc/${SOFTWARE}/hooks"
30 KEYS="/etc/${SOFTWARE}/keys"
31 MACHINES="/var/lib/machinesscip-shell filesystem . . `/var/lib/machines`."
32
33 Parametersscip-shell shell shell-project 0.0.0 Parameters(). ()
34 {
35 GETOPT_LONGOPTIONS="bind:,bind-ro:,script:,name:,architecture:,clean,password:,server:,setup:,system:,"
36 GETOPT_OPTIONS="b:,s:,n:,a:,p:"
37
38 PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${SCRIPT} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
39
40 if [scip-shell system . . `[`. "${?}" != "0" ]
41 then
42 echoscip-shell system . . echo. "'${SCRIPT}': getopt exit" >&2
43 exit 1
44 fi
45
46 eval set -- "${PARAMETERS}"
47
48 while truescip-shell system . . true.
49 do
50 case "${1}" in
51 -b|--bind)
52 # ignore
53 shift 2
54 ;;
55
56 --bind-ro)
57 # ignore
58 shift 2
59 ;;
60
61 --cnt.auto)
62 # ignore
63 shift 2
64 ;;
65
66 --cnt.container-server)
67 # ignore
68 shift 2
69 ;;
70
71 -s|--script)
72 # ignore
73 shift 2
74 ;;
75
76 -n|--name)
77 NAME="${2}"
78 shift 2
79 ;;
80
81 -a|--architecture)
82 ARCHITECTURE="${2}"
83 shift 2
84 ;;
85
86 --clean)
87 CLEAN="true"
88 shift 1
89 ;;
90
91 -p|--password)
92 PASSWORD="${2}"
93 shift 2
94 ;;
95
96 --server)
97 SERVER="${2}"
98 shift 2
99 ;;
100
101 --setup)
102 SETUP="${2}"
103 shift 2
104 ;;
105
106 --system)
107 SYSTEM="${2}"
108 shift 2
109 ;;
110
111 --)
112 shift 1
113 break
114 ;;
115
116 *)
117 echoscip-shell system . . echo. "'${SCRIPT}': getopt error" >&2
118 exit 1
119 ;;
120 esac
121 done
122 }
123
124 Usagescip-shell shell shell-project 0.0.0 Usage(). ()
125 {
126 echoscip-shell system . . echo. "Usage: container get -n|--name NAME -s|--script ${SCRIPT} -- [--clean] [-p|--password PASSWORD] [--server SERVER] [--setup SETUP] [--system SYSTEM]" >&2
127 exit 1
128 }
129
130 Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}"
131
132 if [scip-shell system . . `[`. -z "${NAME}" ]
133 then
134 Usagescip-shell shell shell-project 0.0.0 Usage().
135 fi
136
137 if [scip-shell system . . `[`. -e "${MACHINES}/${NAME}" ]
138 then
139 echoscip-shell system . . echo. "'${NAME}': container already exists" >&2
140 exit 1
141 fi
142
143 if [scip-shell system . . `[`. ! -x /usr/bin/curlscip-shell filesystem . . `/usr/bin/curl`. ]
144 then
145 echoscip-shell system . . echo. "'${NAME}': /usr/bin/curl - no such file." >&2
146 exit 1
147 fi
148
149 if [scip-shell system . . `[`. "$(idscip-shell system . . id. -u)" -ne 0 ]
150 then
151 echoscip-shell system . . echo. "'${NAME}': need root privileges" >&2
152 exit 1
153 fi
154
155 COMPRESSIONS=""
156
157 if [scip-shell system . . `[`. -x /usr/bin/lzipscip-shell filesystem . . `/usr/bin/lzip`. ]
158 then
159 COMPRESSIONS="${COMPRESSIONS} lz"
160 fi
161
162 if [scip-shell system . . `[`. -x /usr/bin/xzscip-shell filesystem . . `/usr/bin/xz`. ]
163 then
164 COMPRESSIONS="${COMPRESSIONS} xz"
165 fi
166
167 if [scip-shell system . . `[`. -x /bin/gzipscip-shell filesystem . . `/bin/gzip`. ]
168 then
169 COMPRESSIONS="${COMPRESSIONS} gz"
170 fi
171
172 if [scip-shell system . . `[`. -z "${COMPRESSIONS}" ]
173 then
174 echoscip-shell system . . echo. "'${NAME}': no supported compressor available (lz, xz, gz)."
175 exit 1
176 fi
177
178 SERVER="${SERVER:-https://get.open-infrastructure.net/system/container/debian}"
179 PASSWORD="${PASSWORD:-$(ddscip-shell system . . dd. if=/dev/urandomscip-shell filesystem . . `/dev/urandom`. bs=12 count=1 2> /dev/nullscip-shell filesystem . . `/dev/null`. | base64scip-shell system . . base64.)}"
180 CACHE="/var/cache/${PROGRAM}/get-$(basenamescip-shell system . . basename. ${SCRIPT})/$(echoscip-shell system . . echo. ${SERVER} | sedscip-shell system . . sed. -e 's|.*//||' -e 's|/|_|g')"
181
182 VERSION="$(container version)"
183
184 Debconfscip-shell shell shell-project 0.0.0 Debconf(). ()
185 {
186 # Configure local debconf
187 mkdirscip-shell system . . mkdir. -p "${DEBCONF_TMPDIR}/debconf"
188
189 catscip-shell system . . cat. > "${DEBCONF_TMPDIR}/debconf.systemrc" << EOF
190 Config: configdb
191 Templates: templatedb
192
193 Name: config
194 Driver: File
195 Mode: 644
196 Reject-Type: password
197 Filename: ${DEBCONF_TMPDIR}/debconf/config.dat
198
199 Name: passwords
200 Driver: File
201 Mode: 600
202 Backup: false
203 Required: false
204 Accept-Type: password
205 Filename: ${DEBCONF_TMPDIR}/debconf/passwords.dat
206
207 Name: configdb
208 Driver: Stack
209 Stack: config, passwords
210
211 Name: templatedb
212 Driver: File
213 Mode: 644
214 Filename: ${DEBCONF_TMPDIR}/debconf/templates.dat
215 EOF
216
217 DEBCONF_SYSTEMRC="${DEBCONF_TMPDIR}/debconf.systemrc"
218 export DEBCONF_SYSTEMRC
219 }
220
221 # Pre hooks
222 for FILE in "${HOOKS}/pre-${SCRIPT}".* "${HOOKS}/${NAME}.pre-${SCRIPT}"
223 do
224 if [scip-shell system . . `[`. -x "${FILE}" ]
225 then
226 "${FILE}"
227 fi
228 done
229
230 # Run
231
232 # FIXME: default server via configuration file
233
234 if [scip-shell system . . `[`. -z "${SYSTEM}" ]
235 then
236 # Downloading container list
237 if curlscip-shell system . . curl. --fail --head --output /dev/nullscip-shell filesystem . . `/dev/null`. --silent "${SERVER}/container-list.txt"
238 then
239 mkdirscip-shell system . . mkdir. -p "/tmp/${SOFTWARE}"
240 DEBCONF_TMPDIR="$(mktempscip-shell system . . mktemp. -d -p "/tmp/${SOFTWARE}" -t $(basenamescip-shell system . . basename. ${0}).XXXX)"
241 export DEBCONF_TMPDIR
242
243 if [scip-shell system . . `[`. -z "${ARCHITECTURE}" ]
244 then
245 case "$(dpkgscip-shell system . . dpkg. --print-architecture)" in
246 amd64)
247 GREP_PATTERN="(amd64|i386)"
248 ;;
249 esac
250 fi
251
252 GREP_PATTERN="${GREP_PATTERN:-${ARCHITECTURE}}"
253
254 echoscip-shell system . . echo. "Downloading $(echoscip-shell system . . echo. ${SERVER} | awkscip-shell system . . awk. -F/ '{ print $3 }') container list"
255 cuscip-shell system . . curl.rlscip-shell system . . curl. --fail --location --progress-bar --user-agent ${SOFTWARE}/${VERSION} --http2 \
256 "${SERVER}/container-list.txt" | grepscip-shell system . . grep. -E "${GREP_PATTERN}" > "${DEBCONF_TMPDIR}/container-list.txt"
257
258 umask 0022
259
260 Debconfscip-shell shell shell-project 0.0.0 Debconf().
261
262 # Run debconf parts
263 for DEBCONF_SCRIPT in /usr/share/${SOFTWARE}/get-scripts/curl.d/*
264 do
265 if [scip-shell system . . `[`. -x "${DEBCONF_SCRIPT}" ]
266 then
267 "${DEBCONF_SCRIPT}"
268 fi
269 done
270
271 # Read-in configuration from debconf
272 . "${DEBCONF_TMPDIR}/debconf.default"
273
274 # Remove debconf temporary files
275 rmscip-shell system . . rm. --preserve-root --one-file-system -rf "${DEBCONF_TMPDIR}"
276 rmdirscip-shell system . . rmdir. --ignore-fail-on-non-empty "/tmp/${SOFTWARE}" 2>&1 || truescip-shell system . . true.
277 fi
278 fi
279
280 for COMPRESSION in ${COMPRESSIONS}
281 do
282 if curlscip-shell system . . curl. --fail --head --output /dev/nullscip-shell filesystem . . `/dev/null`. --silent "${SERVER}/${SYSTEM}.${COMPRESSION}"
283 then
284 SYSTEM="${SYSTEM}.${COMPRESSION}"
285 break
286 fi
287 done
288
289 # Downloading container files
290 mkdirscip-shell system . . mkdir. -p "${CACHE}"
291
292 SETUP="${SETUP:-$(echoscip-shell system . . echo. ${SYSTEM} | sedscip-shell system . . sed. -e 's|.system.tar.|.setup.tar.|')}"
293
294 for FILE in "${SYSTEM}" "${SYSTEM}.sig" "${SYSTEM}.sha512" \
295 "${SETUP}" "${SETUP}.sig" "${SETUP}.sha512"
296 do
297 if curlscip-shell system . . curl. --fail --head --output /dev/nullscip-shell filesystem . . `/dev/null`. --silent "${SERVER}/${FILE}"
298 then
299 case "${FILE}" in
300 *.sha512)
301 if [scip-shell system . . `[`. -e "${CACHE}/$(basenamescip-shell system . . basename. ${FILE} .sha512).sig" ]
302 then
303 continue
304 fi
305 ;;
306 esac
307
308 if [scip-shell system . . `[`. -e "${CACHE}/${FILE}" ]
309 then
310 CURL_TIME_COND="--time-cond ${CACHE}/${FILE}"
311 else
312 CURL_TIME_COND=""
313 fi
314
315 echoscip-shell system . . echo. "Downloading ${FILE}"
316 cuscip-shell system . . curl.rlscip-shell system . . curl. --fail --location --progress-bar --user-agent ${SOFTWARE}/${VERSION} --http2 ${CURL_TIME_COND} \
317 "${SERVER}/${FILE}" -o "${CACHE}/${FILE}"
318 fi
319 done
320
321 cd "${CACHE}"
322
323 for FILE in "${SYSTEM}" "${SETUP}"
324 do
325 if [scip-shell system . . `[`. ! -e "${FILE}" ]
326 then
327 continue
328 fi
329
330 if [scip-shell system . . `[`. -e "${FILE}.sig" ]
331 then
332 echoscip-shell system . . echo. -n "Verifying ${FILE}:"
333
334 set +e
335 gpgscip-shell system . . gpg. --homedir "${KEYS}" --verify "${FILE}.sig" "${FILE}" > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
336 GNUPG="${?}"
337 set -e
338
339 case "${GNUPG}" in
340 0)
341 echoscip-shell system . . echo. " gpg ok."
342 continue
343 ;;
344
345 *)
346 echoscip-shell system . . echo. " gpg failed."
347 exit 1
348 ;;
349 esac
350 elif [scip-shell system . . `[`. -e "${FILE}.sha512" ]
351 then
352 echoscip-shell system . . echo. -n "Verifying ${FILE}:"
353
354 set +e
355 sha512sumscip-shell system . . sha512sum. --check "${FILE}.sha512" --status
356 SHA512SUM="${?}"
357 set -e
358
359 case "${SHA512SUM}" in
360 0)
361 echoscip-shell system . . echo. " sha512 ok."
362 ;;
363
364 *)
365 echoscip-shell system . . echo. " sha512 failed."
366 exit 1
367 ;;
368 esac
369 fi
370 done
371
372 cd "${OLDPWD}"
373
374 case "${SYSTEM}" in
375 *.gz)
376 TAR_OPTIONS="--gzip"
377
378 if [scip-shell system . . `[`. ! -e /bin/gzipscip-shell filesystem . . `/bin/gzip`. ]
379 then
380 echoscip-shell system . . echo. -en "\n"
381 echoscip-shell system . . echo. "'${NAME}': /bin/lzip - no such file." >&2
382 exit 1
383 fi
384 ;;
385
386 *.lz)
387 TAR_OPTIONS="--lzip"
388
389 if [scip-shell system . . `[`. ! -e /usr/bin/lzipscip-shell filesystem . . `/usr/bin/lzip`. ]
390 then
391 echoscip-shell system . . echo. -en "\n"
392 echoscip-shell system . . echo. "'${NAME}': /usr/bin/lzip - no such file." >&2
393 exit 1
394 fi
395 ;;
396
397 *.xz)
398 TAR_OPTIONS="--xz"
399
400 if [scip-shell system . . `[`. ! -e /usr/bin/xzscip-shell filesystem . . `/usr/bin/xz`. ]
401 then
402 echoscip-shell system . . echo. -en "\n"
403 echoscip-shell system . . echo. "'${NAME}': /usr/bin/xz - no such file." >&2
404 exit 1
405 fi
406 ;;
407
408 *)
409 TAR_OPTIONS=""
410 ;;
411 esac
412
413 for FILE in "${SYSTEM}" "${SETUP}"
414 do
415 if [scip-shell system . . `[`. ! -e "${CACHE}/${FILE}" ]
416 then
417 continue
418 fi
419
420 case "${FILE}" in
421 *.system.tar.*)
422 DIRECTORY="${MACHINES}/${NAME}"
423 ;;
424
425 *.setup.tar.*)
426 DIRECTORY="${MACHINES}/${NAME}/setup"
427 ;;
428 esac
429
430 mkdirscip-shell system . . mkdir. -p "${DIRECTORY}"
431
432 if [scip-shell system . . `[`. -e /usr/bin/pvscip-shell filesystem . . `/usr/bin/pv`. ]
433 then
434 echoscip-shell system . . echo. "Unpacking ${FILE}"
435 pv --format '%p' --width 77 "${CACHE}/${FILE}" | tarscip-shell system . . tar. xf - ${TAR_OPTIONS} -C "${DIRECTORY}" --strip 1
436 else
437 echoscip-shell system . . echo. -n "Unpacking ${FILE}:"
438 tarscip-shell system . . tar. xf "${CACHE}/${FILE}" ${TAR_OPTIONS} -C "${DIRECTORY}" --strip 1
439 echoscip-shell system . . echo. " ok."
440 fi
441 done
442
443 if [scip-shell system . . `[`. -x "${MACHINES}/${NAME}/setup/container" ]
444 then
445 chrooscip-shell system . . chroot.tscip-shell system . . chroot. "${MACHINES}/${NAME}" /usr/bin/envscip-shell filesystem . . `/usr/bin/env`. -i \
446 LC_ALL="C" PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/gamesscip-shell filesystem . . `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games`." TERM="${TERM}" \
447 DEBIAN_FRONTEND="dialog" DEBIAN_PRIORITY="low" \
448 DEBCONF_NONINTERACTIVE_SEEN="true" DEBCONF_NOWARNINGS="true" \
449 NAME="${NAME}"scip-shell filesystem . . `/setup/container`. \
450 /setup/container
451
452 rmscip-shell system . . rm. -rf "${MACHINES}/${NAME}/setup"
453 fi
454
455 # Creating machine-id
456 chrootscip-shell system . . chroot. "${MACHINES}/${NAME}" systemd-machine-id-setup > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
457
458 # Setting hostname
459 echoscip-shell system . . echo. "${NAME}" > "${MACHINES}/${NAME}/etc/hostname"
460
461 # Copying resolv.conf
462 cpscip-shell system . . cp. -L /etc/resolv.confscip-shell filesystem . . `/etc/resolv.conf`. "${MACHINES}/${NAME}/etc/resolv.conf"
463
464 # Setting root password
465 echoscip-shell system . . echo. root:${PASSWORD} | chrootscip-shell system . . chroot. "${MACHINES}/${NAME}" chpasswd
466 echoscip-shell system . . echo. "${NAME}: root password set to '${PASSWORD}'."
467
468 # Remove cache
469 case "${CLEAN}" in
470 true)
471 rmscip-shell system . . rm. -f "${CACHE}/${SYSTEM}" "${CACHE}/${SYSTEM}.sha512"
472 rmscip-shell system . . rm. -f "${CACHE}/${SETUP}" "${CACHE}/${SETUP}.sha512"
473 ;;
474 esac
475
476 # Post hooks
477 for FILE in "${HOOKS}/post-${SCRIPT}".* "${HOOKS}/${NAME}.post-${SCRIPT}"
478 do
479 if [scip-shell system . . `[`. -x "${FILE}" ]
480 then
481 "${FILE}"
482 fi
483 done