-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-nspawn-images
executable file
·52 lines (46 loc) · 1.04 KB
/
update-nspawn-images
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
function help() {
echo "usage: $0 CONTAINER_NAME CONTAINER_NAME ..."
exit 1
}
function stop_container_if_running() {
CONTAINER=$1
machinectl status "$CONTAINER" 1> /dev/null 2> /dev/null
CONTAINER_RUNNING=$?
if [ $CONTAINER_RUNNING -eq 0 ]; then
while true; do
machinectl stop "$CONTAINER"
CONTAINER_STOPPED=$?
if [ $CONTAINER_STOPPED -eq 0 ]; then
break
fi
done
fi
}
function remove_container_if_exists() {
CONTAINER=$1
machinectl image-status "$CONTAINER" 1> /dev/null 2> /dev/null
CONTAINER_EXISTS=$?
if [ $CONTAINER_EXISTS -eq 0 ]; then
machinectl remove "$CONTAINER"
fi
}
function install_container() {
CONTAINER=$1
make
stop_container_if_running "$CONTAINER"
remove_container_if_exists "$CONTAINER"
make install
make clean
}
if [ $# -eq 0 ]; then
help
else
NSPAWN_FILES_DIR=$(cd "$(dirname "$0")" || exit 1; pwd)
CONTAINERS=( "$@" )
fi
for CONTAINER in "${CONTAINERS[@]}"; do
echo "Build and install $CONTAINER"
cd "$NSPAWN_FILES_DIR/$CONTAINER" || exit 1
install_container "$CONTAINER"
done