-
Notifications
You must be signed in to change notification settings - Fork 18
/
backup.sh
231 lines (208 loc) · 6.6 KB
/
backup.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
#!/bin/bash
#shellcheck source=/dev/null
set -e
########################################################
#
# Pterodactyl-AutoAddons Installation
#
# Created and maintained by Ferks-FK
#
# Protected by GPL 3.0 License
#
########################################################
# Fixed Variables #
SUPPORT_LINK="https://discord.gg/buDBbSGJmQ"
# Update Variables #
update_variables() {
INFORMATIONS="/var/log/Pterodactyl-AutoAddons-informations"
MORE_BUTTONS="${PTERO}/resources/scripts/components/server/MoreButtons.tsx"
PMA_ARCH="${PTERO}/resources/scripts/routers/ServerRouter.tsx"
PMA_FILE="${PTERO}/resources/scripts/components/server/databases/DatabaseRow.tsx"
PMA_REDIRECT_FILE="${PTERO}/public/pma_redirect.html"
PMA_NAME="${PTERO}/public/phpmyadmin"
MC_PASTE="${PTERO}/app/Repositories/Eloquent/MCPasteVariableRepository.php"
FILES_IN_EDITOR="${PTERO}/resources/scripts/components/server/files/FileViewer.tsx"
if [ -f "${INFORMATIONS}/user.txt" ]; then USERNAME="$(cat "${INFORMATIONS}/user.txt")"; fi
if [ -f "${INFORMATIONS}/pass.txt" ]; then PASSWORD="$(cat "${INFORMATIONS}/pass.txt")"; fi
if [ -f "${INFORMATIONS}/check_variable.txt" ]; then GET_INFO="$(cat "${INFORMATIONS}/check_variable.txt")"; fi
if [ -f "${INFORMATIONS}/custom_directory.txt" ]; then CUSTOM_DIRECTORY="$(cat "${INFORMATIONS}/custom_directory.txt")"; fi
}
# Visual Functions #
print_brake() {
for ((n = 0; n < $1; n++)); do
echo -n "#"
done
echo ""
}
print_warning() {
echo ""
echo -e "* ${YELLOW}WARNING${RESET}: $1"
echo ""
}
print_error() {
echo ""
echo -e "* ${RED}ERROR${RESET}: $1"
echo ""
}
print() {
echo ""
echo -e "* ${GREEN}$1${RESET}"
echo ""
}
hyperlink() {
echo -e "\e]8;;${1}\a${1}\e]8;;\a"
}
GREEN="\e[0;92m"
YELLOW="\033[1;33m"
RESET="\e[0m"
RED='\033[0;31m'
# Find where pterodactyl is installed #
find_pterodactyl() {
print "Looking for your pterodactyl installation..."
sleep 2
if [ -d "/var/www/pterodactyl" ]; then
PTERO_INSTALL=true
PTERO="/var/www/pterodactyl"
elif [ -d "/var/www/panel" ]; then
PTERO_INSTALL=true
PTERO="/var/www/panel"
elif [ -d "/var/www/ptero" ]; then
PTERO_INSTALL=true
PTERO="/var/www/ptero"
else
PTERO_INSTALL=false
fi
# Update the variables after detection of the pterodactyl installation #
update_variables
}
# Deletes all files installed by the script #
delete_files() {
# ADDON MORE_BUTONS #
if [ -f "$MORE_BUTTONS" ]; then
rm -r "$MORE_BUTTONS"
fi
# ADDON MORE_BUTONS #
# ADDON PMA_BUTTON_NAVBAR #
if grep "<a href='/phpmyadmin' target='_blank'>PhpMyAdmin</a>" "$PMA_ARCH" &>/dev/null; then
rm -r "$PMA_NAME"
rm -r /etc/phpmyadmin
if [ "$GET_INFO" == true ]; then
if [ -f "$INFORMATIONS/user.txt" ]; then
mysql -u root -p"$PASSWORD" -e "DROP USER '${USERNAME}'@'%';"
rm -r "$INFORMATIONS/user.txt"
fi
mysql -u root -p"$PASSWORD" -e "DROP USER 'pma'@'127.0.0.1';"
mysql -u root -p"$PASSWORD" -e "DROP DATABASE phpmyadmin;"
elif [ "$GET_INFO" == false ]; then
if [ -f "$INFORMATIONS/user.txt" ]; then
mysql -u root -e "DROP USER '${USERNAME}'@'%';"
rm -r "$INFORMATIONS/user.txt"
fi
mysql -u root -e "DROP USER 'pma'@'127.0.0.1';"
mysql -u root -e "DROP DATABASE phpmyadmin;"
fi
rm -r "$INFORMATIONS"
fi
# ADDON PMA_BUTTON_NAVBAR #
# ADDON PMA_BUTTON_DATABASE_TAB #
if grep 'location.replace("/pma_redirect.html");' "$PMA_FILE" &>/dev/null; then
rm -r "$PMA_NAME" "$PMA_REDIRECT_FILE"
rm -r /etc/phpmyadmin
if [ "$GET_INFO" == true ]; then
if [ -f "$INFORMATIONS/user.txt" ]; then
mysql -u root -p"$PASSWORD" -e "DROP USER '${USERNAME}'@'%';"
rm -r "$INFORMATIONS/user.txt"
fi
mysql -u root -p"$PASSWORD" -e "DROP USER 'pma'@'127.0.0.1';"
mysql -u root -p"$PASSWORD" -e "DROP DATABASE phpmyadmin;"
elif [ "$GET_INFO" == false ]; then
if [ -f "$INFORMATIONS/user.txt" ]; then
mysql -u root -e "DROP USER '${USERNAME}'@'%';"
rm -r "$INFORMATIONS/user.txt"
fi
mysql -u root -e "DROP USER 'pma'@'127.0.0.1';"
mysql -u root -e "DROP DATABASE phpmyadmin;"
fi
rm -r "$INFORMATIONS"
fi
# ADDON PMA_BUTTON_DATABASE_TAB #
# ADDON MC_PASTE #
if [ -f "$MC_PASTE" ]; then
rm -r "$MC_PASTE"
rm -r "$PTERO/app/Http/Controllers/Admin/MCPasteController.php"
rm -r "$PTERO/app/Http/Controllers/Api/Client/Servers/MCPasteController.php"
rm -r "$PTERO/app/Http/Requests/Admin/MCPasteFormRequest.php"
rm -r "$PTERO/app/Http/Requests/Api/Client/Servers/ShareLogRequest.php"
rm -r "$PTERO/app/Models/MCPasteVariable.php"
rm -r "$PTERO/patches"
rm -r "$PTERO/resources/scripts/api/server/shareServerLog.ts"
rm -r "$PTERO/resources/scripts/components/server/McPaste.tsx"
rm -r "$PTERO/resources/views/admin/mcpaste"
if [ "$GET_INFO" == true ]; then
mysql -u root -p"$PASSWORD" -e "USE panel;DROP TABLE mcpaste_variables;"
elif [ "$GET_INFO" == false ]; then
mysql -u root -e "USE panel;DROP TABLE mcpaste_variables;"
fi
rm -r "$INFORMATIONS"
fi
# ADDON MC_PASTE #
# ADDON FILES_IN_EDITOR #
if [ -f "$FILES_IN_EDITOR" ]; then
rm -r "$FILES_IN_EDITOR"
fi
# ADDON FILES_IN_EDITOR #
}
# Restore Backup #
restore() {
print "Checking for a backup..."
if [ -d "$PTERO/PanelBackup[Auto-Addons]" ]; then
cd "$PTERO/PanelBackup[Auto-Addons]"
tar -xzvf "$PTERO/PanelBackup[Auto-Addons]/PanelBackup[Auto-Addons].tar.gz"
rm -r "$PTERO/PanelBackup[Auto-Addons]/PanelBackup[Auto-Addons].tar.gz"
cp -r -- * .env "$PTERO"
rm -rf "$PTERO/PanelBackup[Auto-Addons]"
else
print_error "There was no backup to restore, Aborting..."
exit 1
fi
}
bye() {
print_brake 50
echo
echo -e "* ${GREEN}Backup restored successfully!"
echo -e "* Thank you for using this script."
echo -e "* Support group: ${YELLOW}$(hyperlink "$SUPPORT_LINK")${RESET}"
echo
print_brake 50
}
# Define Permissions #
permissions() {
if id "www-data" &>/dev/null; then
chown -R www-data:www-data "$PTERO"/*
elif id "nginx" &>/dev/null; then
chown -R nginx:nginx "$PTERO"/*
elif id "apache" &>/dev/null; then
chown -R apache:apache "$PTERO"/*
else
print_warning "The correct permissions could not be set. Contact the script author."
fi
}
# Exec Script #
find_pterodactyl
if [ "$PTERO_INSTALL" == true ]; then
print "Installation of the panel found, continuing the backup..."
delete_files
restore
permissions
bye
elif [ "$PTERO_INSTALL" == false ]; then
print_error "The installation of your panel could not be located."
print "Trying to use the custom directory..."
sleep 2
PTERO=$CUSTOM_DIRECTORY
update_variables
delete_files
restore
permissions
bye
fi