-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
executable file
·421 lines (353 loc) · 9.2 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
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
#!/bin/bash
# Copyright, Aleksey Konovkin ([email protected])
# BSD license type
if [ "$1" == "" ]; then
echo "build.sh <clean/clean_all> <download/download_all> <build>"
exit 0
fi
download=0
download_only=0
download_all=0
build_deps=0
clean_all=0
compile=0
build_only=0
make_clean=0
DIR="$(pwd)"
DIAG_DIR="diag"
VCS_PATH=${DIR%/*/*}
VERSION="1.20.1"
ZOO_VERSION="3.5.9"
PCRE_VERSION="8.40"
ZLIB_VERSION="1.2.11"
SUFFIX=""
if [ "$BUILD_DIR" == "" ]; then
BUILD_DIR="$DIR/build"
fi
if [ "$INSTALL_DIR" == "" ]; then
INSTALL_DIR="$DIR/install"
fi
if [ "$ERR_LOG" == "" ]; then
ERR_LOG=$BUILD_DIR/error.log
else
ERR_LOG=$BUILD_DIR/$ERR_LOG
fi
if [ "$BUILD_LOG" == "" ]; then
BUILD_LOG=$BUILD_DIR/build.log
else
BUILD_LOG=$BUILD_DIR/$BUILD_LOG
fi
[ -e "$BUILD_DIR" ] || mkdir -p $BUILD_DIR
export ZOO_PREFIX="$BUILD_DIR/deps/zookeeper"
export ZLIB_PREFIX="$BUILD_DIR/deps/zlib"
export PCRE_PREFIX="$BUILD_DIR/deps/pcre"
export LD_LIBRARY_PATH="-L$PCRE_PREFIX/lib:$ZOO_PREFIX/lib:$ZLIB_PREFIX/lib"
ADDITIONAL_INCLUDES="-I$PCRE_PREFIX/include -I$ZLIB_PREFIX/include"
ADDITIONAL_LIBS="-L$PCRE_PREFIX/lib -L$ZLIB_PREFIX/lib"
function clean() {
rm -rf install 2>>$ERR_LOG
if [ $clean_all -eq 1 ]; then
rm -rf $BUILD_DIR 2>>$ERR_LOG
else
rm -rf $(ls -1d $BUILD_DIR/* 2>>$ERR_LOG | grep -v deps) 2>>$ERR_LOG
fi
if [ $download_all -eq 1 ]; then
rm -rf src 2>>$ERR_LOG
fi
}
doclean=0
dobuild=0
for i in "$@"
do
if [ "$i" == "download" ]; then
download=1
fi
if [ "$i" == "download_all" ]; then
download=1
download_all=1
fi
if [ "$i" == "clean_all" ]; then
clean_all=1
doclean=1
fi
if [ "$i" == "build" ]; then
dobuild=1
fi
if [ "$i" == "build_only" ]; then
dobuild=1
build_only=1
fi
if [ "$i" == "clean" ]; then
doclean=1
fi
if [ "$i" == "compile" ]; then
compile=1
fi
done
if [ $doclean -eq 1 ]; then
clean
fi
if [ $download -eq 1 ] && [ $dobuild -eq 0 ]; then
download_only=1
fi
if [ $download -eq 0 ] && [ $dobuild -eq 0 ]; then
if [ $make_components -eq 0 ]; then
exit 0
fi
fi
current_os=`uname`
if [ "$current_os" = "Linux" ]; then
platform="linux"
arch=`uname -p`
shared="so"
if [ -e /etc/redhat-release ]; then
vendor='redhat'
ver=`cat /etc/redhat-release | sed -e 's#[^0-9]##g' -e 's#7[0-2]#73#'`
if [ $ver -lt 50 ]; then
os_release='4.0'
elif [ $ver -lt 60 ]; then
os_release='5.0'
elif [ $ver -lt 70 ]; then
os_release='6.0'
else
os_release='7.0'
fi
if [ "$arch" != "x86_64" ]; then
arch='i686'
fi
DISTR_NAME=$vendor-$platform-$os_release-$arch
else
vendor=$(uname -r)
DISTR_NAME=$vendor-$platform-$arch
fi
fi
if [ "$current_os" = "Darwin" ]; then
platform="macos"
arch=`uname -m`
vendor="apple"
shared="dylib"
CFLAGS="-arch x86_64"
DISTR_NAME=$vendor-$platform-$arch
fi
case $platform in
linux)
# platform has been recognized
;;
macos)
# platform has been recognized
;;
*)
echo "I do not recognize the platform '$platform'." | tee -a $BUILD_LOG
exit 1;;
esac
if [ -z "$BUILD_VERSION" ]; then
BUILD_VERSION="develop"
fi
function build_pcre() {
echo "Build PCRE" | tee -a $BUILD_LOG
cd pcre-$PCRE_VERSION
./configure --prefix="$PCRE_PREFIX" --libdir="$PCRE_PREFIX/lib" >> $BUILD_LOG 2>>$ERR_LOG
make -j 8 >> $BUILD_LOG 2>>$ERR_LOG
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install >> $BUILD_LOG 2>>$ERR_LOG
cd ..
}
function build_zlib() {
echo "Build ZLIB" | tee -a $BUILD_LOG
cd zlib-$ZLIB_VERSION
./configure --prefix="$ZLIB_PREFIX" --libdir="$ZLIB_PREFIX/lib" >> $BUILD_LOG 2>>$ERR_LOG
make -j 8 >> $BUILD_LOG 2>>$ERR_LOG
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install >> $BUILD_LOG 2>>$ERR_LOG
cd ..
}
function build_zoo() {
echo "Build Zookeeper" | tee -a $BUILD_LOG
cd apache-zookeeper-$ZOO_VERSION
ant compile_jute
cd zookeeper-client/zookeeper-client-c
autoreconf -if >> $BUILD_LOG 2>>$ERR_LOG
./configure --without-cppunit --prefix="$ZOO_PREFIX" --enable-shared --disable-static --libdir "$ZOO_PREFIX/lib" >> $BUILD_LOG 2>>$ERR_LOG
make -j 8 >> $BUILD_LOG 2>>$ERR_LOG
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install >> $BUILD_LOG 2>>$ERR_LOG
cd ../../..
}
function build_release() {
cd nginx-$VERSION
if [ $build_only -eq 0 ]; then
make clean >> $BUILD_LOG 2>>$ERR_LOG
echo "Configuring release nginx-$VERSION" | tee -a $BUILD_LOG
./configure --prefix="$INSTALL_DIR/nginx-$VERSION" \
$EMBEDDED_OPTS \
--with-stream \
--with-cc-opt="-Wno-error=unused-value $ADDITIONAL_INCLUDES" \
--with-ld-opt="$ADDITIONAL_LIBS" \
--add-module=../echo-nginx-module \
--add-module=../ngx_dynamic_upstream \
--add-module=../ngx_dynamic_healthcheck \
--add-module=../.. >> $BUILD_LOG 2>>$ERR_LOG
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
fi
echo "Build release nginx-$VERSION" | tee -a $BUILD_LOG
make -j 8 >> $BUILD_LOG 2>>$ERR_LOG
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install >> $BUILD_LOG 2>>$ERR_LOG
cd ..
}
function gitclone() {
LD_LIBRARY_PATH="" git clone $1 >> $BUILD_LOG 2> /tmp/err
if [ $? -ne 0 ]; then
cat /tmp/err
exit 1
fi
}
function gitcheckout() {
git checkout $1 >> $BUILD_LOG 2> /tmp/err
if [ $? -ne 0 ]; then
cat /tmp/err
exit 1
fi
}
function download_module() {
if [ -e $DIR/../$2 ]; then
echo "Get $DIR/../$2"
dir=$(pwd)
cd $DIR/..
tar zcf $dir/$2.tar.gz $(ls -1d $2/* | grep -vE "(install$)|(build$)|(download$)|(.git$)")
cd $dir
else
if [ $download -eq 1 ] || [ ! -e $2.tar.gz ]; then
echo "Download $2 branch=$3"
curl -s -L -o $2.zip https://github.com/$1/$2/archive/$3.zip
unzip -q $2.zip
mv $2-* $2
tar zcf $2.tar.gz $2
rm -rf $2-* $2 $2.zip
fi
fi
}
function download_dep() {
if [ $download -eq 1 ] || [ ! -e $2-$3.tar.gz ]; then
if [ $download_all -eq 1 ] || [ ! -e $2-$3.tar.gz ]; then
echo "Download $2-$3.$4" | tee -a $BUILD_LOG
LD_LIBRARY_PATH="" curl -s -L -o $2-$3.tar.gz $1/$2-$3.$4
echo "$1/$2-$3.$4" > $2.log
else
echo "Get $2-$3.tar.gz" | tee -a $BUILD_LOG
fi
else
echo "Get $2-$3.tar.gz" | tee -a $BUILD_LOG
fi
}
function extract_downloads() {
cd src
for d in $(ls -1 *.tar.gz)
do
echo "Extracting $d" | tee -a $BUILD_LOG
tar zxf $d -C $BUILD_DIR --keep-old-files 2>>$ERR_LOG
done
cd ..
}
function download() {
mkdir -p $BUILD_DIR 2>>$ERR_LOG
mkdir $BUILD_DIR/deps 2>>$ERR_LOG
mkdir src 2>>$ERR_LOG
cd src
download_dep http://nginx.org/download nginx $VERSION tar.gz
download_dep http://mirror.linux-ia64.org/apache/zookeeper/zookeeper-$ZOO_VERSION apache-zookeeper $ZOO_VERSION tar.gz
download_dep http://ftp.cs.stanford.edu/pub/exim/pcre pcre $PCRE_VERSION tar.gz
download_dep http://zlib.net zlib $ZLIB_VERSION tar.gz
download_module ZigzagAK ngx_dynamic_upstream master
download_module ZigzagAK ngx_dynamic_healthcheck master
download_module openresty echo-nginx-module master
cd ..
}
function install_file() {
echo "Install $1" | tee -a $BUILD_LOG
if [ ! -e "$INSTALL_DIR/nginx-$VERSION/$2" ]; then
mkdir -p "$INSTALL_DIR/nginx-$VERSION/$2"
fi
if [ "$4" == "" ]; then
if [ "$3" == "" ]; then
cp -r $1 "$INSTALL_DIR/nginx-$VERSION/$2/"
else
cp -r $1 "$INSTALL_DIR/nginx-$VERSION/$2/$3"
fi
else
echo $4 > "$INSTALL_DIR/nginx-$VERSION/$2/$3"
fi
}
function install_gzip() {
echo "Install $1" | tee -a $BUILD_LOG
if [ ! -e "$INSTALL_DIR/nginx-$VERSION/$2" ]; then
mkdir -p "$INSTALL_DIR/nginx-$VERSION/$2"
fi
if [ "$4" == "" ]; then
if [ "$3" == "" ]; then
tar zxf $1 -C "$INSTALL_DIR/nginx-$VERSION/$2/"
else
tar zxf $1 -C "$INSTALL_DIR/nginx-$VERSION/$2/$3"
fi
else
echo $4 > "$INSTALL_DIR/nginx-$VERSION/$2/$3"
fi
}
function install_files() {
for f in $(ls $1)
do
install_file $f $2
done
}
function build() {
cd $BUILD_DIR
if [ $build_deps -eq 1 ] || [ ! -e deps/zookeeper ]; then
build_zoo
fi
if [ $build_deps -eq 1 ] || [ ! -e deps/zlib ]; then
build_zlib
fi
if [ $build_deps -eq 1 ] || [ ! -e deps/pcre ]; then
build_pcre
fi
build_release
install_files "$ZOO_PREFIX/lib/libzookeeper_mt.$shared*" lib
install_files "$ZLIB_PREFIX/lib/libz.$shared*" lib
install_files "$PCRE_PREFIX/lib/libpcre.$shared*" lib
install_files "$PCRE_PREFIX/lib/libpcreposix.$shared*" lib
chmod 755 $INSTALL_DIR/nginx-$VERSION/lib/*.$shared*
cd $DIR
}
if [ $build_only -eq 0 ]; then
clean
fi
download
if [ $download_only -eq 0 ]; then
if [ $build_only -eq 0 ]; then
extract_downloads
fi
build
fi
cd "$DIR"
kernel_name=$(uname -s)
kernel_version=$(uname -r)
cd install
tar zcvf nginx-$VERSION$SUFFIX-$kernel_name-$kernel_version.tar.gz nginx-$VERSION$SUFFIX
rm -rf nginx-$VERSION$SUFFIX
cd ..
exit $r