forked from nuls-io/nuls-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package
executable file
·690 lines (645 loc) · 20.2 KB
/
package
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#!/bin/bash
help()
{
cat <<- EOF
Desc: 使用此脚本将生成符合NULSTAR规范的可执行子模块,
所有子模块按照module.ncf配置,使用mvn命令进行打包,并生成启动、停止脚本
Usage: ./package.sh
-b <branch> 打包前同步最新代码 参数为同步的远程分支名称
-p 打包前同步最新代码 从master分支拉取
-o <目录> 指定输出目录
-h 查看帮助
-j JAVA_HOME
-J 输出的jvm虚拟机目录,脚本将会把这个目录复制到程序依赖中
-i 跳过mvn打包
-z 生成压缩包
-N d打包时加入Nulstar模块
-a 添加一个打包模块
-r 移除一个打包模块
-s 查看配置的待打包模块列表
Author: zlj
EOF
exit 0
}
#日志打印函数
echoRed() { echo $'\e[0;31m'$1$'\e[0m'; } #print red
echoGreen() { echo $'\e[0;32m'$1$'\e[0m'; } #print green
echoYellow() { echo $'\e[0;33m'$1$'\e[0m'; } #print yellow
log(){ #print date prefix and green
now=`date "+%Y-%m-%d %H:%M:%S"`
echoGreen "$now $@"
}
BUILD_NULSTAR="1"
NULSTAR_FILE_NAME="nulstar_190909.tar.gz"
#TARGET_OS=linux
#NULSTAR download url
NULSTAR_URL="https://nulscn.oss-cn-beijing.aliyuncs.com/nulstar/"
#获取参数
#输出目录
NULS_WALLET_TAR_NAME="./NULS_Wallet"
MODULES_PATH="${NULS_WALLET_TAR_NAME}"
#RELEASE_OUT_PATH="./NULS-Walltet-linux64-alpha1"
#是否马上更新代码
DOPULL=
#是否生成mykernel模块
DOMOCK=
#更新代码的 git 分支
GIT_BRANCH=
#项目根目录
cd `dirname $0`
PROJECT_PATH=`pwd`;
cd $PROJECT_PATH;
#打包工作目录
BUILD_PATH="${PROJECT_PATH}/build";
#打包配置文件
PACKAGE_CONFIG="`pwd`/.package.ncf"
if [ ! -f "$PACKAGE_CONFIG" ]; then
cp "${BUILD_PATH}/package-base.ncf" $PACKAGE_CONFIG
fi
NULS_NCF=${PROJECT_PATH}/config/nuls.ncf
GENESIS_BLOCK=${PROJECT_PATH}/config/genesis-block.json
#编辑.package.ncf
updatePackage(){
c="sed -n '/^$1/p' $PACKAGE_CONFIG"
has=`eval $c`;
if [ -n "$has" ];
then
os=`uname`
if [ "$os" == "Darwin" ];
then
eval "sed -i '' 's/^$has/$1=$2/' $PACKAGE_CONFIG"
else
eval "sed -i 's/^$has/$1=$2/' $PACKAGE_CONFIG"
fi
else
if [ $2 == "1" ]; then
echo "${1}=1" >> $PACKAGE_CONFIG
echo "" >> $PACKAGE_CONFIG
fi
fi
exit 0
}
showPackageModule(){
log "=========================="
log "package module list"
while read line
do
TEMP=`echo $line|grep -Eo '\[.+\]'`
if [ -z "$TEMP" ]; then
isPackage=`echo $line |grep "=1"`
if [ -n "$isPackage" ]; then
log "---->$line" | awk -F '=' '{print $1}'
fi
fi
done < $PACKAGE_CONFIG
log "=========================="
}
setTargetOS(){
case "$1" in
linux64)
TARGET_OS=linux;;
linux)
TARGET_OS=linux;;
macos)
TARGET_OS=macos;;
win64)
TARGET_OS=window;;
window)
TARGET_OS=window;;
?) exit 2;;
esac
NULSTAR_FILE_NAME=${TARGET_OS}_${NULSTAR_FILE_NAME}
}
while getopts phb:o:j:iJ:zNa:r:sO:B name
do
case $name in
p) DOPULL=1
GIT_BRANCH="master";;
b) DOPULL=1
GIT_BRANCH="$OPTARG"
;;
o) MODULES_PATH="$OPTARG";;
O) setTargetOS "$OPTARG";;
h) help ;;
j) JAVA_HOME="$OPTARG";;
i) IGNROEMVN="1";;
J) JRE_HOME="$OPTARG";;
z) BUILDTAR="1";;
N) BUILD_NULSTAR="1";;
a) updatePackage "$OPTARG" 1;;
r) updatePackage "$OPTARG" 0;;
s) showPackageModule
exit 0
;;
B) NULS_NCF=${PROJECT_PATH}/config/nuls.beta.ncf
GENESIS_BLOCK=${PROJECT_PATH}/config/genesis-block.beta.json
;;
?) exit 2;;
esac
done
# default packing nulstar for linux platform
if [ -z "$TARGET_OS" ]; then
setTargetOS "linux"
fi
# 检查java版本 must be 11
checkJavaVersion(){
JAVA="$JAVA_HOME/bin/java"
if [ ! -r "$JAVA" ]; then
JAVA='java'
fi
JAVA_EXIST=`${JAVA} -version 2>&1 |grep 11`
if [ ! -n "$JAVA_EXIST" ]; then
log "JDK version is not 11"
${JAVA} -version
exit 0
fi
}
checkJavaVersion
#执行mvn函数打包java工程 $1 命令 $2 模块名称
doMvn(){
if [ -n "$IGNROEMVN" ]; then
log "skip mvn package";
return ;
fi
log "mvn $1 $2"
moduleLogDir="${BUILD_PATH}/tmp/$2";
if [ ! -d ${moduleLogDir} ]; then
mkdir ${moduleLogDir}
fi
installLog="${moduleLogDir}/log.log";
mvn clean $1 -Dmaven.test.skip=true > "${installLog}" 2>&1
mvnSuccess=`grep "BUILD SUCCESS" ${installLog}`
if [ ! -n "$mvnSuccess" ]; then
echoRed "$1 $2 FAIL"
echoRed "日志文件:${installLog}"
cd ..
exit 0
fi
# rm $installLog;
log "$1 $2 success"
}
log "working path is $PROJECT_PATH";
log "loading package config : ${PACKAGE_CONFIG}"
#读取要打包的模块信息
showPackageModule
if [ ! -d "${BUILD_PATH}/tmp" ]; then
mkdir "${BUILD_PATH}/tmp"
fi
if [ ! -d "${MODULES_PATH}" ]; then
mkdir "${MODULES_PATH}"
fi
MODULES_PATH=`cd "$MODULES_PATH"; pwd`
RELEASE_PATH=$MODULES_PATH
echoYellow "Modules Path $MODULES_PATH"''
log "==================BEGIN PACKAGE MODULES=============================="
declare -a managedModules
#if [ ! -d "$MODULES_PATH/bin" ]; then
# mkdir $MODULES_PATH/bin
#fi
#存放脚本目录
MODULES_BIN_PATH=$MODULES_PATH
if [ ! -d "$MODULES_PATH/Modules" ]; then
#statements
mkdir $MODULES_PATH/Modules
fi
#模块数据库文件存放位置
COMMON_DATA_PATH=$MODULES_PATH/data
if [ ! -d ${COMMON_DATA_PATH} ]; then
mkdir ${COMMON_DATA_PATH}
fi
#默认日志目录
MODULES_LOGS_PATH=${MODULES_PATH}/Logs
if [ ! -d "$MODULES_LOGS_PATH" ]; then
#statements
mkdir $MODULES_LOGS_PATH
fi
MODULES_PATH=$MODULES_PATH/Modules
#创建NULS_2.0公共模块目录
if [ ! -d "$MODULES_PATH/Nuls" ]; then
mkdir $MODULES_PATH/Nuls
fi
MODULES_PATH=$MODULES_PATH/Nuls
#模块公共依赖jar存放目录
COMMON_LIBS_PATH=$MODULES_PATH/libs
if [ -z "${IGNROEMVN}" ]; then
if [ -d ${COMMON_LIBS_PATH} ]; then
rm -r ${COMMON_LIBS_PATH}
fi
mkdir ${COMMON_LIBS_PATH}
fi
#0.更新代码
if [ -n "${DOPULL}" ];then
log "git pull origin $GIT_BRANCH"
git pull origin "$GIT_BRANCH"
fi
echo "`cat version`-`git rev-parse --short HEAD`" > .package-version
PACKAGE_VERSION=`cat .package-version`
#0.download Nulstar
if [ -n "${BUILD_NULSTAR}" ]; then
log "build Nulstar "
log "target os : $TARGET_OS"
if [ ! -f "${BUILD_PATH}/tmp/${NULSTAR_FILE_NAME}" ];
then
log "download Nulstar"
wget $NULSTAR_URL${NULSTAR_FILE_NAME}
mv "./${NULSTAR_FILE_NAME}" ${BUILD_PATH}/tmp/${NULSTAR_FILE_NAME}
else
log "found ${BUILD_PATH}/tmp/${NULSTAR_FILE_NAME}"
fi
if [ -f "${BUILD_PATH}/tmp/${NULSTAR_FILE_NAME}" ]; then
tar -xvf "${BUILD_PATH}/tmp/${NULSTAR_FILE_NAME}" -C "${BUILD_PATH}/tmp"
cp -Rf "${BUILD_PATH}/tmp/Nulstar/Modules" ${RELEASE_PATH}
cp -Rf "${BUILD_PATH}/tmp/Nulstar/Libraries" ${RELEASE_PATH}
if [ "${TARGET_OS}" == "window" ];
then
cp "${BUILD_PATH}/nulstar/start.bat" "${RELEASE_PATH}/start.bat"
cp "${BUILD_PATH}/nulstar/stop.bat" "${RELEASE_PATH}/stop.bat"
else
cp "${BUILD_PATH}/nulstar/start.sh" "$RELEASE_PATH/start"
cp "${BUILD_PATH}/nulstar/stop.sh" "$RELEASE_PATH/stop"
chmod +x "${RELEASE_PATH}/start"
chmod +x "${RELEASE_PATH}/stop"
fi
fi
log "build Nulstar done"
fi
rm -rf ${COMMON_LIBS_PATH}/*
doMvn "clean package" "nuls-project"
#检查module.ncf指定配置项是否存在
checkModuleItem(){
if [ ! -f "./module.ncf" ]; then
return 0
fi
if [ -z "$1" ]; then
echoRed "getModuleItem 必须传入配置项名称"
exit 1
fi
while read line
do
pname=`echo $line | awk -F '=' '{print $1}'`
if [ "${pname}" == "$1" ]; then
return 1;
fi
done < "$(pwd)/module.ncf"
echoRed "$2 module.ncf 必须配置 $1"
exit 0
}
getModuleItem(){
moduleFile="./module.ncf"
if [ -n "$2" ]; then
moduleFile=$2
fi
while read line
do
pname=`echo $line | awk -F '=' '{print $1}'`
pvalue=`awk -v a="$line" '
BEGIN{
len = split(a,ary,"=")
r=""
for ( i = 2; i <= len; i++ ){
if(r != ""){
r = (r"=")
}
r=(r""ary[i])
}
print r
}
'`
if [ "${pname}" == $1 ]; then
echo ${pvalue};
return 1;
fi
done < $moduleFile
return 0
}
hasPackageModule(){
echo `getModuleItem $1 ${PACKAGE_CONFIG}`
}
#拷贝打好的jar包到Moules/Nuls/<Module Name>/<Version> 下
copyJarToModules(){
# if [ -z "$IGNROEMVN" ]; then
# doMvn "clean package" $1
# fi
moduleName=`getModuleItem "APP_NAME"`;
version=`getModuleItem "VERSION"`;
privateDependent=`getModuleItem "PrivateDependent"`;
if [ ! -d "${MODULES_PATH}/${moduleName}" ];then
mkdir ${MODULES_PATH}/${moduleName}
fi
if [ -d "${MODULES_PATH}/${moduleName}/${version}" ]; then
rm -r "${MODULES_PATH}/${moduleName}/${version}"
fi
moduleOutPath="${MODULES_PATH}/${moduleName}/${version}"
if [ ! -d "$moduleOutPath" ]; then
mkdir $moduleOutPath
fi
modulePriLibPath="${moduleOutPath}/lib"
if [ ! -d "${modulePriLibPath}" ]; then
mkdir $modulePriLibPath
else
rm -rf "${modulePriLibPath}/*"
fi
jarName=`ls target |grep .jar`
nowPath=`pwd`
echo "copy ${nowPath}/target/${moduleName}-${version}.jar to ${MODULES_PATH}/${moduleName}/${version}/${moduleName}-${version}.jar"
cp ./target/${jarName} "${MODULES_PATH}/${moduleName}/${version}/${moduleName}-${version}.jar"
dependentListConf=./target/dependentList
if [ -f "$dependentListConf" ]; then
rm -f $dependentListConf
fi
touch $dependentListConf;
if [ -d ./target/libs ]; then
for jar in `ls ./target/libs`; do
echo "$jar" >> $dependentListConf
# isPriDependent=`awk -v a="$privateDependent" -v j="$jar" '
# BEGIN{
# len = split(a,ary,",")
# for ( i = 1; i <= len; i++ ){
# if(index(j,ary[i])){
# print j
# }
# }
# }
# '`
# if [ -n "$isPriDependent" ]; then
# cp "./target/libs/${jar}" "${modulePriLibPath}"
# else
# #statement
if [ ! -f ${COMMON_LIBS_PATH}/${jar} ]; then
cp "./target/libs/${jar}" "${COMMON_LIBS_PATH}"
fi
# fi
done
cp "$dependentListConf" "${MODULES_PATH}/${moduleName}/${version}/dependent.conf"
fi
loadLanguage=`getModuleItem "loadLanguage"`;
if [ "$loadLanguage" == "1" ]; then
cp -r "${BUILD_PATH}/gen_languages" "${moduleOutPath}/languages"
fi
}
copyModuleNcfToModules(){
moduleName=`getModuleItem "APP_NAME"`;
version=`getModuleItem "VERSION"`;
mainClass=`getModuleItem "MAIN_CLASS"`;
mainClassName=`awk -v s="${mainClass}" 'BEGIN{ len = split(s,ary,"."); print ary[len]}'`
moduleDynamicDependent=`getModuleItem "moduleDynamicDependent"`; #模块动态依赖
moduleBuildPath="${BUILD_PATH}/tmp/$1"
if [ ! -d "${moduleBuildPath}" ]; then
mkdir "${moduleBuildPath}"
fi
moduleNcf="${moduleBuildPath}/module.1.ncf";
if [ -f $moduleNcf ]; then
rm $moduleNcf
fi
touch $moduleNcf
cfgDomain=""
sedCommand="sed "
while read line
do
TEMP=`echo $line|grep -Eo '\[.+\]'`
if [ -n "$TEMP" ]; then
# echo "set cfg domain ${TEMP}"
cfgDomain=$TEMP
fi
if [ "${cfgDomain}" == "[JAVA]" -a ! -n "$TEMP" ];
then
pname=`echo $line | awk -F '=' '{print $1}'`
#pvalue=$(echo $line | awk -F '=' '{print $2}')
pvalue=`awk -v a="$line" '
BEGIN{
len = split(a,ary,"=")
r=""
for ( i = 2; i <= len; i++ ){
if(r != ""){
r = (r"=")
}
r=(r""ary[i])
}
print r
}
'`
if [ "${pname}" != "" ]; then
sedCommand+=" -e 's/%${pname}%/${pvalue}/g' "
fi
echo $line >> $moduleNcf
else
if [ "${cfgDomain}" != "[JAVA]" ]; then
echo $line >> $moduleNcf
fi
fi
done < ./module.ncf
#给模块添加动态依赖
dependent=
if [ -n "${moduleDynamicDependent}" ]; then
IFS=',' read -ra ddm <<< "${moduleDynamicDependent}"
for i in "${ddm[@]}"; do
isPackage=`hasPackageModule $i`
if [ "${isPackage}" == "1" ]; then
if [ -n "$dependent" ]; then
dependent="${dependent},"
fi
dependent="${dependent}${i}"
fi
done
if [ -n "$dependent" ];
then
log "dynamic dependent : $dependent"
echo "dependent=$dependent" >> $moduleNcf
fi
fi
# merge common module.ncf and private module.ncf to module.tmep.ncf
"${PROJECT_PATH}/build/merge-ncf" "${BUILD_PATH}/module-prod.ncf" $moduleNcf $moduleName
# rm $moduleNcf
sedCommand+=" -e 's/%MAIN_CLASS_NAME%/${mainClassName}/g' "
# echo $sedCommand
if [ -z `echo "${sedCommand}" | grep -o "%JOPT_XMS%"` ]; then
sedCommand="${sedCommand} -e 's/%JOPT_XMS%/256/g' "
fi
if [ -z `echo "${sedCommand}" | grep -o "%JAVA_OPTS%"` ]; then
sedCommand="${sedCommand} -e 's/%JAVA_OPTS%//g' "
fi
if [ -z `echo "${sedCommand}" | grep -o "%JOPT_XMX%"` ]; then
sedCommand="${sedCommand} -e 's/%JOPT_XMX%/256/g' "
fi
if [ -z `echo "${sedCommand}" | grep -o "%JOPT_METASPACESIZE%"` ]; then
sedCommand="${sedCommand} -e 's/%JOPT_METASPACESIZE%/128/g' "
fi
if [ -z `echo "${sedCommand}" | grep -o "%JOPT_MAXMETASPACESIZE%"` ]; then
sedCommand="${sedCommand} -e 's/%JOPT_MAXMETASPACESIZE%/256/g' "
fi
if [ -d "./script" ];
then
for file in `ls ./script`
do
nowPath=`pwd`
eval "${sedCommand} ${nowPath}/script/${file} > ${moduleBuildPath}/${file}"
cp "${moduleBuildPath}/${file}" "${MODULES_PATH}/${moduleName}/${version}/${file}"
chmod u+x "${MODULES_PATH}/${moduleName}/${version}/${file}"
echo "copy ${moduleBuildPath}/${file} to ${MODULES_PATH}/${moduleName}/${version}/${file}"
done
else
startSh="${BUILD_PATH}/start-temp"
startBat="${BUILD_PATH}/start-temp.bat"
stopSh="${BUILD_PATH}/stop-temp"
stopBat="${BUILD_PATH}/stop-temp.bat"
# echo $sedCommand
eval "${sedCommand} ${startSh} > ${moduleBuildPath}/start.sh"
cp "${moduleBuildPath}/start.sh" "${MODULES_PATH}/${moduleName}/${version}/start.sh"
chmod +x "${MODULES_PATH}/${moduleName}/${version}/start.sh"
echo "copy ${moduleBuildPath}/start.sh to ${MODULES_PATH}/${moduleName}/${version}/start.sh"
eval "${sedCommand} ${startBat} > ${moduleBuildPath}/start.bat"
cp "${moduleBuildPath}/start.bat" "${MODULES_PATH}/${moduleName}/${version}/start.bat"
# cp "${moduleBuildPath}/start.bat" "/Volumes/share/start.bat"
echo "copy ${moduleBuildPath}/start.bat to ${MODULES_PATH}/${moduleName}/${version}/start.bat"
eval "${sedCommand} ${stopSh} > ${moduleBuildPath}/stop.sh"
cp "${moduleBuildPath}/stop.sh" "${MODULES_PATH}/${moduleName}/${version}/stop.sh"
chmod +x "${MODULES_PATH}/${moduleName}/${version}/stop.sh"
echo "copy ${moduleBuildPath}/stop.sh to ${MODULES_PATH}/${moduleName}/${version}/stop.sh"
eval "${sedCommand} ${stopBat} > ${moduleBuildPath}/stop.bat"
cp "${moduleBuildPath}/stop.bat" "${MODULES_PATH}/${moduleName}/${version}/stop.bat"
#cp "${moduleBuildPath}/stop.bat" "/Volumes/share/stop.bat"
echo "copy ${moduleBuildPath}/stop.bat to ${MODULES_PATH}/${moduleName}/${version}/stop.bat"
fi
cp "${moduleBuildPath}/module.temp.ncf" "${MODULES_PATH}/${moduleName}/${version}/Module.ncf"
echo "copy ${moduleBuildPath}/module.temp.ncf to ${MODULES_PATH}/${moduleName}/${version}/Module.ncf"
}
#2.遍历文件夹,检查第一个pom 发现pom文件后通过mvn进行打包,完成后把文件jar文件和module.ncf文件复制到Modules文件夹下
packageModule() {
if [ ! -d "./$1" ]; then
return 0
fi
if [ "$1" == "tmp" ]; then
return 0
fi
cd ./$1
# echo `pwd`
# echo ${RELEASE_PATH}
if [ `pwd` == "${RELEASE_PATH}" ]; then
cd ..
return 0;
fi
nowPath=`pwd`
if [ -f "./module.ncf" ]; then
echoYellow "find module.ncf in ${nowPath}"
if [ ! -f "./pom.xml" ]; then
echoRed "模块配置文件必须与pom.xml在同一个目录 : ${nowPath}"
exit 0;
fi
moduleName=`getModuleItem "APP_NAME"`;
package=`hasPackageModule "$moduleName"`;
if [ "${package}" == "1" ];
then
checkModuleItem "APP_NAME" "$1"
checkModuleItem "VERSION" "$1"
checkModuleItem "MAIN_CLASS" "$1"
log "build $1"
copyJarToModules $1
copyModuleNcfToModules $1
managed=`getModuleItem "Managed"`;
if [ "${managed}" == "1" ]; then
managedModules[${#managedModules[@]}]="$moduleName"
fi
log "build $moduleName done"
else
rm -rf "$MODULES_PATH/${moduleName}"
echoYellow "$moduleName skip"
fi
cd ..
return 0
fi
for f in `ls`
do
packageModule $f
done
cd ..
}
#log "INSTALL REQUIRE MODULE"
#for fi in `ls`
#do
# installModule $fi
#done
log "PACKAGE MODULE"
for fi in `ls`
do
packageModule $fi
done
log "============ PACKAGE MODULES DONE ==============="
cd $PROJECT_PATH
moduleListFile=${MODULES_BIN_PATH}/.modules
#echo $moduleListFile
if [ -f "${moduleListFile}" ] ; then
rm -f $moduleListFile
fi
for module in ${managedModules[@]}
do
echo "$module" >> $moduleListFile
done
if [ -n "${JRE_HOME}" ]; then
log "============ COPY JRE TO libs ==================="
if [ ! -d "${JRE_HOME}" ];
then
echoRed "JRE_HOME 必须是文件夹"
else
log "JRE_HOME IS ${JRE_HOME}"
LIBS_PATH="${RELEASE_PATH}/Libraries"
if [ ! -d "${LIBS_PATH}" ]; then
mkdir ${LIBS_PATH}
fi
if [ ! -d "${LIBS_PATH}/JAVA" ]; then
mkdir "${LIBS_PATH}/JAVA"
fi
if [ ! -d "${LIBS_PATH}/JAVA/JRE" ]; then
mkdir "${LIBS_PATH}/JAVA/JRE"
fi
rm -Rf "${LIBS_PATH}/JAVA/JRE/11.0.2"
cp -r ${JRE_HOME} "${LIBS_PATH}/JAVA/JRE/11.0.2"
fi
log "============ COPY JRE TO libs done ============"
fi
log "================ COPY SCRIPT ==============="
eval "sed -e 's/%PACKAGE_VERSION%/${PACKAGE_VERSION}/g' ${NULS_NCF} > ${MODULES_BIN_PATH}/nuls.ncf"
cp $GENESIS_BLOCK ${MODULES_BIN_PATH}/genesis-block.json
cp "${BUILD_PATH}/cmd" "${MODULES_BIN_PATH}/"
cp "${BUILD_PATH}/cmd.bat" "${MODULES_BIN_PATH}/"
chmod u+x "${MODULES_BIN_PATH}/cmd"
cp "${BUILD_PATH}/create-address" "${MODULES_BIN_PATH}/"
chmod u+x "${MODULES_BIN_PATH}/create-address"
cp "${BUILD_PATH}/test" "${MODULES_BIN_PATH}/"
chmod u+x "${MODULES_BIN_PATH}/test"
cp "${BUILD_PATH}/func" "${MODULES_BIN_PATH}/"
chmod u+x "${MODULES_BIN_PATH}/func"
tempModuleList=
for m in ${managedModules[@]}
do
tempModuleList+=" \"${m}\""
done
eval "sed -e 's/%MODULES%/${tempModuleList}/g' ${BUILD_PATH}/check-status > ${BUILD_PATH}/tmp/check-status-temp"
cp "${BUILD_PATH}/tmp/check-status-temp" "${MODULES_BIN_PATH}/check-status"
chmod u+x "${MODULES_BIN_PATH}/check-status"
cp ${PROJECT_PATH}/version ${MODULES_BIN_PATH}/version
log "=============== COPY SCRIPT DONE ==========="
DOMOCK=`hasPackageModule "mykernel"`
if [ -n "${DOMOCK}" ]; then
log "============== BUILD start-dev script ====================="
cp "${BUILD_PATH}/start-mykernel" "${MODULES_BIN_PATH}/start-dev"
chmod u+x "${MODULES_BIN_PATH}/start-dev"
cp "${BUILD_PATH}/stop-mykernel" "${MODULES_BIN_PATH}/stop-dev"
chmod u+x "${MODULES_BIN_PATH}/stop-dev"
log "============== BUILD start-dev script done ================"
fi
#临时删除window版本未实现的脚本
if [ "$TARGET_OS" == "window" ]; then
rm -f "${MODULES_BIN_PATH}/start-dev"
rm -f "${MODULES_BIN_PATH}/stop-dev"
rm -f "${MODULES_BIN_PATH}/check-status"
rm -f "${MODULES_BIN_PATH}/test"
rm -f "${MODULES_BIN_PATH}/create-address"
fi
if [ -n "${BUILDTAR}" ]; then
log "============ BUILD ${RELEASE_PATH}.tar.gz ==================="
tar -zcPf "${NULS_WALLET_TAR_NAME}_${TARGET_OS}.tar.gz" ${NULS_WALLET_TAR_NAME}
log "============ BUILD ${NULS_WALLET_TAR_NAME}_${TARGET_OS}.tar.gz FINISH==================="
fi
cd $PROJECT_PATH
echo "package version : $PACKAGE_VERSION"
log "============ ${RELEASE_PATH} PACKAGE FINISH 🍺🍺🍺🎉🎉🎉 ==============="