forked from canonical/snapd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapd.postrm
67 lines (58 loc) · 2.25 KB
/
snapd.postrm
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
#!/bin/sh
set -e
systemctl_stop() {
unit="$1"
if systemctl is-active -q "$unit"; then
echo "Stoping $unit"
systemctl stop -q "$unit" || true
fi
}
if [ "$1" = "purge" ]; then
mounts=$(systemctl list-unit-files | grep '^snap[-.].*\.mount' | cut -f1 -d ' ')
services=$(systemctl list-unit-files | grep '^snap[-.].*\.service' | cut -f1 -d ' ')
for unit in $services $mounts; do
# ensure its really a snapp mount unit or systemd unit
if ! grep -q 'What=/var/lib/snapd/snaps/' "/etc/systemd/system/$unit" && ! grep -q 'X-Snappy=yes' "/etc/systemd/system/$unit"; then
echo "Skipping non-snapd systemd unit $unit"
continue
fi
echo "Stopping $unit"
systemctl_stop "$unit"
# if it is a mount unit, we can find the snap name in the mount
# unit (we just ignore unit files)
snap=$(grep 'Where=/snap/' "/etc/systemd/system/$unit"|cut -f3 -d/)
rev=$(grep 'Where=/snap/' "/etc/systemd/system/$unit"|cut -f4 -d/)
if [ -n "$snap" ]; then
echo "Removing snap $snap"
# generated binaries
rm -f "/snap/bin/$snap"
rm -f "/snap/bin/$snap".*
# snap mount dir
umount -l "/snap/$snap/$rev" 2> /dev/null || true
rm -rf "/snap/$snap/$rev"
rm -f "/snap/$snap/current"
# snap data dir
rm -rf "/var/snap/$snap/$rev"
rm -rf "/var/snap/$snap/common"
rm -f "/var/snap/$snap/current"
# opportunistic remove (may fail if there are still revisions left
for d in "/snap/bin" "/snap/$snap" "/var/snap/$snap" "/snap" "/var/snap"; do
if [ -d "$d" ]; then
rmdir --ignore-fail-on-non-empty $d
fi
done
fi
echo "Removing $unit"
rm -f "/etc/systemd/system/$unit"
rm -f "/etc/systemd/system/multi-user.target.wants/$unit"
done
echo "Discarding preserved snap namespaces"
# opportunistic as those might not be actually mounted
for mnt in /run/snapd/ns/*.mnt; do
umount -l "$mnt" || true
done
umount -l /run/snapd/ns/ || true
echo "Removing snapd state"
rm -rf /var/lib/snapd
fi
#DEBHELPER#