Debian Codegraph @

libexec/container/rebuild

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 COMMAND="$(basenamescip-shell system . . basename. ${0})"
26
27 HOOKS="/etc/${SOFTWARE}/hooks"
28 MACHINES="/var/lib/machinesscip-shell filesystem . . `/var/lib/machines`."
29
30 Parametersscip-shell shell shell-project 0.0.0 Parameters(). ()
31 {
32 OPTIONS_ALL=""
33
34 GETOPT_LONGOPTIONS="name:,force,verbose,"
35 GETOPT_OPTIONS="n:,f,v,"
36
37 PARAMETERS="$(getoptscip-shell system . . getopt. --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})"
38
39 if [scip-shell system . . `[`. "${?}" != "0" ]
40 then
41 echoscip-shell system . . echo. "'${COMMAND}': getopt exit" >&2
42 exit 1
43 fi
44
45 eval set -- "${PARAMETERS}"
46
47 while truescip-shell system . . true.
48 do
49 case "${1}" in
50 -n|--name)
51 NAME="${2}"
52 shift 2
53 ;;
54
55 -f|--force)
56 FORCE="true"
57 shift 1
58
59 OPTIONS_ALL="${OPTIONS_ALL} --force"
60 ;;
61
62 -v|--verbose)
63 VERBOSE="true"
64 shift 1
65
66 OPTIONS_ALL="${OPTIONS_ALL} --verbose"
67 ;;
68
69 --)
70 shift 1
71 break
72 ;;
73
74 *)
75 echoscip-shell system . . echo. "'${COMMAND}': getopt error" >&2
76 exit 1
77 ;;
78 esac
79 done
80 }
81
82 Usagescip-shell shell shell-project 0.0.0 Usage(). ()
83 {
84 echoscip-shell system . . echo. "Usage: ${PROGRAM} ${COMMAND} -n|--name NAME [-f|--force] [-v|--verbose]" >&2
85 echoscip-shell system . . echo.
86 echoscip-shell system . . echo. "See ${COMMAND}(1), ${PROGRAM}(1) and ${PROJECT}(7) for more information."
87
88 exit 1
89 }
90
91 Parametersscip-shell shell shell-project 0.0.0 Parameters(). "${@}"
92
93 if [scip-shell system . . `[`. -z "${NAME}" ]
94 then
95 Usagescip-shell shell shell-project 0.0.0 Usage().
96 fi
97
98 case "${NAME}" in
99 ALL)
100 NAMES="$(${PROGRAM} list --format shell --started)"
101
102 for NAME in ${NAMES}
103 do
104 ${PROGRAM} rebuild,start --name ${NAME} ${OPTIONS_ALL} || truescip-shell system . . true.
105 done
106
107 exit 0
108 ;;
109 esac
110
111 if [scip-shell system . . `[`. ! -e "${MACHINES}/${NAME}" ]
112 then
113 echoscip-shell system . . echo. "'${NAME}': no such container" >&2
114 exit 1
115 fi
116
117 # Pre hooks
118 for FILE in "${HOOKS}/pre-${COMMAND}".* "${HOOKS}/${NAME}.pre-${COMMAND}"
119 do
120 if [scip-shell system . . `[`. -x "${FILE}" ]
121 then
122 "${FILE}"
123 fi
124 done
125
126 # Run
127 case "${VERBOSE}" in
128 true)
129 echoscip-shell system . . echo. -n "Rebuilding container ${NAME}..."
130 ;;
131 esac
132
133 ${PROGRAM} stop ${OPTIONS_ALL} --name ${NAME} || truescip-shell system . . true.
134 sleepscip-shell system . . sleep. 0.5
135 ${PROGRAM} remove ${OPTIONS_ALL} --name ${NAME} || truescip-shell system . . true.
136 sleepscip-shell system . . sleep. 0.5
137 ${PROGRAM} build --name ${NAME} || truescip-shell system . . true.
138
139 case "${VERBOSE}" in
140 true)
141 echoscip-shell system . . echo. " done."
142 ;;
143 esac
144
145 # Post hooks
146 for FILE in "${HOOKS}/post-${COMMAND}".* "${HOOKS}/${NAME}.post-${COMMAND}"
147 do
148 if [scip-shell system . . `[`. -x "${FILE}" ]
149 then
150 "${FILE}"
151 fi
152 done