-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·263 lines (221 loc) · 6.19 KB
/
build.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
#!/bin/bash
# Constants.
BASE_DIR=`pwd`
MIN_JAVA_VER=18
LOG_DIR=$BASE_DIR/log
TARGET_DIR=$BASE_DIR/target
declare -a core=(
"maven-parent"
"bukkit-parent"
"type-safe-collections"
)
declare -a primary=(
"mbapi"
"mc-minerap"
"mc-chimera"
)
declare -a secondary=(
"prism"
"block-saver"
"book-dupe"
"dueler"
"pearl-nerf"
"radio"
"insight-jdbc"
"insight-web"
)
# Functions.
install_lib() {
echo "--- Compiling $1"
cd $BASE_DIR/$1/
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to enter directory $1. Check $2 for more info."; exit $rc
fi
mvn clean compile package install >>$2 2>&1
rc=$?
cd $BASE_DIR/
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to compile $1. Check $2 for more info."; exit $rc
fi
if [ -d "$BASE_DIR/$1/target/" ]; then
echo "--- Copying jars to target/ "
cp $BASE_DIR/$1/target/*.jar $TARGET_DIR
fi
echo "--- Compiled successfully"
}
clean() {
echo "--- Removing log/ directory"
rm -rf $LOG_DIR
echo "--- Removing target/ directory"
rm -rf $TARGET_DIR
}
setup() {
# Initial setup.
echo "--- Creating log/ directory"
mkdir -p $LOG_DIR
echo "--- Creating target/ directory"
mkdir -p $TARGET_DIR
}
check_java_executable() {
# Check that Java is present.
if type -p java >/dev/null; then
echo "--- Java executable found in PATH"
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
echo "--- Java executable found in JAVA_HOME"
_java="$JAVA_HOME/bin/java"
else
echo "[ERROR] Java executable not found!"
exit 1
fi
}
# Ensure that the Java version is above the required minimum.
check_java_ver() {
JAVA_VER=$(java -version 2>&1 | sed 's/java version "\(.*\)\.\(.*\)\..*"/\1\2/; 1q')
if [[ "$JAVA_VER" -ge $1 ]]; then
echo "--- Java version is $JAVA_VER"
else
echo "[ERROR] Java version ($JAVA_VER) is less than the minimum: $1"
exit 1
fi
}
# Check that Maven is present.
check_maven() {
if hash mvn >&2; then
echo "--- Found maven"
else
echo "[ERROR] Maven not found!"
exit 1
fi
}
make_group() {
echo
echo "Building MinerAp $1"
looparray="$1[@]"
for lib in "${!looparray}"
do
install_lib $lib $LOG_DIR/$1.log
done
}
main() {
echo "Performing clean..."
clean
echo
echo "Performing initial setup..."
setup
echo
echo "Performing initial checks..."
check_java_executable
check_java_ver $MIN_JAVA_VER
check_maven
BUILD_LEVEL=$1
if [ -z $BUILD_LEVEL ]; then
echo
echo "Building entire workspace"
make_group "core"
make_group "primary"
make_group "secondary"
return
fi
echo
echo "Build level $BUILD_LEVEL selected."
if [ $BUILD_LEVEL -ge 1 ]; then
make_group "core"
else
echo
echo "Failed to build anything."
echo "Specify a build level greater than 0."
exit 1
fi
if [ $BUILD_LEVEL -ge 2 ]; then
make_group "primary"
else
echo "Finished!"
return
fi
if [ $BUILD_LEVEL -ge 3 ]; then
make_group "secondary"
else
return
fi
}
install_spigot() {
echo
echo "Installing Spigot to maven repo..."
echo "--- Entering spigot/ directory"
cd $BASE_DIR/spigot/ >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to enter spigot/ directory. Check $1 for more info."; exit $rc
fi
echo "--- Applying patches"
./applyPatches.sh >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to apply Spigot patches. Check $1 for more info."; exit $rc
fi
echo "--- Entering spigot/Spigot-Server/ directory"
cd $BASE_DIR/spigot/Spigot-Server/ >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to enter spigot/Spigot-Server/ directory. Check $1 for more info."; exit $rc
fi
echo "--- Adding ams2990 remote to spigot-server"
git remote add ams2990 https://github.com/ams2990/CraftBukkit >>$1 2>&1
rc=$?
echo "--- Fetching ams2990 remote for spigot-server"
git fetch ams2990 >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to fetch ams2990 remote for spigot-server. Check $1 for more info."; exit $rc
fi
echo "--- Cherry-picking ams2990's commits for spigot-server"
git cherry-pick f11291edd9c21e8691c483151428e85af2382544 >>$1 2>&1
git cherry-pick 5ae0b449dff4cb92d40d4ccefc8ea10fe4ee5345 >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to cherry-pick ams2990's for spigot-server. Check $1 for more info."; exit $rc
fi
echo "--- Entering spigot/ directory"
cd $BASE_DIR/spigot/ >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to enter spigot/ directory. Check $1 for more info."; exit $rc
fi
echo "--- Compiling Spigot and installing to maven repo"
mvn clean source:jar install >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to compile and install Spigot. Check $1 for more info."; exit $rc
fi
echo "--- Spigot installation complete!"
}
install_combat_tag() {
echo
echo "Installing Combat Tag to maven repo..."
echo "--- Entering combat-tag/ directory"
cd $BASE_DIR/combat-tag/ >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to enter combat-tag/ directory. Check $1 for more info."; exit $rc
fi
echo "--- Installing jar into maven repo"
mvn install:install-file \
-DpomFile=combat-tag-6.1.3.pom \
-Dfile=combat-tag-6.1.3.jar >>$1 2>&1
rc=$?
if [[ $rc != 0 ]]; then
echo "[ERROR] Failed to install Combat Tag into maven repo. Check $1 for more info."; exit $rc
fi
echo "--- Combat Tag installation complete!"
}
if [[ "$1" == "install_spigot" ]]; then
install_spigot $LOG_DIR/spigot.log
fi
if [[ "$1" == "install_combat_tag" ]]; then
install_combat_tag $LOG_DIR/combat_tag.log
else
main $1
fi
echo "Finished!"