-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·362 lines (295 loc) · 8.62 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
#!/bin/bash
# Copyright, Aleksey Konovkin ([email protected])
# BSD license type
download=0
if [ "$1" == "1" ]; then
download=1
fi
build_deps=0
DIR="$(pwd)"
VERSION="1.13.6"
PCRE_VERSION="8.39"
LUAJIT_VERSION="2.1.0-beta2"
ZLIB_VERSION="1.2.11"
SUFFIX=""
BASE_PREFIX="$DIR/build"
INSTALL_PREFIX="$DIR/install"
JIT_PREFIX="$DIR/build/deps/luajit"
export LUAJIT_INC="$JIT_PREFIX/usr/local/include/luajit-2.1"
export LUAJIT_LIB="$JIT_PREFIX/usr/local/lib"
export PCRE_SOURCES="$DIR/build/pcre-$PCRE_VERSION"
export ZLIB_SOURCES="$DIR/build/zlib-$ZLIB_VERSION"
EMBEDDED_OPTS="--with-pcre=$PCRE_SOURCES --with-zlib=$ZLIB_SOURCES"
export LD_LIBRARY_PATH="$JIT_PREFIX/lib"
function clean() {
rm -rf install 2>/dev/null
rm -rf $(ls -1d build/* 2>/dev/null | grep -v deps) 2>/dev/null
if [ $download -eq 1 ]; then
rm -rf download 2>/dev/null
fi
}
if [ "$1" == "clean" ]; then
clean
exit 0
fi
function build_luajit() {
echo "Build luajit"
cd LuaJIT-$LUAJIT_VERSION
make -j 8 > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
DESTDIR="$JIT_PREFIX" make install > /dev/null
cd ..
}
function build_cJSON() {
echo "Build cjson"
cd lua-cjson
PREFIX="$JIT_PREFIX/usr/local" make > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
cd ..
}
function build_int64() {
echo "Build int64"
cd lua_int64
CFLAGS="-I$JIT_PREFIX/usr/local/include/luajit-2.1" make > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
cd ..
}
function build_debug() {
cd nginx-$VERSION$SUFFIX
echo "Configuring debug nginx-$VERSION$SUFFIX"
./configure --prefix="$INSTALL_PREFIX/nginx-$VERSION$SUFFIX" \
$EMBEDDED_OPTS \
--with-debug \
--with-stream \
--add-module=../ngx_devel_kit \
--add-module=../lua-nginx-module > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
echo "Build debug nginx-$VERSION$SUFFIX"
make -j8 > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install > /dev/null
mv "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/sbin/nginx" "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/sbin/nginx.debug"
cd ..
}
function build_release() {
cd nginx-$VERSION$SUFFIX
echo "Configuring release nginx-$VERSION$SUFFIX"
./configure --prefix="$INSTALL_PREFIX/nginx-$VERSION$SUFFIX" \
$EMBEDDED_OPTS \
--with-stream \
--add-module=../ngx_devel_kit \
--add-module=../lua-nginx-module > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
echo "Build release nginx-$VERSION$SUFFIX"
make -j8 > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
make install > /dev/null
cd ..
}
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 gitclone() {
git clone $1 > /dev/null 2> /tmp/err
if [ $? -ne 0 ]; then
cat /tmp/err
fi
}
function download_nginx() {
if [ $download -eq 1 ] || [ ! -e nginx-$VERSION.tar.gz ]; then
echo "Download nginx-$VERSION"
curl -s -L -O http://nginx.org/download/nginx-$VERSION.tar.gz
else
echo "Get nginx-$VERSION.tar.gz"
fi
}
function download_luajit() {
if [ $download -eq 1 ] || [ ! -e LuaJIT-$LUAJIT_VERSION.tar.gz ]; then
echo "Download LuaJIT-$LUAJIT_VERSION"
curl -s -L -O http://luajit.org/download/LuaJIT-$LUAJIT_VERSION.tar.gz
else
echo "Get LuaJIT-$LUAJIT_VERSION.tar.gz"
fi
}
function download_pcre() {
if [ $download -eq 1 ] || [ ! -e pcre-$PCRE_VERSION.tar.gz ]; then
echo "Download PCRE-$PCRE_VERSION"
curl -s -L -O http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-$PCRE_VERSION.tar.gz
else
echo "Get pcre-$PCRE_VERSION.tar.gz"
fi
}
function download_dep() {
if [ $download -eq 1 ] || [ ! -e $2-$3.tar.gz ]; then
echo "Download $2-$3.$4"
curl -s -L -o $2-$3.tar.gz $1/$2-$3.$4
else
echo "Get $2-$3.tar.gz"
fi
}
function extract_downloads() {
cd download
for d in $(ls -1 *.tar.gz)
do
echo "Extracting $d"
tar zxf $d -C ../build --no-overwrite-dir --keep-old-files 2>/dev/null
done
cd ..
}
function download() {
mkdir build 2>/dev/null
mkdir build/deps 2>/dev/null
mkdir download 2>/dev/null
mkdir download/lua_modules 2>/dev/null
cd download
download_luajit
download_pcre
download_nginx
download_module simpl ngx_devel_kit master
download_module ZigzagAK lua-nginx-module mixed
download_module ZigzagAK lua-cjson mixed
download_module ZigzagAK lua_int64 master
download_module openresty echo-nginx-module master
download_dep http://zlib.net zlib $ZLIB_VERSION tar.gz
cd ..
}
function install_file() {
echo "Install $1"
if [ ! -e "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$2" ]; then
mkdir -p "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$2"
fi
cp -r $3 $1 "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$2/"
}
function install_files() {
for f in $(ls $1)
do
install_file $f $2 $3
done
}
function build() {
cd build
patch -N -p0 < ../lua-cjson-Makefile.patch
if [ $build_deps -eq 1 ] || [ ! -e deps/luajit ]; then
build_luajit
fi
build_cJSON
build_int64
make clean > /dev/null 2>&1
build_debug
make clean > /dev/null 2>&1
build_release
install_file "$JIT_PREFIX/usr/local/lib" .
install_file lua-cjson/cjson.so lib/lua/5.1
install_file lua_int64/int64.so lib/lua/5.1
cd ..
}
clean
download
extract_downloads
build
function install_resty_module() {
if [ -e $DIR/../$2 ]; then
echo "Get $DIR/../$2"
dir=$(pwd)
cd $DIR/..
zip -qr $dir/$2.zip $(ls -1d $2/* | grep -vE "(install$)|(build$)|(download$)|(.git$)")
cd $dir
else
if [ $6 -eq 1 ] || [ ! -e $2-$5.zip ] ; then
echo "Download $2 branch=$5"
rm -rf $2-$5 2>/dev/null
curl -s -L -O https://github.com/$1/$2/archive/$5.zip
mv $5.zip $2-$5.zip
else
echo "Get $2-$5"
fi
fi
echo "Install $2/$3"
if [ ! -e "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$4" ]; then
mkdir -p "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$4"
fi
if [ -e $2-$5.zip ]; then
unzip -q $2-$5.zip
cp -r $2-$5/$3 "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$4/"
rm -rf $2-$5
elif [ -e $2-$5.tar.gz ]; then
tar zxf $2-$5.tar.gz
cp -r $2-$5/$3 "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$4/"
rm -rf $2-$5
elif [ -e $2.zip ]; then
unzip -q $2.zip
cp -r $2/$3 "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$4/"
rm -rf $2
elif [ -e $2.tar.gz ]; then
tar zxf $2.tar.gz
cp -r $2/$3 "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/$4/"
rm -rf $2
fi
}
function install_lua_modules() {
if [ $download -eq 1 ]; then
rm -rf download/lua_modules/* 2>/dev/null
fi
cd download/lua_modules
install_resty_module openresty lua-resty-redis lib . master $download
install_resty_module openresty lua-resty-lock lib . master $download
install_resty_module pintsized lua-resty-http lib . master $download
install_resty_module openresty lua-resty-lrucache lib . master $download
install_resty_module ZigzagAK nginx-resty-auto-healthcheck-config lua/job.lua lua master $download
install_resty_module ZigzagAK nginx-resty-auto-healthcheck-config lua/shdict.lua lua master 0
install_resty_module ZigzagAK nginx-resty-auto-healthcheck-config lua/shdict_ex.lua lua master 0
install_resty_module ZigzagAK nginx-resty-auto-healthcheck-config scripts/start.sh . master 0
install_resty_module ZigzagAK nginx-resty-auto-healthcheck-config scripts/stop.sh . master 0
install_resty_module ZigzagAK nginx-resty-auto-healthcheck-config scripts/restart.sh . master 0
cd ../..
install_file conf .
install_file lib .
install_file lua .
install_file html .
}
install_lua_modules
cp LICENSE "$INSTALL_PREFIX/nginx-$VERSION$SUFFIX/LICENSE"
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