forked from cmangos/classic-db
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallFullDB.sh
executable file
·374 lines (340 loc) · 9.32 KB
/
InstallFullDB.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
#!/bin/bash
####################################################################################################
#
# Simple helper script to insert clean Classic-DB
#
####################################################################################################
# need to be changed on each official DB/CORE release
FULLDB_FILE="ClassicDB_1_11_z2757.sql"
DB_TITLE="v1.11 'Into the Frozen Heart of Naxxramas'"
NEXT_MILESTONES="0.19 0.20"
#internal use
SCRIPT_FILE="InstallFullDB.sh"
CONFIG_FILE="InstallFullDB.config"
# testing only
ADDITIONAL_PATH=""
#variables assigned and read from $CONFIG_FILE
DB_HOST="localhost"
DB_PORT="3306"
DATABASE=""
USERNAME=""
PASSWORD=""
MYSQL=""
CORE_PATH=""
DEV_UPDATES="NO"
FORCE_WAIT="YES"
function create_config {
# Re(create) config file
cat > $CONFIG_FILE << EOF
####################################################################################################
# This is the config file for the '$SCRIPT_FILE' script
#
# You need to insert
# DB_HOST: Host on which the database resides
# DB_PORT: Port on which the database is running
# DATABASE: Your database
# USERNAME: Your username
# PASSWORD: Your password
# CORE_PATH: Your path to core's directory (OPTIONAL: Use if you want to apply remaining core updates automatically)
# MYSQL: Your mysql command (usually mysql)
#
####################################################################################################
## Define the host on which the mangos database resides (typically localhost)
DB_HOST="localhost"
## Define the port on which the mangos database is running (typically 3306)
DB_PORT="3306"
## Define the database in which you want to add clean Classic-DB
DATABASE="classicmangos"
## Define your username
USERNAME="mangos"
## Define your password (It is suggested to restrict read access to this file!)
PASSWORD="mangos"
## Define the path to your core's folder (This is optional)
## If set the core updates located under sql/updates from this mangos-directory will be added automatically
CORE_PATH=""
## Define your mysql programm if this differs
MYSQL="mysql"
## Define if you want to wait a bit before applying the full database
FORCE_WAIT="YES"
## Define if the 'dev' directory for processing development SQL files needs to be used
## Set the variable to "YES" to use the dev directory
DEV_UPDATES="NO"
# Enjoy using the tool
EOF
}
function display_help {
echo
echo "Welcome to the Classic-DB helper $SCRIPT_FILE"
echo
echo "Run this tool from a bash compatible terminal (on windows like Git Bash)"
echo
echo "To configure edit the file $CONFIG_FILE"
echo
}
# Check if config file present
if [ ! -f $CONFIG_FILE ]
then
create_config
display_help
exit 1
fi
. $CONFIG_FILE
export MYSQL_PWD="$PASSWORD"
MYSQL_COMMAND="$MYSQL -h$DB_HOST -P$DB_PORT -u$USERNAME $DATABASE"
## Print header
echo
echo "Welcome to the Classic-DB helper $SCRIPT_FILE"
echo
if [ "$FORCE_WAIT" != "NO" ]
then
echo "ATTENTION: Your database $DATABASE will be reset to Classic-DB!"
echo "Please bring your repositories up-to-date!"
echo "Press CTRL+C to exit"
# show a mini progress bar
for i in {1..10}
do
echo -ne .
sleep 1
done
echo .
fi
## Full Database
echo "> Processing Classic database $DB_TITLE."
$MYSQL_COMMAND < "${ADDITIONAL_PATH}Full_DB/$FULLDB_FILE"
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply ${ADDITIONAL_PATH}Full_DB/$FULLDB_FILE"
exit 1
fi
echo " $DB_TITLE is applied!"
echo
echo
## Updates
echo "> Processing database updates ..."
COUNT=0
for UPDATE in "${ADDITIONAL_PATH}Updates/"[0-9]*.sql
do
if [ -e "$UPDATE" ]
then
echo " Appending $UPDATE"
$MYSQL_COMMAND < "$UPDATE"
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply $UPDATE"
exit 1
fi
((COUNT++))
fi
done
if [ "$COUNT" != 0 ]
then
echo " $COUNT DB updates applied successfully"
else
echo " Did not found any new DB update to apply"
fi
echo
echo
#
# Core updates
#
echo "> Trying to retrieve last core update packaged in database ..."
LAST_CORE_REV=0
CORE_REVS="$(grep -r "^.*required_z[0-9]*.* DEFAULT NULL" ${ADDITIONAL_PATH}Full_DB/* | sed 's/.*required_z\([0-9]*\).*/\1/') "
CORE_REVS+=$(grep -ri '.*alter table.*required_z' ${ADDITIONAL_PATH}Updates/* | sed 's/.*required_z\([0-9]*\).*required_z\([0-9]*\).*/\1 \2/')
if [ "$CORE_REVS" != "" ]
then
for rev in $CORE_REVS
do
if [ "$rev" -gt "$LAST_CORE_REV" ]
then
LAST_CORE_REV=$rev
fi
done
fi
if [ "$LAST_CORE_REV" -eq "0" ]
then
echo "ERROR: cannot get last core revision in DB"
exit 1
else
echo " Found last core revision in DB is $LAST_CORE_REV"
fi
echo
echo
# process future release folders
if [ "$CORE_PATH" != "" ]
then
if [ ! -e $CORE_PATH ]
then
echo "Path to core provided, but directory not found! $CORE_PATH"
exit 1
fi
UPD_PROCESSED=0
UPD_FOUND=0
for NEXT_MILESTONE in ${NEXT_MILESTONES};
do
# A new milestone was released, apply additional updates
if [ -e ${CORE_PATH}/sql/updates/${NEXT_MILESTONE}/ ]
then
echo "> Trying to apply core updates from milestone $NEXT_MILESTONE ..."
for f in "${CORE_PATH}/sql/archives/${NEXT_MILESTONE}/z*_*_mangos_*.sql"
do
CUR_REV=`basename $f | sed 's/^\z\([0-9]*\)_.*/\1/' `
if [ "$CUR_REV" -gt "$LAST_CORE_REV" ]
then
# found a newer core update file
echo " Appending core update `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply $f"
exit 1
fi
((UPD_PROCESSED++))
else
((UPD_FOUND++))
fi
done
fi
done
# Apply remaining files from main folder
echo "> Trying to apply additional core updates from path $CORE_PATH ..."
for f in "$CORE_PATH/sql/updates/mangos/"*_mangos_*.sql
do
CUR_REV=$( echo $(basename "$f") | sed 's/^\z\([0-9]*\).*/\1/' )
if [ "$CUR_REV" -gt "$LAST_CORE_REV" ]
then
# found a newer core update file
echo " Appending core update `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply $f"
exit 1
fi
((UPD_PROCESSED++))
else
((UPD_FOUND++))
fi
done
echo " CORE UPDATE PROCESSED: $UPD_PROCESSED"
echo " CORE UPDATE FOUND BUT ALREADY IN DB: $UPD_FOUND"
echo
echo
# Apply dbc folder
echo "> Trying to apply $CORE_PATH/sql/base/dbc/original_data ..."
for f in "$CORE_PATH/sql/base/dbc/original_data/"*.sql
do
echo " Appending DBC file update `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply $f"
exit 1
fi
done
echo " DBC data successfully applied"
echo
echo
# Apply dbc changes (specific fixes to known wrong/missing data)
echo "> Trying to apply $CORE_PATH/sql/base/dbc/cmangos_fixes ..."
for f in "$CORE_PATH/sql/base/dbc/cmangos_fixes/"*.sql
do
echo " Appending CMaNGOS DBC file fixes `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply $f"
exit 1
fi
done
echo " DBC changes successfully applied"
echo
echo
# Apply ScriptDev2 data
echo "> Trying to apply $CORE_PATH/sql/scriptdev2 ..."
for f in "$CORE_PATH/sql/scriptdev2/"*.sql
do
echo " Appending SD2 file update `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply $f"
exit 1
fi
done
echo " ScriptDev2 data successfully applied"
echo
echo
fi
#
# ACID Full file
#
# Apply acid_classic.sql
echo "> Trying to apply ${ADDITIONAL_PATH}ACID/acid_classic.sql ..."
$MYSQL_COMMAND < ${ADDITIONAL_PATH}ACID/acid_classic.sql
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply ${ADDITIONAL_PATH}ACID/acid_classic.sql"
exit 1
fi
echo " ACID successfully applied"
echo
echo
#
# CMaNGOS custom updates file
#
# Apply cmangos_custom.sql
echo "> Trying to apply ${ADDITIONAL_PATH}utilities/cmangos_custom.sql ..."
$MYSQL_COMMAND < ${ADDITIONAL_PATH}utilities/cmangos_custom.sql
if [[ $? != 0 ]]
then
echo "ERROR: cannot apply ${ADDITIONAL_PATH}utilities/cmangos_custom.sql"
exit 1
fi
echo " CMaNGOS custom updates successfully applied"
echo
echo
#
# DEVELOPERS UPDATES
#
if [ "$DEV_UPDATES" == "YES" ]
then
echo "> Trying to apply development updates ..."
for UPDATEFILE in ${ADDITIONAL_PATH}dev/*.sql
do
if [ -e "$UPDATEFILE" ]
then
for UPDATE in ${ADDITIONAL_PATH}dev/*.sql
do
echo " process update $UPDATE"
$MYSQL_COMMAND < $UPDATE
[[ $? != 0 ]] && exit 1
done
echo " Development updates applied"
else
echo " No development update to process"
fi
break
done
for UPDATEFILE in ${ADDITIONAL_PATH}dev/*/*.sql
do
if [ -e "$UPDATEFILE" ]
then
for UPDATE in ${ADDITIONAL_PATH}dev/*/*.sql
do
echo " process update $UPDATE"
$MYSQL_COMMAND < $UPDATE
[[ $? != 0 ]] && exit 1
done
echo " Development subupdates applied"
else
echo " No development subupdate to process"
fi
break
done
echo
echo
fi
echo "You have now a clean and recent Classic-DB database loaded into $DATABASE"
echo "Enjoy using Classic-DB"
echo