Debian Codegraph @

bin/container

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 HOOKS="/etc/${SOFTWARE}/hooks"
27
28 # Parameter
29 PARAMETER="${1}"
30
31 if [ -z "${PARAMETER}" ]
32 then
33 echo "Usage: ${PROGRAM} COMMAND [OPTIONS]" >&2
34 echo "Usage: ${PROGRAM} COMMAND1,COMMAND2,... [COMMON_OPTIONS]" >&2
35 echo
36 echo "See ${PROGRAM}(1) and ${PROJECT}(7) for more information."
37
38 exit 1
39 fi
40
41 # Command
42 COMMANDS="${1}"
43
44 # Options
45 shift 1
46 OPTIONS="${*}"
47
48 for COMMAND in $(echo "${COMMANDS}" | sed -e 's|,| |g')
49 do
50 if [ ! -e "/usr/libexec/${PROGRAM}/${COMMAND}" ]
51 then
52 echo "'${COMMAND}': no such ${PROGRAM} command, see ${PROGRAM}(1)." >&2
53 exit 1
54 fi
55
56 # Pre hooks
57 for FILE in "${HOOKS}/pre-${PROGRAM}".* "${HOOKS}/${NAME}.pre-${PROGRAM}"
58 do
59 if [ -x "${FILE}" ]
60 then
61 "${FILE}"
62 fi
63 done
64
65 # Notification
66 if echo "${OPTIONS}" | grep -qs "\--no-notification"
67 then
68 OPTIONS="$(echo "${OPTIONS}" | sed -e 's|--no-notification||')"
69 else
70 case "${COMMAND}" in
71 build|b|get|g|move|mv|remove|rm|rebuild|rb|restart|rs|start|s|stop|t|update|u)
72 if [ -z "${CONTAINER_USER}" ]
73 then
74 CONTAINER_USER="${SUDO_USER:-${USER}}"
75 fi
76
77 DATE="$(date +%Y-%m-%d\ %H:%M:%S)"
78 HOST="$(hostname -f 2> /dev/null || hostname)"
79
80 # logfile
81 echo "${DATE} ${HOST} ${CONTAINER_USER} ${PROGRAM} ${COMMAND} ${OPTIONS}" >> "/var/log/${SOFTWARE}/${PROGRAM}.log"
82
83 # irc
84 if [ -e /usr/bin/irk ]
85 then
86 for FILE in "/etc/${SOFTWARE}/${PROGRAM}.conf" "/etc/${SOFTWARE}/${PROGRAM}.conf.d"/*.conf
87 do
88 if [ -e "${FILE}" ]
89 then
90 . "${FILE}"
91 fi
92 done
93
94 if [ -n "${IRK_TARGETS}" ]
95 then
96 for TARGET in ${IRK_TARGETS}
97 do
98 irk "${TARGET}" "\x0300${CONTAINER_USER}\x03@\x0312${HOST}:\x03 \x0303${PROGRAM}\x03 \x0307${COMMAND}\x03 ${OPTIONS}"
99 done
100 fi
101 fi
102 ;;
103 esac
104 fi
105
106 # Run
107 "/usr/libexec/${PROGRAM}/${COMMAND}" "${OPTIONS}"
108
109 # Post hooks
110 for FILE in "${HOOKS}/post-${PROGRAM}".* "${HOOKS}/${NAME}.post-${PROGRAM}"
111 do
112 if [ -x "${FILE}" ]
113 then
114 "${FILE}"
115 fi
116 done
117 done