This repository has been archived by the owner on Mar 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
reset-state
executable file
·85 lines (76 loc) · 1.58 KB
/
reset-state
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
#!/bin/sh
if [ ! -e /var/lib/dpkg/status ]; then
echo "This script only works on Ubuntu Classic"
exit 1
fi
if [ "$(id -u)" != 0 ]; then
echo "This script needs to be run as root"
exit 1
fi
echo "This script will permanently destroy and reset all state in snapd"
echo "You will loose all of your installed snaps"
echo
echo "Type: DESTROY to remove all of your snap state"
echo
read consent
if [ "$consent" != "DESTROY" ]; then
echo "No consent, aborting"
exit 0
fi
echo
echo "ABOUT TO DESTROY ALL OF STATE OF SNAPD"
echo
echo "Interrupt the script in 10 seconds to abort"
sleep 10 || exit
echo
echo "DESTROYING ALL STATE OF SNAPD"
if systemctl is-active --quiet snapd.service snapd.socket; then
snapd_was_active=yes
echo
echo "Stoping snapd..."
echo
(
set -x
systemctl stop snapd.socket snapd.service
)
else
echo "Skipping stopping snapd as systemctl reports it's inactive."
fi
echo
echo "Unmounting all snaps..."
echo
(
set -x
umount /var/lib/snapd/snaps/*.snap
)
echo
echo "Removing all support files and state..."
echo
(
set -x
rm -rvf /var/lib/snapd/*
)
echo
echo "Removing generated systemd units..."
echo
(
set -x
rm -vf /etc/systemd/system/snap-*.mount
rm -vf /etc/systemd/system/snap-*.service
rm -vf /etc/systemd/system/multi-user.target.wants/snap-*.mount
)
echo
echo "Removing generated executable wrappers..."
echo
(
set -x
rm -vrf /snap/*
)
if [ "$snapd_was_active" = "yes" ]; then
echo
echo "Starting snapd"
(
set -x
systemctl start snapd.socket
)
fi