-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdeploy.sh
executable file
·521 lines (491 loc) · 13.9 KB
/
deploy.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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/bin/bash
DEPLOY_PATH="."
cd $DEPLOY_PATH
DEPLOY_PATH=`pwd`
BUILD_PATH="${DEPLOY_PATH}/build"
NEBULA_BOOTSTRAP="NebulaBeacon NebulaInterface NebulaLogic"
CPU_NUM=`lscpu | awk '/^CPU\(s\)/{print $2}'`
CPU_NUM=1
chmod u+x *.sh
mkdir -p ${DEPLOY_PATH}/lib >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/bin >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/conf >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/log >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/data >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/plugins/logic >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/conf/ssl >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/temp >> /dev/null 2>&1
mkdir -p ${DEPLOY_PATH}/build >> /dev/null 2>&1
function Usage()
{
echo "Usage: $0 [OPTION]..."
echo "options:"
echo -e " -h, --help\t\t\tdisplay this help and exit."
echo -e " -v, --version\t\t\tdisplay nebula version and exit."
echo -e " -L, --local\t\t\tdeploy from local without download any files from internet."
echo -e " --demo\t\tbuild NebulaDemo and NebulaDepend."
echo -e " --only-nebula\t\tonly build Nebula and NebulaBootstrap."
echo -e " --build-path\t\tset the compilation path."
echo -e " --with-ssl\t\tinclude openssl for ssl and crypto. [default: without ssl]"
echo -e " --with-custom-ssl\t\tinclude openssl for ssl and crypto, the openssl is a custom installation version. [default: without ssl]"
echo -e " --with-ssl-include\tthe openssl include path."
echo -e " --with-ssl-lib\t\tthe openssl library path."
echo "example:"
echo " $0 --local --with-ssl --with-ssl-lib /usr/local/lib64 --with-ssl-include /usr/local/include"
echo ""
}
DEPLOY_ONLY_NEBULA=false
DEPLOY_LOCAL=false
DEPLOY_WITH_SSL=false
DEPLOY_WITH_CUSTOM_SSL=false
SSL_INCLUDE_PATH=""
SSL_LIB_PATH=""
ARGV_DEFINE=`getopt \
-o hvL \
--long help,version,local,demo,only-nebula,with-ssl,with-custom-ssl,build-path:,with-ssl-include:,with-ssl-lib: \
-n 'deploy.bash' \
-- "$@"`
if [ $? != 0 ]
then
echo "Terminated!" >&2
exit 1
fi
eval set -- "$ARGV_DEFINE"
while :
do
case "$1" in
-h|--help)
Usage
exit 0
;;
-v|--version)
echo "0.3"
exit 0
;;
--demo)
echo "build NebulaDemo and NebulaDepend."
NEBULA_BOOTSTRAP="NebulaDemo"
shift
;;
--only-nebula)
echo "Only build Nebula and NebulaBootstrap."
DEPLOY_ONLY_NEBULA=true
shift
;;
-L|--local)
echo "Deploy from local without download any files from internet."
DEPLOY_LOCAL=true
shift
;;
--with-ssl)
DEPLOY_WITH_SSL=true
shift
;;
--with-custom-ssl)
DEPLOY_WITH_CUSTOM_SSL=true
shift
;;
--build-path)
BUILD_PATH=$2
shift 2
;;
--with-ssl-include)
SSL_INCLUDE_PATH=$2
DEPLOY_WITH_SSL=true
shift 2
;;
--with-ssl-lib)
SSL_LIB_PATH=$2
DEPLOY_WITH_SSL=true
shift 2
;;
--)
shift
break
;;
*)
echo "invalid argument!"
break
;;
esac
done
replace_config="yes"
build_dir_num=`ls -l ${DEPLOY_PATH}/build | wc -l`
if $DEPLOY_ONLY_NEBULA
then
echo "do you want to replace all the config files with the original config files in build path? [yes | no]"
read replace_config
else # deploy remote
cd ${BUILD_PATH}
if ! $DEPLOY_LOCAL
then
mkdir NebulaDepend lib_build >> /dev/null 2>&1
fi
# install protobuf
cd ${BUILD_PATH}/lib_build
if ! $DEPLOY_LOCAL
then
if [ -f v3.6.0.zip ]
then
echo "protobuf-3.6.0 exist, skip download."
else
wget https://github.com/google/protobuf/archive/v3.6.0.zip
if [ $? -ne 0 ]
then
echo "failed to download protobuf!" >&2
exit 2
fi
fi
unzip v3.6.0.zip
cd protobuf-3.6.0
chmod u+x autogen.sh
./autogen.sh
./configure --prefix=${BUILD_PATH}/NebulaDepend
make -j$CPU_NUM
make install
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cd ${BUILD_PATH}/lib_build
rm -rf protobuf-3.6.0
fi
# install libev
cd ${BUILD_PATH}/lib_build
if ! $DEPLOY_LOCAL
then
if [ -f libev.zip ]
then
echo "libev exist, skip download."
else
wget https://github.com/kindy/libev/archive/master.zip
if [ $? -ne 0 ]
then
echo "failed to download libev!" >&2
exit 2
fi
mv master.zip libev.zip
fi
unzip libev.zip
mv libev-master libev
cd libev/src
chmod u+x autogen.sh
./autogen.sh
./configure --prefix=${BUILD_PATH}/NebulaDepend
make -j$CPU_NUM
make install
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cd ${BUILD_PATH}/lib_build
rm -rf libev
fi
# install hiredis
cd ${BUILD_PATH}/lib_build
if ! $DEPLOY_LOCAL
then
if [ -f hiredis_v0.13.0.zip ]
then
echo "directory hiredis exist, skip download."
else
wget https://github.com/redis/hiredis/archive/v0.13.0.zip
if [ $? -ne 0 ]
then
echo "failed to download hiredis!" >&2
exit 2
fi
mv v0.13.0.zip hiredis_v0.13.0.zip
fi
unzip hiredis_v0.13.0.zip
mv hiredis-0.13.0 hiredis
cd hiredis
make -j$CPU_NUM
mkdir -p ../../NebulaDepend/include/hiredis
cp -r adapters *.h ../../NebulaDepend/include/hiredis/
cp libhiredis.so ../../NebulaDepend/lib/libhiredis.so.0.13
cd ../../NebulaDepend/lib/
ln -s libhiredis.so.0.13 libhiredis.so
cd -
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cd ${BUILD_PATH}/lib_build
rm -rf hiredis
fi
# install openssl
if $DEPLOY_WITH_CUSTOM_SSL
then
cd ${BUILD_PATH}/lib_build
if ! $DEPLOY_LOCAL
then
if [ -f OpenSSL_1_1_0.zip ]
then
echo "openssl-OpenSSL_1_1_0 exist, skip download."
else
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0.zip
if [ $? -ne 0 ]
then
echo "failed to download openssl!" >&2
exit 2
fi
fi
unzip OpenSSL_1_1_0.zip
cd openssl-OpenSSL_1_1_0
./config --prefix=${BUILD_PATH}/NebulaDepend
make -j$CPU_NUM
make install
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cd ${BUILD_PATH}/lib_build
rm -rf openssl-OpenSSL_1_1_0
fi
fi
# install crypto++
cd ${BUILD_PATH}/lib_build
if ! $DEPLOY_LOCAL
then
if [ -f CRYPTOPP_8_0_0.zip ]
then
echo "cryptopp-CRYPTOPP_8_0_0 exist, skip download."
else
wget https://github.com/weidai11/cryptopp/archive/CRYPTOPP_8_0_0.zip
if [ $? -ne 0 ]
then
echo "failed to download crypto++!" >&2
exit 2
fi
fi
unzip CRYPTOPP_8_0_0.zip
cd cryptopp-CRYPTOPP_8_0_0
make -j$CPU_NUM libcryptopp.so
mkdir -p ../../NebulaDepend/include/cryptopp
cp *.h ../../NebulaDepend/include/cryptopp/
cp libcryptopp.so ../../NebulaDepend/lib/libcryptopp.so.8
cd ../../NebulaDepend/lib
ln -s libcryptopp.so.8 libcryptopp.so
cd -
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cd ${BUILD_PATH}/lib_build
rm -rf cryptopp-CRYPTOPP_8_0_0
fi
# copy libs to deploy path
if ! $DEPLOY_LOCAL
then
cd ${BUILD_PATH}/NebulaDepend/lib
tar -zcvf neb_depend.tar.gz lib*.so lib*.so.*
mv neb_depend.tar.gz ${DEPLOY_PATH}/lib/
cd ${DEPLOY_PATH}/lib
rm -r lib* >> /dev/null 2>&1
tar -zxvf neb_depend.tar.gz
rm neb_depend.tar.gz
fi
fi
# shutdown running nebula server
if $DEPLOY_LOCAL -a $DEPLOY_ONLY_NEBULA
then
cd ${DEPLOY_PATH}
echo "yes" | ./shutdown.sh
rm log/* >> /dev/null 2>&1
fi
# download Nebula
cd ${BUILD_PATH}
if ! $DEPLOY_LOCAL
then
if [ -f Nebula.zip ]
then
echo "Nebula exist, skip download."
else
wget https://github.com/Bwar/Nebula/archive/master.zip
if [ $? -ne 0 ]
then
echo "failed to download Nebula!" >&2
exit 2
fi
mv master.zip Nebula.zip
fi
fi
if [ -d Nebula ]
then
echo "Nebula directory exist."
else
unzip Nebula.zip
mv Nebula-master Nebula
mkdir Nebula/include
mkdir Nebula/lib
fi
cd Nebula/proto
${BUILD_PATH}/NebulaDepend/bin/protoc *.proto --cpp_out=../src/pb
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
# modify Nebula Makefile and make
cd ${BUILD_PATH}/Nebula/src
sed -i 's/gcc-6/gcc/g' Makefile
sed -i 's/g++-6/g++/g' Makefile
if $DEPLOY_WITH_SSL
then
sed -i 's/-D__GUNC__/-D__GUNC__ -DWITH_OPENSSL/g' Makefile
sed -i "/-L\$(LIB3RD_PATH)\/lib -lprotobuf/a\ -L\$(SYSTEM_LIB_PATH)\/lib -lssl \x5c" Makefile
if [ ! -z "$SSL_INCLUDE_PATH" ]
then
sed -i "/-I \$(LIB3RD_PATH)\/include/a\ -I ${SSLINCLUDE_PATH} \x5c" Makefile
fi
if [ ! -z "$SSL_LIB_PATH" ]
then
sed -i "s/-L\$(SYSTEM_LIB_PATH)\/lib -lssl/-L${SSL_LIB_PATH} -lssl/g" Makefile
fi
elif $DEPLOY_WITH_CUSTOM_SSL
then
sed -i 's/-D__GUNC__/-D__GUNC__ -DWITH_OPENSSL/g' Makefile
sed -i "/-L\$(LIB3RD_PATH)\/lib -lprotobuf/a\ -L\$(LIB3RD_PATH)\/lib -lssl \x5c" Makefile
if [ ! -z "$SSL_INCLUDE_PATH" ]
then
sed -i "/-I \$(LIB3RD_PATH)\/include/a\ -I ${SSLINCLUDE_PATH} \x5c" Makefile
fi
if [ ! -z "$SSL_LIB_PATH" ]
then
sed -i "s/-L\$(LIB3RD_PATH)\/lib -lssl/-L${SSL_LIB_PATH} -lssl/g" Makefile
fi
else
sed -i 's/-DWITH_OPENSSL / /g' Makefile
sed -i '/-L$(LIB3RD_PATH)\/lib -lssl/d' Makefile
sed -i '/-L$(SYSTEM_LIB_PATH)\/lib -lssl/d' Makefile
fi
make clean; make -j$CPU_NUM
cp libnebula.so ${DEPLOY_PATH}/lib/
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cd ${BUILD_PATH}
# download NebulaBootstrap server
cd ${BUILD_PATH}
for server in $NEBULA_BOOTSTRAP
do
if ! $DEPLOY_LOCAL
then
if [ -f "${server}.zip" ]
then
echo "${server} exist, skip download."
else
wget https://github.com/Bwar/${server}/archive/master.zip
if [ $? -ne 0 ]
then
echo "failed to download ${server}!" >&2
exit 2
fi
mv master.zip ${server}.zip
fi
fi
if [ -d ${server} ]
then
echo "${server} directory exist."
else
unzip ${server}.zip
mv ${server}-master ${server}
fi
if [ -d ${server}/proto ]
then
cd ${server}/proto
${BUILD_PATH}/NebulaDepend/bin/protoc *.proto --cpp_out=../src
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
fi
cd ${BUILD_PATH}/${server}/src/
sed -i 's/gcc-6/gcc/g' Makefile
sed -i 's/g++-6/g++/g' Makefile
if $DEPLOY_WITH_SSL
then
sed -i 's/-L$(LIB3RD_PATH)\/lib -lssl/-L$(SYSTEM_LIB_PATH)\/lib -lssl/g' Makefile
if [ ! -z "$SSL_INCLUDE_PATH" ]
then
sed -i "/-I \$(LIB3RD_PATH)\/include/i\ -I ${SSLINCLUDE_PATH} \x5c" Makefile
fi
if [ ! -z "$SSL_LIB_PATH" ]
then
sed -i "s/-L\$(SYSTEM_LIB_PATH)\/lib -lssl/-L${SSL_LIB_PATH} -lssl/g" Makefile
fi
elif $DEPLOY_WITH_CUSTOM_SSL
then
if [ ! -z "$SSL_INCLUDE_PATH" ]
then
sed -i "/-I \$(LIB3RD_PATH)\/include/i\ -I ${SSLINCLUDE_PATH} \x5c" Makefile
fi
if [ ! -z "$SSL_LIB_PATH" ]
then
sed -i "s/-L\$(SYSTEM_LIB_PATH)\/lib -lssl/-L${SSL_LIB_PATH} -lssl/g" Makefile
fi
else
sed -i '/-L$(LIB3RD_PATH)\/lib -lssl/d' Makefile
fi
make clean; make -j$CPU_NUM
if [ $? -ne 0 ]
then
echo "failed, teminated!" >&2
exit 2
fi
cp ${server} ${DEPLOY_PATH}/bin/
if [[ "$replace_config" == "yes" ]]
then
cd ${BUILD_PATH}/${server}/conf/
cp *.json ${DEPLOY_PATH}/conf/
fi
cd ${BUILD_PATH}
done
# download NebulaDynamic and build
if ! $DEPLOY_LOCAL && [ "$NEBULA_BOOTSTRAP" != "NebulaDemo" ]
then
if [ -f "NebulaDynamic.zip" ]
then
echo "NebulaDynamic exist, skip download."
else
wget https://github.com/Bwar/NebulaDynamic/archive/master.zip
if [ $? -ne 0 ]
then
echo "failed to download NebulaDynamic!" >&2
exit 2
fi
mv master.zip NebulaDynamic.zip
fi
fi
if [ -d NebulaDynamic ]
then
echo "NebulaDynamic directory exist."
else
unzip NebulaDynamic.zip
mv NebulaDynamic-master NebulaDynamic
fi
if [ -d ${BUILD_PATH}/NebulaDynamic ]
then
cd ${BUILD_PATH}/NebulaDynamic/Hello/src/
sed -i 's/gcc-6/gcc/g' Makefile
sed -i 's/g++-6/g++/g' Makefile
make clean; make -j$CPU_NUM
cp *.so ${DEPLOY_PATH}/plugins/logic/ >> /dev/null
fi
cd ${BUILD_PATH}
# startup nebula server
cd ${DEPLOY_PATH}/
if [[ "$replace_config" == "yes" ]]
then
./configure.sh
fi
./startup.sh