-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdelete_gui_container.sh
executable file
·47 lines (36 loc) · 1.04 KB
/
delete_gui_container.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
#!/bin/bash
#
# Delete a container and associated resources that were created by the "create"
# tool.
# directory on host where bind mounts are created
readonly CONTAINER_MOUNTS_DIR=${HOME}/container_mounts
function usage() {
echo "$(basename $0) container-name"
echo
}
function print_status() {
echo "[+] $*"
}
function print_err() {
echo "[!] $*"
}
if [ $# -lt 1 ]; then
usage
exit 1
fi
readonly CONTAINER_NAME=$1
shift
# name of profile to use
readonly PROFILE_NAME="${CONTAINER_NAME}"
lxc stop "${CONTAINER_NAME}" 2>/dev/null
print_status "Deleting container \"${CONTAINER_NAME}\"."
lxc delete "${CONTAINER_NAME}"
# delete profile AFTER associated containers are deleted
print_status "Deleting profile \"${PROFILE_NAME}\"."
lxc profile delete "${PROFILE_NAME}"
readonly mount_dir="${CONTAINER_MOUNTS_DIR}/${CONTAINER_NAME}"
readonly share_dir="${mount_dir}/share"
# fail if the file sharing bind mount is not empty
rmdir "${share_dir}" || exit 1
print_status "Deleting container mount directory \"${mount_dir}\"."
rm -r "${mount_dir}"