Skip to content

Commit 7698a1f

Browse files
authored
Merge pull request #71 from thin-edge/feat-add-uninstall-script
feat: add uninstall script
2 parents 3111368 + c89ebd1 commit 7698a1f

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

docs/Actility-TAO.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ This is the thin-edge installation instructions for Actility TAO device -- kerli
4646
* If you don't see the registration URL on your console then try closing the terminal, and opening a new window as sometimes the terminal's output can get corrupted and hide messages that were printed to it.
4747
4848
4. Reboot the device to verify that thin-edge.io automatically connects to Cumulocity
49+
50+
### Uninstalling
51+
52+
You can uninstall thin-edge.io by running the following script, though this will stop and remove all components, so please do not run on a production system!
53+
54+
```sh
55+
wget -q -O - https://raw.githubusercontent.com/thin-edge/tedge-standalone/main/uninstall.sh | sh -s -- --install-path /user --force
56+
```

uninstall.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/sh
2+
set -e
3+
4+
FORCE=0
5+
INSTALL_PATH="${INSTALL_PATH:-/data}"
6+
7+
usage() {
8+
cat << EOT
9+
Remove thin-edge.io and all of its components.
10+
11+
USAGE
12+
$0 --force
13+
14+
ARGUMENTS
15+
--force Force removal of thin-edge.io.
16+
If not provided then the script will not do anything
17+
--install-path <path> Install path. Defaults to $INSTALL_PATH
18+
19+
EXAMPLE
20+
21+
$0 --force
22+
# Remove thin-edge.io
23+
24+
$0 --force --install-path /user
25+
# Remove thin-edge.io under the /user directory
26+
EOT
27+
}
28+
29+
while [ $# -gt 0 ]; do
30+
case "$1" in
31+
--force)
32+
FORCE=1
33+
;;
34+
--install-path)
35+
INSTALL_PATH="$2"
36+
shift
37+
;;
38+
--help|-h)
39+
usage
40+
exit 0
41+
;;
42+
--*|-*)
43+
echo "Unknown flags. $1" >&2
44+
exit 1
45+
;;
46+
*)
47+
echo "Unexpected positional arguments" >&2
48+
exit 1
49+
;;
50+
esac
51+
shift
52+
done
53+
54+
if [ "$FORCE" != 1 ]; then
55+
echo "ERROR: You must call this script with '--force' to confirm the removal of thin-edge.io" >&2
56+
exit 1
57+
fi
58+
59+
BASE_DIR="$INSTALL_PATH/tedge"
60+
61+
if [ ! -d "$BASE_DIR" ]; then
62+
echo "ERROR: tedge installation path was not found. path=$BASE_DIR"
63+
exit 1
64+
fi
65+
66+
if [ -f "$BASE_DIR/env" ]; then
67+
# shellcheck disable=SC1091
68+
. "$BASE_DIR/env"
69+
fi
70+
71+
echo "Stopping services" >&2
72+
tedgectl stop tedge-mapper-c8y ||:
73+
tedgectl stop tedge-agent ||:
74+
tedgectl stop mosquitto ||:
75+
76+
# monit config (if present)
77+
rm -f /etc/monit.d/tedge
78+
79+
# service definitions
80+
echo "Removing service definitions" >&2
81+
rm -f /etc/init.d/*tedge-agent*
82+
rm -f /etc/init.d/*tedge-mapper*
83+
rm -f /etc/init.d/*mosquitto*
84+
85+
if command -V update-rc.d >/dev/null 2>&1; then
86+
# remove old services which are no longer used
87+
update-rc.d -f tedge-reconnect remove >/dev/null 2>&1 ||:
88+
fi
89+
90+
# logs
91+
echo "Removing log files" >&2
92+
rm -rf "$(tedge config get logs.path)"
93+
rm -rf "$(tedge config get data.path)"
94+
rm -rf /var/log/tedge-*.log
95+
96+
# shell profiles
97+
rm -f /etc/profile.d/tedge
98+
99+
# app
100+
if [ -d "$BASE_DIR" ]; then
101+
echo "Removing thin-edge.io directory. path=$BASE_DIR" >&2
102+
rm -rf "$BASE_DIR"
103+
fi

0 commit comments

Comments
 (0)