forked from pterodactyl-installer/pterodactyl-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
332 lines (294 loc) · 9.81 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/bash
set -e
#############################################################################
# #
# Project 'pterodactyl-installer' #
# #
# Copyright (C) 2018 - 2022, Vilhelm Prytz, <[email protected]> #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
# #
# https://github.com/vilhelmprytz/pterodactyl-installer/blob/master/LICENSE #
# #
# This script is not associated with the official Pterodactyl Project. #
# https://github.com/vilhelmprytz/pterodactyl-installer #
# #
#############################################################################
######## General checks #########
# exit with error status code if user is not root
if [[ $EUID -ne 0 ]]; then
echo "* This script must be executed with root privileges (sudo)." 1>&2
exit 1
fi
# check for curl
if ! [ -x "$(command -v curl)" ]; then
echo "* curl is required in order for this script to work."
echo "* install using apt (Debian and derivatives) or yum/dnf (CentOS)"
exit 1
fi
########## Variables ############
RM_PANEL=false
RM_WINGS=false
####### Visual functions ########
print_brake() {
for ((n = 0; n < $1; n++)); do
echo -n "#"
done
echo ""
}
output() {
echo "* ${1}"
}
print_list() {
print_brake 30
for word in $1; do
output "$word"
done
print_brake 30
echo ""
}
error() {
COLOR_RED='\033[0;31m'
COLOR_NC='\033[0m'
echo ""
echo -e "* ${COLOR_RED}ERROR${COLOR_NC}: $1"
echo ""
}
warning() {
COLOR_YELLOW='\033[1;33m'
COLOR_NC='\033[0m'
echo ""
echo -e "* ${COLOR_YELLOW}WARNING${COLOR_NC}: $1"
echo ""
}
summary() {
print_brake 30
output "Uninstall panel? $RM_PANEL"
output "Uninstall wings? $RM_WINGS"
print_brake 30
}
####### OS check funtions #######
detect_distro() {
if [ -f /etc/os-release ]; then
# freedesktop.org and systemd
. /etc/os-release
OS=$(echo "$ID" | awk '{print tolower($0)}')
OS_VER=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
# linuxbase.org
OS=$(lsb_release -si | awk '{print tolower($0)}')
OS_VER=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
# For some versions of Debian/Ubuntu without lsb_release command
. /etc/lsb-release
OS=$(echo "$DISTRIB_ID" | awk '{print tolower($0)}')
OS_VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
# Older Debian/Ubuntu/etc.
OS="debian"
OS_VER=$(cat /etc/debian_version)
elif [ -f /etc/SuSe-release ]; then
# Older SuSE/etc.
OS="SuSE"
OS_VER="?"
elif [ -f /etc/redhat-release ]; then
# Older Red Hat, CentOS, etc.
OS="Red Hat/CentOS"
OS_VER="?"
else
# Fall back to uname, e.g. "Linux <version>", also works for BSD, etc.
OS=$(uname -s)
OS_VER=$(uname -r)
fi
OS=$(echo "$OS" | awk '{print tolower($0)}')
OS_VER_MAJOR=$(echo "$OS_VER" | cut -d. -f1)
}
check_os_comp() {
SUPPORTED=false
case "$OS" in
ubuntu)
[ "$OS_VER_MAJOR" == "18" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "20" ] && SUPPORTED=true
;;
debian)
[ "$OS_VER_MAJOR" == "9" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "10" ] && SUPPORTED=true
;;
centos)
[ "$OS_VER_MAJOR" == "7" ] && SUPPORTED=true
[ "$OS_VER_MAJOR" == "8" ] && SUPPORTED=true
;;
esac
# exit if not supported
if [ "$SUPPORTED" == true ]; then
echo "* $OS $OS_VER is supported."
else
echo "* $OS $OS_VER is not supported"
error "Unsupported OS"
exit 1
fi
}
### Main uninstallation functions ###
rm_panel_files() {
output "Removing panel files..."
rm -rf /var/www/pterodactyl /usr/local/bin/composer
[ "$OS" != "centos" ] && unlink /etc/nginx/sites-enabled/pterodactyl.conf
[ "$OS" != "centos" ] && rm -f /etc/nginx/sites-available/pterodactyl.conf
[ "$OS" != "centos" ] && ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
[ "$OS" == "centos" ] && rm -f /etc/nginx/conf.d/pterodactyl.conf
systemctl restart nginx
output "Succesfully removed panel files."
}
rm_wings_files() {
output "Removing wings files..."
# stop and remove wings service
systemctl disable --now wings
rm -rf /etc/systemd/system/wings.service
rm -rf /etc/pterodactyl /usr/local/bin/wings /var/lib/pterodactyl
output "Succesfully removed wings files."
}
rm_services() {
output "Removing services..."
systemctl disable --now pteroq
rm -rf /etc/systemd/system/pteroq.service
case "$OS" in
debian | ubuntu)
systemctl disable --now redis-server
;;
centos)
systemctl disable --now redis
systemctl disable --now php-fpm
rm -rf /etc/php-fpm.d/www-pterodactyl.conf
;;
esac
output "Succesfully removed services."
}
rm_cron() {
output "Removing cron jobs..."
crontab -l | grep -vF "* * * * * php /var/www/pterodactyl/artisan schedule:run >> /dev/null 2>&1" | crontab -
output "Succesfully removed cron jobs."
}
rm_database() {
output "Removing database..."
valid_db=$(mysql -u root -e "SELECT schema_name FROM information_schema.schemata;" | grep -v -E -- 'schema_name|information_schema|performance_schema|mysql')
warning "Be careful! This database will be deleted!"
if [[ "$valid_db" == *"panel"* ]]; then
echo -n "* Database called panel has been detected. Is it the pterodactyl database? (y/N): "
read -r is_panel
if [[ "$is_panel" =~ [Yy] ]]; then
DATABASE=panel
else
print_list "$valid_db"
fi
else
print_list "$valid_db"
fi
while [ -z "$DATABASE" ] || [[ $valid_db != *"$database_input"* ]]; do
echo -n "* Choose the panel database (to skip don't input anything): "
read -r database_input
if [[ -n "$database_input" ]]; then
DATABASE="$database_input"
else
break
fi
done
[[ -n "$DATABASE" ]] && mysql -u root -e "DROP DATABASE $DATABASE;"
# Exclude usernames User and root (Hope no one uses username User)
output "Removing database user..."
valid_users=$(mysql -u root -e "SELECT user FROM mysql.user;" | grep -v -E -- 'user|root')
warning "Be careful! This user will be deleted!"
if [[ "$valid_users" == *"pterodactyl"* ]]; then
echo -n "* User called pterodactyl has been detected. Is it the pterodactyl user? (y/N): "
read -r is_user
if [[ "$is_user" =~ [Yy] ]]; then
DB_USER=pterodactyl
else
print_list "$valid_users"
fi
else
print_list "$valid_users"
fi
while [ -z "$DB_USER" ] || [[ $valid_users != *"$user_input"* ]]; do
echo -n "* Choose the panel user (to skip don't input anything): "
read -r user_input
if [[ -n "$user_input" ]]; then
DB_USER=$user_input
else
break
fi
done
[[ -n "$DB_USER" ]] && mysql -u root -e "DROP USER $DB_USER@'127.0.0.1';"
mysql -u root -e "FLUSH PRIVILEGES;"
output "Succesfully removed database and database user."
}
## MAIN FUNCTIONS ##
perform_uninstall() {
[ "$RM_PANEL" == true ] && rm_panel_files
[ "$RM_PANEL" == true ] && rm_cron
[ "$RM_PANEL" == true ] && rm_database
[ "$RM_PANEL" == true ] && rm_services
[ "$RM_WINGS" == true ] && rm_wings_files
true
}
main() {
detect_distro
print_brake 70
output "Pterodactyl uninstallation script"
output
output "Copyright (C) 2018 - 2022, Vilhelm Prytz, <[email protected]>"
output "https://github.com/vilhelmprytz/pterodactyl-installer"
output
output "Sponsoring/Donations: https://github.com/vilhelmprytz/pterodactyl-installer?sponsor=1"
output "This script is not associated with the official Pterodactyl Project."
output
output "Running $OS version $OS_VER."
print_brake 70
check_os_comp
if [ -d "/var/www/pterodactyl" ]; then
output "Panel installation has been detected."
echo -e -n "* Do you want to remove panel? (y/N): "
read -r RM_PANEL_INPUT
[[ "$RM_PANEL_INPUT" =~ [Yy] ]] && RM_PANEL=true
fi
if [ -d "/etc/pterodactyl" ]; then
output "Wings installation has been detected."
warning "This will remove all the servers!"
echo -e -n "* Do you want to remove Wings (daemon)? (y/N): "
read -r RM_WINGS_INPUT
[[ "$RM_WINGS_INPUT" =~ [Yy] ]] && RM_WINGS=true
fi
if [ "$RM_PANEL" == false ] && [ "$RM_WINGS" == false ]; then
error "Nothing to uninstall!"
exit 1
fi
summary
# confirm uninstallation
echo -e -n "* Continue with uninstallation? (y/N): "
read -r CONFIRM
if [[ "$CONFIRM" =~ [Yy] ]]; then
perform_uninstall
else
error "Uninstallation aborted."
exit 1
fi
}
goodbye() {
print_brake 62
[ "$RM_PANEL" == true ] && output "Panel uninstallation completed"
[ "$RM_WINGS" == true ] && output "Wings uninstallation completed"
output "Thank you for using this script."
print_brake 62
}
main
goodbye