forked from rustdesk/rustdesk-server-pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
266 lines (238 loc) · 6.41 KB
/
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
##################################################################################################################
# Install curl and whiptail if needed
if [ ! -x "$(command -v curl)" ] || [ ! -x "$(command -v whiptail)" ]
then
# We need curl to fetch the lib
# There are the package managers for different OS:
# osInfo[/etc/redhat-release]=yum
# osInfo[/etc/arch-release]=pacman
# osInfo[/etc/gentoo-release]=emerge
# osInfo[/etc/SuSE-release]=zypp
# osInfo[/etc/debian_version]=apt-get
# osInfo[/etc/alpine-release]=apk
NEEDED_DEPS=(curl whiptail)
echo "Installing" "${NEEDED_DEPS[@]}"
if [ -x "$(command -v apt-get)" ]
then
sudo apt-get install "${NEEDED_DEPS[@]}" -y
elif [ -x "$(command -v apk)" ]
then
sudo apk add --no-cache "${NEEDED_DEPS[@]}"
elif [ -x "$(command -v dnf)" ]
then
sudo dnf install "${NEEDED_DEPS[@]}"
elif [ -x "$(command -v zypper)" ]
then
sudo zypper install "${NEEDED_DEPS[@]}"
elif [ -x "$(command -v pacman)" ]
then
sudo pacman -S install "${NEEDED_DEPS[@]}"
elif [ -x "$(command -v yum)" ]
then
sudo yum install "${NEEDED_DEPS[@]}"
elif [ -x "$(command -v emerge)" ]
then
sudo emerge -av "${NEEDED_DEPS[@]}"
else
echo "FAILED TO INSTALL! Package manager not found. You must manually install:" "${NEEDED_DEPS[@]}"
exit 1
fi
fi
# We need to source directly from the Github repo to be able to use the functions here
# shellcheck disable=2034,2059,2164
true
SCRIPT_NAME="Uninstall script"
export SCRIPT_NAME
# shellcheck source=lib.sh
source <(curl -sL https://raw.githubusercontent.com/rustdesk/rustdesk-server-pro/main/lib.sh)
# see https://github.com/koalaman/shellcheck/wiki/Directive
unset SCRIPT_NAME
##################################################################################################################
# Check if root
root_check
# Output debugging info if $DEBUG set
if [ "$DEBUG" = "true" ]
then
identify_os
print_text_in_color "$ICyan" "OS: $OS"
print_text_in_color "$ICyan" "VER: $VER"
print_text_in_color "$ICyan" "UPSTREAM_ID: $UPSTREAM_ID"
exit 0
fi
# Switch for Certbot
if [ -d /etc/letsencrypt ]
then
CERTBOT_SWITCH=ON
else
CERTBOT_SWITCH=OFF
fi
# Uninstall Rustdesk Menu
choice=$(whiptail --title "$TITLE" --checklist \
"Please choose what to uninstall:\n\n
$CHECKLIST_GUIDE\n\n$RUN_LATER_GUIDE" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"certbot" "(Everything related to Let's Encrypt)" "$CERTBOT_SWITCH" \
"rustdesk-logs" "(RustDesk LOG dir)" ON \
"rustdesk-server" "(RustDesk SERVER + RustDesk services)" ON \
"nginx-rustdesk" "(RustDesk Nginx config)" OFF \
"nginx" "(Linux webserver package + ALL configs)" ON \
"ufw" "(Linux firewall package + RustDesk rules)" ON \
"whiptail" "(Linux menu package)" ON \
"curl" "(Linux package)" OFF \
"wget" "(Linux package)" OFF \
"unzip" "(Linux package)" OFF \
"dnsutils" "(Linux package)" ON \
"bind-utils" "(Linux package)" ON \
"bind" "(Linux package)" ON 3>&1 1>&2 2>&3)
case "$choice" in
*"nginx-rustdesk"*)
REMOVE_NGINX_CONF="yes"
;;&
*"nginx"*)
REMOVE_NGINX_ALL="yes"
;;&
*"wget"*)
REMOVE_WGET="yes"
;;&
*"whiptail"*)
REMOVE_WHIPTAIL="yes"
;;&
*"unzip"*)
REMOVE_UNZIP="yes"
;;&
*"dnsutils"*)
REMOVE_DNSUTILS="yes"
;;&
*"bind-utils"*)
REMOVE_BIND_UTILS="yes"
;;&
*"bind"*)
REMOVE_BIND="yes"
;;&
*"ufw"*)
REMOVE_UFW="yes"
;;&
*"rustdesk-logs"*)
REMOVE_RUSTDESK_LOG="yes"
;;&
*"rustdesk-server"*)
REMOVE_RUSTDESK_SERVER="yes"
;;&
*"curl"*)
REMOVE_CURL="yes"
;;&
*"certbot"*)
REMOVE_CERTBOT="yes"
;;&
*)
;;
esac
msg_box "WARNING WARNING WARNING
This script will remove EVERYTHING that was chosen in the previous selection.
You can choose to opt out after you hit OK."
if ! yesno_box_no "Are you REALLY sure you want to continue with the uninstallation?"
then
exit 0
fi
if [ -n "$UFW" ]
then
# Deleting UFW rules
ufw delete allow 21115:21119/tcp
# ufw delete 22/tcp # If connected to a remote VPS, this deletion will make the connection go down
ufw delete allow 21116/udp
if [ -f "/etc/nginx/sites-available/rustdesk.conf" ] || [ -f "/etc/nginx/conf.d/rustdesk.conf" ]
then
ufw delete allow 80/tcp
ufw delete allow 443/tcp
else
ufw delete allow 21114/tcp
fi
ufw --force disable
ufw --force reload
fi
# Rustdesk Server
if [ -n "$REMOVE_RUSTDESK_SERVER" ]
then
# Rustdesk installation dir
print_text_in_color "$IGreen" "Removing RustDesk Server..."
rm -rf "$RUSTDESK_INSTALL_DIR"
rm -rf /usr/bin/hbbs
rm -rf /usr/bin/hbbr
# systemctl services
# HBBS
systemctl disable rustdesk-hbbs.service
systemctl stop rustdesk-hbbs.service
rm -f "/etc/systemd/system/rustdesk-hbbs.service"
# HBBR
systemctl disable rustdesk-hbbr.service
systemctl stop rustdesk-hbbr.service
rm -f "/etc/systemd/system/rustdesk-hbbr.service"
# daemon-reload
systemctl daemon-reload
fi
# Rustdesk LOG
if [ -n "$REMOVE_RUSTDESK_LOG" ]
then
# Rustdesk LOG dir
rm -rf "$RUSTDESK_LOG_DIR"
fi
# Certbot
if [ -n "$REMOVE_CERTBOT" ]
then
if snap list | grep -q certbot > /dev/null
then
purge_linux_package snap
snap remove certbot
else
purge_linux_package python3-certbot-nginx -y
fi
# Also remove the actual certs
rm -rf /etc/letsencrypt
fi
# Nginx
if [ -n "$REMOVE_NGINX_CONF" ]
then
rm -f "/etc/nginx/sites-available/rustdesk.conf"
rm -f "/etc/nginx/sites-enabled/rustdesk.conf"
rm -f "/etc/nginx/conf.d/rustdesk.conf"
service nginx restart
elif [ -n "$REMOVE_NGINX_ALL" ]
then
purge_linux_package nginx
rm -rf "/etc/nginx"
fi
# The rest
if [ -n "$REMOVE_CURL" ]
then
purge_linux_package curl
fi
if [ -n "$REMOVE_WGET" ]
then
purge_linux_package wget
fi
if [ -n "$REMOVE_UNZIP" ]
then
purge_linux_package unzip
fi
if [ -n "$REMOVE_DNSUTILS" ]
then
purge_linux_package dnsutils
fi
if [ -n "$REMOVE_BIND_UTILS" ]
then
purge_linux_package bind-utils
fi
if [ -n "$REMOVE_BIND" ]
then
purge_linux_package bind
fi
if [ -n "$REMOVE_UFW" ]
then
purge_linux_package ufw
fi
msg_box "Uninstallation complete!
Please hit OK to remove the last package."
if [ -n "$REMOVE_WHIPTAIL" ]
then
purge_linux_package whiptail
fi