forked from classicdb/database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallFullDB.sh
executable file
·248 lines (218 loc) · 6.72 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
#!/bin/bash
####################################################################################################
#
# Simple helper script to insert clean classic DB
#
####################################################################################################
#internal use
SCRIPT_FILE="InstallFullDB.sh"
CONFIG_FILE="InstallFullDB.config"
# testing only
ADDITIONAL_PATH=""
#variables assigned and read from $CONFIG_FILE
DATABASE=""
USERNAME=""
PASSWORD=""
MYSQL=""
CORE_PATH=""
SD2_UPDATES="1"
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
# 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)
# ACID_PATH: Your path to a git-clone of ACID (OPTIONAL: Use it if you want to install recent downloaded acid)
# SD2_UPDATES: If you want to disable adding ScriptDev2 updates (Has only meaning if CORE_PATH above is set
# MYSQL: Your mysql command (usually mysql)
#
####################################################################################################
## Define the database in which you want to add clean classic DB
DATABASE="mangos"
## 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 the path to the folder into which you cloned ACID (This is optional)
## If set the file acid_classic.sql will be applied from this folder
ACID_PATH=""
## Include ScriptDev2 updates? (If set, the SD2-Updates are expected to be located in the place defined at CORE_PATH)
## NOTE: They are only applied if CORE_PATH is set!
## Set to 0 if you want core updates BUT no SD2-updates
SD2_UPDATES="1"
## Define your mysql programm if this differs
MYSQL="mysql"
# 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
MYSQL_COMMAND="$MYSQL -u$USERNAME -p$PASSWORD $DATABASE"
## Print header
echo
echo "Welcome to the classic DB helper $SCRIPT_FILE"
echo
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..19}
do
echo -ne .
sleep 1
done
echo .
## Full Database
echo "Process classic database v1.3"
$MYSQL_COMMAND < ${ADDITIONAL_PATH}Full_DB/ClassicDB_1_3_z2436.sql
[[ $? != 0 ]] && exit 1
## Updates
echo "Process database updates"
if [ ! -e ${ADDITIONAL_PATH}updates/[0-9]*.sql ]
then
echo " No update to process"
else
for UPDATE in ${ADDITIONAL_PATH}updates/[0-9]*.sql
do
echo " process update $UPDATE"
$MYSQL_COMMAND < $UPDATE
[[ $? != 0 ]] && exit 1
done
echo "Updates applied"
fi
LAST_CORE_REV="2436"
LAST_SD2_REV="2689"
# process future release folders
NEXT_MILESTONES="0.12.3 0.12.4"
NEXT_SD2_MILESTONES="0.8 0.9"
if [ "$CORE_PATH" != "" ]
then
if [ ! -e $CORE_PATH ]
then
echo "Path to core provided, but directory not found! $CORE_PATH"
exit 1
fi
#
# Core updates
#
echo
echo
echo "Applying additional core updates from path $CORE_PATH"
echo
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 "Apply core updates from milestone $NEXT_MILESTONE"
for f in ${CORE_PATH}/sql/updates/${NEXT_MILESTONE}/z*_*_*_*_mangos_*.sql
do
CUR_REV=`basename $f | sed 's/^\([0-9]*\)_.*/\1/' `
if [ "$CUR_REV" -gt "$LAST_CORE_REV" ]
then
# found a newer core update file
echo "Append core update `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
[[ $? != 0 ]] && exit 1
fi
done
fi
done
# Apply remaining files from main folder
for f in $CORE_PATH/sql/updates/*_*_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 "Append core update `basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
[[ $? != 0 ]] && exit 1
fi
done
echo "All core updates applied"
#
# ScriptDev2 updates
#
echo
echo "Applying additional ScriptDev2 updates from path $CORE_PATH/src/bindings/ScriptDev2"
echo
for NEXT_SD2_MILESTONE in ${NEXT_SD_MILESTONES}
do
# A new milestone was released, apply additional updates
if [ -e ${CORE_PATH}/src/bindings/ScriptDev2/sql/updates/${NEXT_SD2_MILESTONE}/ ]
then
echo "Apply SD2 updates from milestone $NEXT_SD2_MILESTONE"
for f in ${CORE_PATH}/src/bindings/ScriptDev2/sql/updates/${NEXT_SD2_MILESTONE}/r*_mangos.sql
do
CUR_REV=`basename $f | sed 's/^r\([0-9]*\)_mangos.sql/\1/' `
if [ "$CUR_REV" -gt "$LAST_SD2_REV" ]
then
# found a newer core update file
echo "Append SD2 update`basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
[[ $? != 0 ]] && exit 1
fi
done
fi
done
# Apply remaining files from main folder
for f in $CORE_PATH/src/bindings/ScriptDev2/sql/updates/r*_mangos.sql
do
CUR_REV=`basename $f | sed 's/^r\([0-9]*\)_mangos.sql/\1/' `
if [ "$CUR_REV" -gt "$LAST_SD2_REV" ]
then
# found a newer core update file
echo "Append SD2 update`basename $f` to database $DATABASE"
$MYSQL_COMMAND < $f
[[ $? != 0 ]] && exit 1
fi
done
echo "All SD2 updates applied"
fi
#
# ACID Full file
#
if [ "$ACID_PATH" != "" ]
then
if [ ! -e $ACID_PATH ]
then
echo "Path to acid provided, but directory not found! $ACID_PATH"
exit 1
fi
# Apply acid_classic.sql
echo "Applying $ACID_PATH/acid_classic.sql ..."
$MYSQL_COMMAND < ${ACID_PATH}/acid_classic.sql
[[ $? != 0 ]] && exit 1
echo "Recent state of ACID applied"
fi
echo "Optimize tables"
$MYSQL_COMMAND < ${ADDITIONAL_PATH}utilities/world_optimize.sql
echo "Optimization done"
echo
echo "You have now a clean and recent classic DB database loaded into $DATABASE"
echo "Enjoy using classic DB"
echo