-
Notifications
You must be signed in to change notification settings - Fork 59
/
InstallDatabases.sh
executable file
·453 lines (403 loc) · 10.1 KB
/
InstallDatabases.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
#!/bin/sh
##############################################################################
# This utility assist you in setting up your mangos database. #
# This is a port of InstallDatabases.bat written by Antz for Windows #
# #
##############################################################################
OLDRELEASE="Rel21"
RELEASE="Rel22"
DUMP="NO"
dbname=""
dbcommand=""
createcharDB="YES"
createworldDB="YES"
createrealmDB="YES"
loadcharDB="YES"
loadworldDB="YES"
loadrealmDB="YES"
dbType="POPULATED"
updatecharDB="YES"
updateworldDB="YES"
updaterealmDB="YES"
addRealmList="YES"
svr_def="localhost"
user_def="mangos"
pass_def="mangos"
port_def="3306"
wdb_def="mangos1"
cdb_def="character1"
rdb_def="realmd"
printHelp()
{
printf "Usage: $0 [-s] [-u] [-d] [-h]\n"
printf "\t-s: Run this script in silent mode, only prompt for the database information\n"
printf "\t-u: Run only the updates of the database\n"
printf "\t-d: Dump the database configuration into the home directory of the user\n"
printf "\t-h: Display this help\n"
}
printBanner()
{
clear
printf " # # # # # ### ### #### \n"
printf " ## ## # # ## # # # # # \n"
printf " # # # # # # # # # # ### # # ### \n"
printf " # # # ####### # ## # # # # # \n"
printf " # # # # # # ### ### #### \n"
printf "\n"
printf " Database Setup and World Loader v0.03 \n"
printf " ---------------------------------------------- \n"
printf " Website / Forum / Wiki : https://getmangos.eu \n"
printf " ---------------------------------------------- \n"
printf "\n"
printf "\n"
}
printActivities()
{
printf "\tCharacter Database : \tV - Toggle Create DB (${createcharDB}) \n"
printf "\t\t\t\tC - Toggle Create Structure (${loadcharDB}) \n"
printf "\t\t\t\tB - Apply Character DB updates (${updatecharDB})\n"
printf "\n"
printf "\t World Database : \tE - Toggle Create DB (${createworldDB}) \n"
printf "\t\t\t\tW - Toggle Create Structure (${loadworldDB}) \n"
if [ "${loadworldDB}" = "YES" ]; then
printf "\t\t\t\tD - Toggle World Type (${dbType})\n"
fi
printf "\t\t\t\tU - Apply World DB updates (${updateworldDB})\n"
printf "\n"
printf "\t Realm Database : \tT - Toggle Create DB (${createrealmDB})\n"
printf "\t\t\t\tR - Toggle Create Structure (${loadrealmDB})\n"
printf "\t\t\t\tY - Apply Realm DB updates (${updaterealmDB})\n"
printf "\t\t\t\tL - Toggle Add RealmList Entry (${addRealmList})\n"
printf "\n"
printf "\t\t\t\tN - Next Step\n"
printf "\t\t\t\tX - Exit\n"
}
determineDBName()
{
if [ $(which mariadb) ]; then
printf "MariaDB found.\n"
dbname="MariaDB"
elif [ $(which mysql) ]; then
printf "MySQL found.\n"
dbname="MySQL"
else
printf "Did not find mariadb or mysql.\n"
fi
}
mysqlconfigeditor()
{
dbconfig="mysql_config_editor set --login-path=local --host=${svr} --port=${port} --user=${user} --password --skip-warn"
}
determineDBCommand()
{
if [ $dbname = "MariaDB" ]; then
dbcommand="mariadb -h ${svr} -u ${user} -p${pass} -q -s"
elif [ $dbname = "MySQL" ]; then
dbcommand="mysql --login-path=local -q -s"
else
printf "Did not find mariadb or mysql.\n"
fi
}
createCharDB()
{
printf "Creating Character database ${cdb}\n"
$(${dbcommand} -e "Create database ${cdb}")
if [ "${loadcharDB}" = "YES" ]; then
loadCharDB
fi
}
loadCharDB()
{
printf "Loading data into character database ${cdb}\n"
$(${dbcommand} ${cdb} < Character/Setup/characterLoadDB.sql)
if [ "${updatecharDB}" = "YES" ]; then
updateCharDB
fi
}
updateCharDB()
{
printf "Updating data into the character database ${cdb}\n"
for file in $(ls Character/Updates/${OLDRELEASE}/*.sql | tr ' ' '|' | tr '\n' ' ')
do
file=$(echo ${file} | tr '|' ' ')
printf "Applying update ${file}\n"
${dbcommand} "${cdb}" < "${file}"
printf "File ${file} imported\n"
done
for file in $(ls Character/Updates/${RELEASE}/*.sql | tr ' ' '|' | tr '\n' ' ')
do
file=$(echo ${file} | tr '|' ' ')
printf "Applying update ${file}\n"
${dbcommand} "${cdb}" < "${file}"
printf "File ${file} imported\n"
done
}
createWorldDB()
{
printf "Creating World database ${wdb}\n"
$(${dbcommand} -e "Create database ${wdb}")
if [ "${loadworldDB}" = "YES" ]; then
loadWorldDB
fi
}
loadWorldDB()
{
printf "Loading data into world database ${wdb}\n"
$(${dbcommand} ${wdb} < World/Setup/mangosdLoadDB.sql)
if [ "${dbType}" = "POPULATED" ]; then
populateWorldDB
fi
}
populateWorldDB()
{
printf "Importing World database ${wdb}\n"
for file in $(ls World/Setup/FullDB/${OLDRELEASE}/*.sql | tr ' ' '|' | tr '\n' ' ')
do
file=$(echo ${file} | tr '|' ' ')
printf "Importing file ${file}\n"
$(${dbcommand} ${wdb} < ${file})
printf "File ${file} imported\n"
done
for file in $(ls World/Setup/FullDB/*.sql | tr ' ' '|' | tr '\n' ' ')
do
file=$(echo ${file} | tr '|' ' ')
printf "Importing file ${file}\n"
$(${dbcommand} ${wdb} < ${file})
printf "File ${file} imported\n"
done
}
updateWorldDB()
{
printf "Updating data into the World database ${wdb}\n"
for file in World/Updates/${OLDRELEASE}/*.sql
do
printf "Applying update ${file}\n"
${dbcommand} "${wdb}" < "${file}"
printf "File ${file} imported\n"
done
for file in World/Updates/${RELEASE}/*.sql
do
printf "Applying update ${file}\n"
${dbcommand} "${wdb}" < "${file}"
printf "File ${file} imported\n"
done
}
createRealmDB()
{
printf "Creating realm database ${rdb}\n"
$(${dbcommand} -e "Create database ${rdb}")
if [ "${loadrealmDB}" = "YES" ]; then
loadRealmDB
fi
}
loadRealmDB()
{
printf "Loading data into realm database ${rdb}\n"
$(${dbcommand} ${rdb} < Realm/Setup/realmdLoadDB.sql)
}
updateRealmDB()
{
printf "Updating data into the Realm database ${rdb}\n"
for file in $(ls Realm/Updates/${OLDRELEASE}/*.sql | tr ' ' '|' | tr '\n' ' ')
do
file=$(echo ${file} | tr '|' ' ')
printf "Applying update ${file}\n"
$(${dbcommand} ${rdb} < ${file})
printf "File ${file} imported\n"
done
for file in $(ls Realm/Updates/${RELEASE}/*.sql | tr ' ' '|' | tr '\n' ' ')
do
file=$(echo ${file} | tr '|' ' ')
printf "Applying update ${file}\n"
$(${dbcommand} ${rdb} < ${file})
printf "File ${file} imported\n"
done
}
addRealmList()
{
printf "Adding realm list entries\n"
$(${dbcommand} ${rdb} < Tools/updateRealm.sql)
}
activity=""
while getopts "suh" o; do
case "${o}" in
s)
activity="N"
printf "You selected silent mode\n"
;;
u)
createcharDB="NO"
createworldDB="NO"
createrealmDB="NO"
loadcharDB="NO"
loadworldDB="NO"
loadrealmDB="NO"
dbType="EMPTY"
printf "You selected update only\n"
;;
d)
DUMP="YES"
;;
h)
printHelp
exit 0
;;
esac
done
while [ -z "${activity}" ] || [ "${activity}" != "N" ]
do
printBanner
printActivities
printf "Please select an activity : "
read activity
activity=$(echo ${activity} | tr '[:lower:]' '[:upper:]' )
case ${activity} in
"V")
if [ "${createcharDB}" = "YES" ]; then
createcharDB="NO"
else
createcharDB="YES"
fi
;;
"C")
if [ "${loadcharDB}" = "YES" ]; then
loadcharDB="NO"
else
loadcharDB="YES"
fi
;;
"B")
if [ "${updatecharDB}" = "YES" ]; then
updatecharDB="NO"
else
updatecharDB="YES"
fi
;;
"E")
if [ "${createworldDB}" = "YES" ]; then
createworldDB="NO"
else
createworldDB="YES"
fi
;;
"W")
if [ "${loadworldDB}" = "YES" ]; then
loadworldDB="NO"
else
loadworldDB="YES"
fi
;;
"D")
if [ "${dbType}" = "POPULATED" ]; then
dbType="EMPTY"
else
dbType="POPULATED"
fi
;;
"U")
if [ "${updateworldDB}" = "YES" ]; then
updateworldDB="NO"
else
updateworldDB="YES"
fi
;;
"T")
if [ "${createrealmDB}" = "YES" ]; then
createrealmDB="NO"
else
createrealmDB="YES"
fi
;;
"R")
if [ "${loadrealmDB}" = "YES" ]; then
loadrealmDB="NO"
else
loadrealmDB="YES"
fi
;;
"Y")
if [ "${updaterealmDB}" = "YES" ]; then
updaterealmDB="NO"
else
updaterealmDB="YES"
fi
;;
"L")
if [ "${addRealmList}" = "YES" ]; then
addRealmList="NO"
else
addRealmList="YES"
fi
;;
"X")
exit 0;;
*)
printf "Invalid selection";;
esac
done
printBanner
determineDBName
printf "What is your ${dbname} host name ?\t[${svr_def}]: "
read svr
svr=${svr:-${svr_def}}
printf "What is your ${dbname} user name ?\t[${user_def}]: "
read user
user=${user:-${user_def}}
printf "What is your ${dbname} port ?\t[${port_def}]: "
read port
port=${port:-${port_def}}
if [ $dbname = "MariaDB" ]; then
printf "What is your ${dbname} password ?\t []: "
read pass
pass=${pass:-${pass_def}}
elif [ $dbname = "MySQL" ]; then
mysqlconfigeditor
$dbconfig
fi
determineDBCommand
if [ "${DUMP}" = "YES" ]; then
printf "Enter it again \t[]: "
read pass
fi
if [ "${createcharDB}" = "YES" ] || [ "${loadcharDB}" = "YES" ] || [ "${updatecharDB}" = "YES" ]; then
printf "What is your Character database name ?\t[${cdb_def}]: "
read cdb
cdb=${cdb:-${cdb_def}}
fi
if [ "${createworldDB}" = "YES" ] || [ "${loadworldDB}" = "YES" ] || [ "${updateworldDB}" = "YES" ]; then
printf "What is your World database name ?\t[${wdb_def}]: "
read wdb
wdb=${wdb:-${wdb_def}}
fi
if [ "${createrealmDB}" = "YES" ] || [ "${loadrealmDB}" = "YES" ] || [ "${updaterealmDB}" = "YES" ] || [ "${addRealmList}" = "YES" ]; then
printf "What is your Realm database name ?\t[${rdb_def}]: "
read rdb
rdb=${rdb:-${rdb_def}}
fi
if [ "${createcharDB}" = "YES" ]; then
createCharDB
fi
if [ "${createworldDB}" = "YES" ]; then
createWorldDB
fi
if [ "${createrealmDB}" = "YES" ]; then
createRealmDB
fi
if [ "${updateworldDB}" = "YES" ]; then
updateWorldDB
fi
if [ "${updaterealmDB}" = "YES" ]; then
updateRealmDB
fi
if [ "${addRealmList}" = "YES" ]; then
addRealmList
fi
if [ "${DUMP}" = "YES" ]; then
printf "Dumping database information...\n"
echo "${svr};${port};${user};${pass};${rdb}" > ~/db.conf
echo "${svr};${port};${user};${pass};${wdb}" >> ~/db.conf
echo "${svr};${port};${user};${pass};${cdb}" >> ~/db.conf
fi
printBanner
printf "Database creation and load complete :-)\n"
printf "\n"