-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatabase_installer.sh
498 lines (474 loc) · 13.3 KB
/
database_installer.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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/bin/bash
############################################
## WARNING! WARNING! WARNING! WARNING! ##
## ##
## DON'T USE NOTEPAD TO CHANGE THIS FILE ##
## INSTEAD USE SOME DECENT TEXT EDITOR. ##
## NEWLINE CHARACTERS DIFFER BETWEEN DOS/ ##
## WINDOWS AND UNIX. ##
## ##
## USING NOTEPAD TO SAVE THIS FILE WILL ##
## LEAVE IT IN A BROKEN STATE!!! ##
############################################
## Writen by DrLecter ##
## License: GNU GPL ##
## Based on Tiago Tagliaferri's script ##
## E-mail: tiago_tagliaferri@msn.com ##
## From "L2J-DataPack" ##
## Bug reports: http://trac.l2jdp.com/ ##
############################################
trap finish 2
configure() {
echo "#############################################"
echo "# You entered script configuration area #"
echo "# No change will be performed in your DB #"
echo "# I will just ask you some questions about #"
echo "# your hosts and DB. #"
echo "#############################################"
MYSQLDUMPPATH=`which -a mysqldump 2>/dev/null`
MYSQLPATH=`which -a mysql 2>/dev/null`
if [ $? -ne 0 ]; then
echo "We were unable to find MySQL binaries on your path"
while :
do
echo -ne "\nPlease enter MySQL binaries directory (no trailing slash): "
read MYSQLBINPATH
if [ -e "$MYSQLBINPATH" ] && [ -d "$MYSQLBINPATH" ] && \
[ -e "$MYSQLBINPATH/mysqldump" ] && [ -e "$MYSQLBINPATH/mysql" ]; then
MYSQLDUMPPATH="$MYSQLBINPATH/mysqldump"
MYSQLPATH="$MYSQLBINPATH/mysql"
break
else
echo "The data you entered is invalid. Please verify and try again."
exit 1
fi
done
fi
#LS
echo -ne "\nPlease enter MySQL Login Server hostname (default localhost): "
read LSDBHOST
if [ -z "$LSDBHOST" ]; then
LSDBHOST="localhost"
fi
echo -ne "\nPlease enter MySQL Login Server database name (default l2jls): "
read LSDB
if [ -z "$LSDB" ]; then
LSDB="l2jls"
fi
echo -ne "\nPlease enter MySQL Login Server user (default root): "
read LSUSER
if [ -z "$LSUSER" ]; then
LSUSER="root"
fi
echo -ne "\nPlease enter MySQL Login Server $LSUSER's password (won't be displayed) :"
stty -echo
read LSPASS
stty echo
echo ""
if [ -z "$LSPASS" ]; then
echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
elif [ "$LSUSER" == "$LSPASS" ]; then
echo "You're not too brilliant choosing passwords huh?"
fi
#CB
echo -ne "\nPlease enter MySQL Community Server hostname (default localhost): "
read CBDBHOST
if [ -z "$CBDBHOST" ]; then
CBDBHOST="localhost"
fi
echo -ne "\nPlease enter MySQL Community Server database name (default l2jcs): "
read CBDB
if [ -z "$CBDB" ]; then
CBDB="l2jcs"
fi
echo -ne "\nPlease enter MySQL Community Server user (default root): "
read CBUSER
if [ -z "$CBUSER" ]; then
CBUSER="root"
fi
echo -ne "\nPlease enter MySQL Community Server $CBUSER's password (won't be displayed) :"
stty -echo
read CBPASS
stty echo
echo ""
if [ -z "$CBPASS" ]; then
echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
elif [ "$CBUSER" == "$CBPASS" ]; then
echo "You're not too brilliant choosing passwords huh?"
fi
#GS
echo -ne "\nPlease enter MySQL Game Server hostname (default $LSDBHOST): "
read GSDBHOST
if [ -z "$GSDBHOST" ]; then
GSDBHOST="localhost"
fi
echo -ne "\nPlease enter MySQL Game Server database name (default l2jgs): "
read GSDB
if [ -z "$GSDB" ]; then
GSDB="l2jgs"
fi
echo -ne "\nPlease enter MySQL Game Server user (default $LSUSER): "
read GSUSER
if [ -z "$GSUSER" ]; then
GSUSER="root"
fi
echo -ne "\nPlease enter MySQL Game Server $GSUSER's password (won't be displayed): "
stty -echo
read GSPASS
stty echo
echo ""
if [ -z "$GSPASS" ]; then
echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords"
elif [ "$GSUSER" == "$GSPASS" ]; then
echo "You're not too brilliant choosing passwords huh?"
fi
save_config $1
}
save_config() {
if [ -n "$1" ]; then
CONF="$1"
else
CONF="database_installer.rc"
fi
echo ""
echo "With these data I can generate a configuration file which can be read"
echo "on future updates. WARNING: this file will contain clear text passwords!"
echo -ne "Shall I generate config file $CONF? (Y/n):"
read SAVE
if [ "$SAVE" == "y" -o "$SAVE" == "Y" -o "$SAVE" == "" ];then
cat <<EOF>$CONF
#Configuration settings for L2J-Datapack database installer script
MYSQLDUMPPATH=$MYSQLDUMPPATH
MYSQLPATH=$MYSQLPATH
LSDBHOST=$LSDBHOST
LSDB=$LSDB
LSUSER=$LSUSER
LSPASS=$LSPASS
CBDBHOST=$CBDBHOST
CBDB=$CBDB
CBUSER=$CBUSER
CBPASS=$CBPASS
GSDBHOST=$GSDBHOST
GSDB=$GSDB
GSUSER=$GSUSER
GSPASS=$GSPASS
EOF
chmod 600 $CONF
echo "Configuration saved as $CONF"
echo "Permissions changed to 600 (rw- --- ---)"
elif [ "$SAVE" != "n" -a "$SAVE" != "N" ]; then
save_config
fi
}
load_config() {
if [ -n "$1" ]; then
CONF="$1"
else
CONF="database_installer.rc"
fi
if [ -e "$CONF" ] && [ -f "$CONF" ]; then
. $CONF
else
echo "Settings file not found: $CONF"
echo "You can specify an alternate settings filename:"
echo $0 config_filename
echo ""
echo "If file doesn't exist it can be created"
echo "If nothing is specified script will try to work with ./database_installer.rc"
echo ""
configure $CONF
fi
}
asklogin(){
clear
echo "#############################################"
echo "# WARNING: This section of the script CAN #"
echo "# destroy your characters and accounts #"
echo "# information. Read questions carefully #"
echo "# before you reply. #"
echo "#############################################"
echo ""
echo "Choose full (f) if you don't have and 'accounts' table or would"
echo "prefer to erase the existing accounts information."
echo "Choose skip (s) to skip loginserver DB installation and go to"
echo "communityserver DB installation/upgrade."
echo -ne "LOGINSERVER DB install type: (f) full, (s) skip or (q) quit? "
read LOGINPROMPT
case "$LOGINPROMPT" in
"f"|"F") logininstall; loginupgrade; cbbackup; askcbtype;;
"s"|"S") cbbackup; askcbtype;;
"q"|"Q") finish;;
*) asklogin;;
esac
}
logininstall(){
echo "Deleting loginserver tables for new content."
$MYL < ls_cleanup.sql
}
loginupgrade(){
clear
echo "Installling new loginserver content."
for login in $(ls ../sql/login/*.sql);do
echo "Installing loginserver table : $login"
$MYL < $login
done
}
gsbackup(){
while :
do
echo ""
echo -ne "Do you want to make a backup copy of your GSDB? (y/n): "
read LSB
if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
echo "Making a backup of the original gameserver database."
$MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > gs_backup.sql
if [ $? -ne 0 ];then
clear
echo ""
echo "There was a problem accesing your GS database, either it wasnt created or authentication data is incorrect."
exit 1
fi
break
elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
break
fi
done
}
cbbackup(){
while :
do
clear
echo ""
echo -ne "Do you want to make a backup copy of your CBDB? (y/n): "
read LSB
if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
echo "Making a backup of the original communityserver database."
$MYSQLDUMPPATH --add-drop-table -h $CBDBHOST -u $CBUSER --password=$CBPASS $CBDB > cs_backup.sql
if [ $? -ne 0 ];then
clear
echo ""
echo "There was a problem accesing your CB database, either it wasnt created or authentication data is incorrect."
exit 1
fi
break
elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
break
fi
done
}
lsbackup(){
while :
do
clear
echo ""
echo -ne "Do you want to make a backup copy of your LSDB? (y/n): "
read LSB
if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
echo "Making a backup of the original loginserver database."
$MYSQLDUMPPATH --add-drop-table -h $LSDBHOST -u $LSUSER --password=$LSPASS $LSDB > ls_backup.sql
if [ $? -ne 0 ];then
clear
echo ""
echo "There was a problem accesing your LS database, either it wasnt created or authentication data is incorrect."
exit 1
fi
break
elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then
break
fi
done
}
asktype(){
echo ""
echo ""
echo "WARNING: A full install (f) will destroy all existing character data."
echo -ne "GAMESERVER DB install type: (f) full install, (u) upgrade, (s) skip or (q) quit? "
read INSTALLTYPE
case "$INSTALLTYPE" in
"f"|"F") fullinstall; upgradeinstall I; custom;;
"u"|"U") upgradeinstall U; custom;;
"s"|"S") custom;;
"q"|"Q") finish;;
*) asktype;;
esac
}
askcbtype(){
clear
echo ""
echo ""
echo "WARNING: A full install (f) will destroy all existing community data."
echo -ne "COMMUNITYSERVER DB install type: (f) full install, (u) upgrade, (s) skip or (q) quit? "
read INSTALLTYPE
case "$INSTALLTYPE" in
"f"|"F") fullcbinstall; upgradecbinstall I; gsbackup; asktype;;
"u"|"U") upgradecbinstall U; gsbackup; asktype;;
"s"|"S") gsbackup; asktype;;
"q"|"Q") finish;;
*) asktype;;
esac
}
fullcbinstall(){
echo "Deleting all communityserver tables for new content."
$MYC < cs_cleanup.sql
}
upgradecbinstall(){
clear
if [ "$1" == "I" ]; then
echo "Installling new communityserver content."
else
echo "Upgrading communityserver content"
fi
if [ "$1" == "I" ]; then
for cb in $(ls ../cb_sql/*.sql);do
echo "Installing Community Board table : $cb"
$MYC < $cb
done
fi
newbie_helper_cb
}
fullinstall(){
clear
echo "Deleting all gameserver tables for new content."
$MYG < gs_cleanup.sql
}
upgradeinstall(){
clear
if [ "$1" == "I" ]; then
echo "Installling new gameserver content."
else
echo "Upgrading gameserver content"
fi
for gs in $(ls ../sql/server/*.sql);do
echo "Installing GameServer table : $gs"
$MYG < $gs
done
newbie_helper
}
custom(){
echo ""
echo ""
echo -ne "Install custom gameserver DB tables: (y) yes or (n) no or (q) quit?"
read ASKCS
case "$ASKCS" in
"y"|"Y") cstinstall;;
"n"|"N") finish;;
"q"|"Q") finish;;
*) custom;;
esac
finish
}
cstinstall(){
while :
do
clear
echo ""
echo -ne "Do you want to make another backup of GSDB before applying custom contents? (y/N): "
read LSB
if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then
echo "Making a backup of the default gameserver tables."
$MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > custom_backup.sql 2> /dev/null
if [ $? -ne 0 ];then
echo ""
echo "There was a problem accesing your GS database, server down?."
exit 1
fi
break
elif [ "$LSB" == "n" -o "$LSB" == "N" -o "$LSB" == "" ]; then
break
fi
done
clear
echo "Installing custom content."
for custom in $(ls ../sql/server/custom/*.sql);do
echo "Installing custom table: $custom"
$MYG < $custom
done
# L2J mods that needed extra tables to work properly, should be
# listed here. To do so copy & paste the following 6 lines and
# change them properly:
# MOD: Wedding.
echo -ne "Install "Wedding Mod" tables? (y/N): "
read modprompt
if [ "$modprompt" == "y" -o "$modprompt" == "Y" ]; then
for mod in $(ls ../sql/server/mods/*.sql);do
echo "Installing custom mod table : $mod"
$MYG < $mod
done
fi
finish
}
finish(){
clear
echo "Script execution finished."
echo ""
echo "L2JDP database_installer version 0.2.2"
echo "(C) 2007-2011 L2J Datapack Team"
echo "database_installer comes with ABSOLUTELY NO WARRANTY;"
echo "This is free software, and you are welcome to redistribute it"
echo "under certain conditions; See the file gpl.txt for further"
echo "details."
echo ""
echo "Thanks for using our software."
echo "visit http://www.l2jdp.com for more info about"
echo "the L2J Datapack project."
exit 0
}
newbie_helper(){
while :
do
echo ""
echo -ne "If you're not that skilled applying changes within 'updates' folder, i can try to do it for you (y). If you wish to do it on your own, choose (n). Should i parse updates files? (Y/n)"
read NOB
if [ "$NOB" == "Y" -o "$NOB" == "y" -o "$NOB" == "" ]; then
clear
echo ""
echo "There we go, it may take some time..."
echo "Installing Gameserver Updates"
for file in $(ls ../sql/server/updates/*.sql);do
$MYG < $file 2>> gserror.log
done
echo "Installing Loginserver Updates"
for file in $(ls ../sql/login/updates/*.sql);do
$MYL < $file 2>> lserror.log
done
break
elif [ "$NOB" == "n" -o "$NOB" == "N" ]; then
break
fi
done
}
newbie_helper_cb(){
while :
do
echo ""
echo -ne "If you're not that skilled applying changes within 'updates' folder, i can try to do it for you (y). If you wish to do it on your own, choose (n). Should i parse updates files? (Y/n)"
read NOB
if [ "$NOB" == "Y" -o "$NOB" == "y" -o "$NOB" == "" ]; then
clear
echo ""
echo "There we go, it may take some time..."
echo "updates parser results. Last run: "`date` >cb_database_installer.log
for file in $(ls ../cb_sql/updates/*sql);do
echo $file|cut -d/ -f4 >> cb_database_installer.log
$MYC < $file 2>> cb_database_installer.log
if [ $? -eq 0 ];then
echo "no errors">> cb_database_installer.log
fi
done
clear
echo ""
echo "Log available at $(pwd)/cb_database_installer.log"
echo ""
break
elif [ "$NOB" == "n" -o "$NOB" == "N" ]; then
break
fi
done
}
clear
load_config $1
MYL="$MYSQLPATH -h $LSDBHOST -u $LSUSER --password=$LSPASS -D $LSDB"
MYG="$MYSQLPATH -h $GSDBHOST -u $GSUSER --password=$GSPASS -D $GSDB"
MYC="$MYSQLPATH -h $CBDBHOST -u $CBUSER --password=$CBPASS -D $CBDB"
lsbackup
asklogin