-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuninstall.sh
More file actions
executable file
·95 lines (76 loc) · 3.16 KB
/
Copy pathuninstall.sh
File metadata and controls
executable file
·95 lines (76 loc) · 3.16 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
set -Eeuox pipefail
cd "$(dirname "$0")"
ALL_FLAG=0
for i in "$@"; do
case $i in
--all)
ALL_FLAG=1
;;
*)
# unknown option
;;
esac
done
# install LXD
if [[ -f "$(command -v lxc)" ]]; then
source ./env
if lxc list --format csv | grep -q "$BCM_VM_NAME"; then
lxc delete "$BCM_VM_NAME" --force
fi
## Delete anything that's tied to a project
for project in $(lxc query "/1.0/projects?recursion=1" | jq .[].name -r); do
for container in $(lxc query "/1.0/containers?recursion=1&project=${project}" | jq .[].name -r); do
echo "==> Deleting container '${container}' for project '${project}'"
lxc delete --project "${project}" -f "${container}"
done
for image in $(lxc query "/1.0/images?recursion=1&project=${project}" | jq .[].fingerprint -r); do
FINGERPRINT=${image:0:12}
if ! lxc image list --format csv --columns lf | grep "$FINGERPRINT" | grep -q "bcm-lxc-base"; then
if ! lxc image list --format csv --columns lf | grep "$FINGERPRINT" | grep -q "bcm-vm-base"; then
echo "==> Deleting image ${FINGERPRINT} for project: ${project}"
lxc image delete --project "${project}" "${image}"
fi
fi
if [[ $ALL_FLAG == 1 ]]; then
echo "==> Deleting image ${FINGERPRINT} for project: ${project}"
lxc image delete --project "${project}" "${image}"
fi
done
done
for project in $(lxc query "/1.0/projects?recursion=1" | jq .[].name -r); do
for profile in $(lxc query "/1.0/profiles?recursion=1&project=${project}" | jq .[].name -r); do
if [ "${profile}" = "default" ]; then
printf 'config: {}\ndevices: {}' | lxc profile edit --project "${project}" default
continue
fi
echo "==> Deleting profile '${profile}'."
lxc profile delete --project "${project}" "${profile}"
done
if [ "${project}" != "default" ]; then
echo "==> Deleting project: ${project}"
lxc project delete "${project}"
fi
done
## Delete the networks
for network in $(lxc query "/1.0/networks?recursion=1" | jq '.[] | select(.managed) | .name' -r); do
echo "==> Deleting network '$network'."
lxc network delete "${network}"
done
## Delete the storage pools
for storage_pool in $(lxc query "/1.0/storage-pools?recursion=1" | jq .[].name -r); do
for volume in $(lxc query "/1.0/storage-pools/${storage_pool}/volumes/custom?recursion=1" | jq .[].name -r); do
echo "==> Deleting storage volume ${volume} on ${storage_pool}"
lxc storage volume delete "${storage_pool}" "${volume}"
done
echo "==> Deleting storage pool '${storage_pool}'"
lxc storage delete "${storage_pool}"
done
fi
if [ $ALL_FLAG = 1 ]; then
sudo snap remove lxd
# delete locally cached files.
if [ -d "$HOME/.local/bcm" ]; then
rm -rf "$HOME/.local/bcm"
fi
fi