Non-interactive uninstaller (#5021)
Paweł Krupa committed
Dec 18, 2018 at 14:02 UTC
889734018bc70cc81c18102742eb33e4f16f6ea3
3 files changed
+71
-25
installer/UNINSTALL.md
+1
-1
@@ -8,7 +8,7 @@ To uninstall netdata, run:
8
9
```
10
cd /path/to/netdata.git
11
-./netdata-uninstaller.sh --force
11
+./netdata-uninstaller.sh --yes
12
```
13
14
The uninstaller will ask you to confirm all deletions.
installer/netdata-uninstaller.sh
+60
-18
@@ -7,9 +7,42 @@
7
# - NETDATA_PREFIX
8
# - NETDATA_ADDED_TO_GROUPS
9
10
-if [ "$1" != "--force" ]; then
10
+usage="$(basename "$0") [-h] [-f ] -- program to calculate the answer to life, the universe and everything
11
+
12
+where:
13
+ -h show this help text
14
+ -f, --force force uninstallation and do not ask any questions
15
+ -y, --yes flag needs to be set to proceed with uninstallation"
16
+
17
+RM_FLAGS="-i"
18
+INTERACTIVE=1
19
+YES=0
20
+while :; do
21
+ case "$1" in
22
+ -h | --help)
23
+ echo "$usage" >&2
24
+ exit 1
25
+ ;;
26
+ -f | --force)
27
+ RM_FLAGS="-f"
28
+ INTERACTIVE=0
29
+ shift
30
+ ;;
31
+ -y | --yes)
32
+ YES=1
33
+ shift
34
+ ;;
35
+ -*)
36
+ echo "$usage" >&2
37
+ exit 1
38
+ ;;
39
+ *) break ;;
40
+ esac
41
+done
42
+
43
+if [ "$YES" != "1" ]; then
44
echo >&2 "This script will REMOVE netdata from your system."
12
- echo >&2 "Run it again with --force to do it."
45
+ echo >&2 "Run it again with --yes to do it."
46
exit 1
47
fi
48
@@ -24,53 +57,62 @@ sleep 2
57
58
if [ ! -z "${NETDATA_PREFIX}" ] && [ -d "${NETDATA_PREFIX}" ]; then
59
# installation prefix was given
27
-
28
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}"
29
-
60
+ if [ $INTERACTIVE -eq 1 ]; then
61
+ portable_deletedir_recursively_interactively "${NETDATA_PREFIX}"
62
+ else
63
+ run rm -f -R "${NETDATA_PREFIX}"
64
+ fi
65
else
66
# installation prefix was NOT given
67
68
if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]; then
69
echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
35
- run rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
70
+ run rm ${RM_FLAGS} "${NETDATA_PREFIX}/usr/sbin/netdata"
71
fi
72
38
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/etc/netdata"
39
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/usr/share/netdata"
40
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/usr/libexec/netdata"
41
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/lib/netdata"
42
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/cache/netdata"
43
- portable_deletedir_recursively_interactively "${NETDATA_PREFIX}/var/log/netdata"
73
+ for dir in "${NETDATA_PREFIX}/etc/netdata" \
74
+ "${NETDATA_PREFIX}/usr/share/netdata" \
75
+ "${NETDATA_PREFIX}/usr/libexec/netdata" \
76
+ "${NETDATA_PREFIX}/var/lib/netdata" \
77
+ "${NETDATA_PREFIX}/var/cache/netdata" \
78
+ "${NETDATA_PREFIX}/var/log/netdata"
79
+ do
80
+ if [ $INTERACTIVE -eq 1 ]; then
81
+ portable_deletedir_recursively_interactively "${dir}"
82
+ else
83
+ run rm -f -R "${dir}"
84
+ fi
85
+ done
86
fi
87
88
if [ -f /etc/logrotate.d/netdata ]; then
89
echo "Deleting /etc/logrotate.d/netdata ..."
48
- run rm -i /etc/logrotate.d/netdata
90
+ run rm ${RM_FLAGS} /etc/logrotate.d/netdata
91
fi
92
93
if [ -f /etc/systemd/system/netdata.service ]; then
94
echo "Deleting /etc/systemd/system/netdata.service ..."
53
- run rm -i /etc/systemd/system/netdata.service
95
+ run rm ${RM_FLAGS} /etc/systemd/system/netdata.service
96
fi
97
98
if [ -f /lib/systemd/system/netdata.service ]; then
99
echo "Deleting /lib/systemd/system/netdata.service ..."
58
- run rm -i /lib/systemd/system/netdata.service
100
+ run rm ${RM_FLAGS} /lib/systemd/system/netdata.service
101
fi
102
103
if [ -f /etc/init.d/netdata ]; then
104
echo "Deleting /etc/init.d/netdata ..."
63
- run rm -i /etc/init.d/netdata
105
+ run rm ${RM_FLAGS} /etc/init.d/netdata
106
fi
107
108
if [ -f /etc/periodic/daily/netdata-updater ]; then
109
echo "Deleting /etc/periodic/daily/netdata-updater ..."
68
- run rm -i /etc/periodic/daily/netdata-updater
110
+ run rm ${RM_FLAGS} /etc/periodic/daily/netdata-updater
111
fi
112
113
if [ -f /etc/cron.daily/netdata-updater ]; then
114
echo "Deleting /etc/cron.daily/netdata-updater ..."
73
- run rm -i /etc/cron.daily/netdata-updater
115
+ run rm ${RM_FLAGS} /etc/cron.daily/netdata-updater
116
fi
117
118
portable_check_user_exists netdata
tests/lifecycle.sh
+10
-6
@@ -8,13 +8,16 @@ then
8
exit 1
9
fi
10
11
-if ! git config user.name; then
12
- git config user.email "test@example.com"
13
- git config user.name "test"
14
-fi
11
+WORKSPACE=$(mktemp -d)
12
+cp -r ./ "${WORKSPACE}/"
13
+cd "${WORKSPACE}"
14
+git config user.email "test@example.com"
15
+git config user.name "test"
16
17
echo "========= INSTALL ========="
18
./netdata-installer.sh --dont-wait --dont-start-it --install /tmp &>/dev/null
19
+# Copy uninstaller as upgrader will overwrite it with a version from master branch
20
+cp netdata-uninstaller.sh /tmp/netdata-uninstaller.sh
21
22
echo "========= ADD GARBAGE ========="
23
touch test
@@ -26,5 +29,6 @@ git status
29
echo "========= UPDATE ========="
30
./netdata-updater.sh
31
29
-#echo "========= UNINSTALL ========="
30
-#./netdata-uninstaller.sh
32
+echo "========= UNINSTALL ========="
33
+mv /tmp/netdata-uninstaller.sh ./netdata-uninstaller.sh
34
+./netdata-uninstaller.sh --yes --force