-
Notifications
You must be signed in to change notification settings - Fork 1
/
lxc-bootstrap.sh
executable file
·58 lines (44 loc) · 1.51 KB
/
lxc-bootstrap.sh
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
53
54
55
56
57
58
#!/bin/sh -e
# Run bootstrap.sh in a new LXD container.
script=$(readlink -f "$0")
script_path=$(dirname "${script}")
if [ "$#" -lt 2 ]; then
cat <<- EOF
Usage: lxc-bootstrap.sh image command [option ...]
The image argument is the LXD image you want to test bootstrap.sh with.
The commands and options are those for bootstrap.sh, as follows:
EOF
"${script_path}/bootstrap.sh" --help-all | grep -A 1000 '^Commands:'
exit 1
fi
image="$1"
name=$(echo "${image}-$2" | sed 's|^[^:]*:||; s|[^a-z0-9]|-|g;')
shift
args="$*"
echo "Checking for existing ${name} container."
if lxc info "${name}" > /dev/null 2>&1; then
echo "Deleting ${name} container."
lxc delete "${name}" --force > /dev/null 2>&1
echo "Waiting for ${name} container to be deleted."
while lxc info "${name}" > /dev/null 2>&1; do
sleep 1
done
echo "Successfully deleted ${name} container."
else
echo "Did not find ${name} container."
fi
echo "Launching ${name} container from ${image} image."
lxc launch "${image}" "${name}"
echo "Waiting for networking to come up in ${name} container."
while ! lxc info "${name}" | grep 'eth0:\sinet\s' > /dev/null 2>&1; do
sleep 1
done
echo "Networking is up in ${name} container."
echo "Pushing bootstrap.sh to ${name} container."
"${script_path}/lxc-push.sh" \
"${script_path}/bootstrap.sh" \
"${name}/root/bootstrap.sh"
echo "Executing bootstrap.sh in ${name} container."
# shellcheck disable=SC2086
lxc exec "${name}" -- /root/bootstrap.sh ${args}
echo "Completed bootstrap.sh in ${name} container."