本文已参与「开源摘星计划」,欢迎正在阅读的你加入。活动链接:https://github.com/weopenprojects/WeOpen-Star
build_release.sh 用于编译chainmaker-go
模块,并打包生成安装
该脚本在 chainmaker-go 的 scripts 目录下
执行方法./build_release.sh
该脚本执行过程如下:
1.check_env
检查环境变量
function check_env() {
if [ ! -d $BUILD_CONFIG_PATH ] ;then
echo $BUILD_CONFIG_PATH" is missing"
exit 1
fi
if [ ! -d $BUILD_CRYPTO_CONFIG_PATH ] ;then
echo $BUILD_CRYPTO_CONFIG_PATH" is missing"
exit 1
fi
}
复制代码
BUILD_CONFIG_PATH 目录是项目目录下的 build/config 目录
BUILD_PATH=${PROJECT_PATH}/build
BUILD_CONFIG_PATH=${BUILD_PATH}/config
复制代码
首先检查该目录是否存在,如果不存在直接报错退出了
其次,再检查 $BUILD_CRYPTO_CONFIG_PATH"目录
BUILD_CRYPTO_CONFIG_PATH=${BUILD_PATH}/crypto-config
复制代码
该目录是项目路的 build/crypto-config
用于存放加密相关的配置目录,如果该目录不存在则直接报错退出
2.build
编译构建,该命令是进入到项目目录,直接调用 make 命令编译源代码,生成二进制包了。
function build() {
cd $PROJECT_PATH
echo "build chainmaker ${PROJECT_PATH}..."
make
}
复制代码
3.pacakge
打包
该方法脚本比较长,我们一段段分析:
如果 release 目录存在,创建一个备份目录,并把 release 目录移动到备份目录下面
第一次打包的时候,一般不会存在,所以不会执行该逻辑
if [ -d $RELEASE_PATH ]; then
mkdir -p $BACKUP_PATH/backup_release
mv $RELEASE_PATH $BACKUP_PATH/backup_release/release_$(date "+%Y%m%d%H%M%S")
fi
复制代码
创建 release 目录,进入到该目录下,执行 tar 命令把 crypto-config 打包成一个压缩包
mkdir -p $RELEASE_PATH
cd $RELEASE_PATH
echo "tar zcf crypto-config..."
tar -zcf crypto-config-$DATETIME.tar.gz ../crypto-config
复制代码
下面的脚本,就是看有几个加密目录,就循环几次。
每次都创建一个对应的目录
然后创建下面对应的 bin,config 等目录。
然后把之前编译好的 chanmerker 还有一些脚本拷贝到对应目录。
然后根据不同的操作系统拷贝一些 lib
最后进行打包
c=0
for file in `ls -tr $BUILD_CRYPTO_CONFIG_PATH`
do
c=$(($c+1))
chainmaker_file=chainmaker-$VERSION-$file
mkdir $chainmaker_file
mkdir $chainmaker_file/bin
mkdir $chainmaker_file/lib
mkdir -p $chainmaker_file/config/$file
mkdir $chainmaker_file/log
cp $PROJECT_PATH/bin/chainmaker $chainmaker_file/bin
cp $CURRENT_PATH/bin/start.sh $chainmaker_file/bin
cp $CURRENT_PATH/bin/stop.sh $chainmaker_file/bin
cp $CURRENT_PATH/bin/restart.sh $chainmaker_file/bin
cp $CURRENT_PATH/bin/docker-vm-standalone-start.sh $chainmaker_file/bin
cp $CURRENT_PATH/bin/docker-vm-standalone-stop.sh $chainmaker_file/bin
cp $CURRENT_PATH/service/* $chainmaker_file/bin
if [ "${system}" = "Linux" ]; then
cp -r $PROJECT_PATH/main/libwasmer_runtime_c_api.so $chainmaker_file/lib/libwasmer.so
cp -r $PROJECT_PATH/main/prebuilt/linux/wxdec $chainmaker_file/lib/
else
cp -r $PROJECT_PATH/main/libwasmer.dylib $chainmaker_file/lib/
cp -r $PROJECT_PATH/main/prebuilt/mac/wxdec $chainmaker_file/lib/
fi
chmod 644 $chainmaker_file/lib/*
chmod 700 $chainmaker_file/lib/wxdec
chmod 700 $chainmaker_file/bin/*
cp -r $BUILD_CONFIG_PATH/node$c/* $chainmaker_file/config/$file
xsed "s%{org_id}%$file%g" $chainmaker_file/bin/start.sh
xsed "s%{org_id}%$file%g" $chainmaker_file/bin/stop.sh
xsed "s%{org_id}%$file%g" $chainmaker_file/bin/restart.sh
xsed "s%{org_id}%$file%g" $chainmaker_file/bin/run.sh
echo "tar zcf ${chainmaker_file}..."
tar -zcf chainmaker-$VERSION-$file-$DATETIME-$PLATFORM.tar.gz $chainmaker_file
rm -rf $chainmaker_file
done
复制代码
评论