Skip to content

Commit d3c26e6

Browse files
committed
add uninstall script
1 parent 77bd1a6 commit d3c26e6

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

dist/dist-packages/linux/nfpm-openziti-controller.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ contents:
3737
- dst: /opt/openziti/etc/controller/
3838
src: ./dist/dist-packages/linux/openziti-controller/bootstrap.bash
3939

40+
- dst: /opt/openziti/etc/controller/
41+
src: ./dist/dist-packages/linux/openziti-controller/uninstall.bash
42+
4043
- dst: /opt/openziti/etc/controller/
4144
src: ./dist/dist-packages/linux/openziti-controller/entrypoint.bash
4245
depends:
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
# initialize a file descriptor for debug output
8+
: "${DEBUG:=0}"
9+
if (( DEBUG )); then
10+
exec 3>&1
11+
set -o xtrace
12+
else
13+
exec 3>/dev/null
14+
fi
15+
16+
# Detect package manager
17+
detect_package_manager() {
18+
if command -v apt-get &>/dev/null; then
19+
echo "apt"
20+
elif command -v dnf &>/dev/null; then
21+
echo "dnf"
22+
elif command -v yum &>/dev/null; then
23+
echo "yum"
24+
else
25+
echo "unknown"
26+
fi
27+
}
28+
29+
# Stop and disable the service
30+
stop_service() {
31+
echo "Stopping and disabling ziti-controller service..."
32+
systemctl disable --now ziti-controller.service || true
33+
systemctl reset-failed ziti-controller.service || true
34+
systemctl clean --what=state ziti-controller.service || true
35+
}
36+
37+
# Remove configuration files
38+
remove_config_files() {
39+
echo "Removing configuration files..."
40+
for FILE in {service,bootstrap}.env
41+
do
42+
[[ -f /opt/openziti/etc/controller/${FILE} ]] && rm -f /opt/openziti/etc/controller/${FILE}
43+
done
44+
}
45+
46+
# Uninstall the package
47+
uninstall_package() {
48+
local pkg_manager
49+
pkg_manager=$(detect_package_manager)
50+
51+
echo "Uninstalling openziti-controller package using ${pkg_manager}..."
52+
53+
case "${pkg_manager}" in
54+
apt)
55+
apt-get purge -y openziti-controller
56+
;;
57+
dnf)
58+
dnf remove -y openziti-controller
59+
;;
60+
yum)
61+
yum remove -y openziti-controller
62+
;;
63+
*)
64+
echo "ERROR: Unsupported package manager. Please uninstall manually." >&2
65+
exit 1
66+
;;
67+
esac
68+
}
69+
70+
# Main execution
71+
main() {
72+
echo "Starting complete removal of openziti-controller..."
73+
74+
stop_service
75+
remove_config_files
76+
uninstall_package
77+
78+
echo "openziti-controller has been completely removed from the system."
79+
}
80+
81+
# Execute main function
82+
main "$@"

0 commit comments

Comments
 (0)