forked from ZigzagAK/ngx_dynamic_healthcheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·231 lines (181 loc) · 4.71 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
#!/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.15.6"
PCRE_VERSION="8.39"
ZLIB_VERSION="1.2.11"
SUFFIX=""
BASE_PREFIX="$DIR/build"
INSTALL_PREFIX="$DIR/install"
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"
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_debug() {
cd nginx-$VERSION$SUFFIX
echo "Configuring debug nginx-$VERSION$SUFFIX"
./configure --prefix="$INSTALL_PREFIX/nginx-$VERSION$SUFFIX" \
$EMBEDDED_OPTS \
--with-stream \
--with-debug \
--with-cc-opt="-O0" \
--add-module=../../../ngx_dynamic_healthcheck \
--add-module=../ngx_dynamic_upstream > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
echo "Build debug nginx-$VERSION$SUFFIX"
make -j4 > /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_dynamic_healthcheck \
--add-module=../ngx_dynamic_upstream > /dev/null
r=$?
if [ $r -ne 0 ]; then
exit $r
fi
echo "Build release nginx-$VERSION$SUFFIX"
make -j4 > /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_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 --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_pcre
download_nginx
download_module ZigzagAK ngx_dynamic_upstream 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
# make clean > /dev/null 2>&1
# build_debug
make clean > /dev/null 2>&1
build_release
cd ..
}
clean
download
extract_downloads
build
install_file scripts/start.sh .
install_file scripts/debug.sh .
install_file scripts/restart.sh .
install_file scripts/stop.sh .
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