-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-uninstall.sh
executable file
·93 lines (80 loc) · 2.17 KB
/
service-uninstall.sh
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
86
87
88
89
90
91
92
93
#!/usr/bin/env bash
#
# remove systemd service files
# optionally, --reload systemd
# optionally, --wipe goto_http_redirect_server configuration files
#
set -e
set -u
set -o pipefail
GOTO_FILE_REDIRECTS=/usr/local/share/goto_http_redirect_server.csv
GOTO_SYSTEMD_SH=/usr/local/bin/goto_http_redirect_server.sh
GOTO_CONFIG=/etc/goto_http_redirect_server.conf
GOTO_SERVICE=goto_http_redirect_server.service
GOTO_FILE_SERVICE=/etc/systemd/user/${GOTO_SERVICE}
reload=false
wipe=false
if ! which getopt &>/dev/null; then
echo "ERROR: GNU getopt not found. It is part of util-linux package." >&2
exit 1
fi
options=$(getopt -n "$(basename -- "${0}")" -o "rwh?" -l "reload,wipe,help" -- "${@}")
eval set -- "${options}"
while true; do
case "${1-}" in
-r|--reload)
reload=true
shift
;;
-w|--wipe)
wipe=true
shift
;;
--)
shift
break
;;
*)
;&
h|help)
;&
\?)
(
echo "Usage: ${0} [-r|--reload] [-w|--wipe]"
echo
echo " -r reload systemd"
echo " -w wipe (remove) configuration files:"
echo " ${GOTO_CONFIG}"
echo " ${GOTO_FILE_REDIRECTS}"
echo
echo "Usage: ${0} [-h|--help|-?]"
echo
echo " This help message"
) >&2
exit 4
;;
esac
done
cd "$(dirname -- "${0}")/.."
set +e # no `set -e`; attempt to remove as much as possible
declare -i ret=0 # but signal remove failures in script return code
rm -v -- "${GOTO_SYSTEMD_SH}" "${GOTO_FILE_SERVICE}" || ret=1
if ${reload}; then
(
set -x
systemctl stop "${GOTO_SERVICE}"
systemctl disable "${GOTO_SERVICE}"
)
rm -v -- "${GOTO_SYSTEMD_SH}" "${GOTO_FILE_SERVICE}" || ret=1
(
set -x
systemctl daemon-reload
systemctl reset-failed
)
shift
fi
if ${wipe}; then
rm -v -- "${GOTO_CONFIG}" "${GOTO_FILE_REDIRECTS}" || ret=1
shift
fi
exit ${ret}