婚庆网站建设必要性,合肥公司注册地址,什么网址可以玩大型游戏,seo外链网需求背景#xff1a;
在实际项目时我们很少把源码用个tar给到客户#xff0c;这样显得很不专业#xff0c;且有的时候我们提供补丁#xff0c;那么这个时候我们提供一个补丁的bin包可以直接安装运行就显得很高大上了。
物料准备
准备一台liunx#xff0c;虚拟机亦可
在实际项目时我们很少把源码用个tar给到客户这样显得很不专业且有的时候我们提供补丁那么这个时候我们提供一个补丁的bin包可以直接安装运行就显得很高大上了。
物料准备
准备一台liunx虚拟机亦可我当前使用的是Debian10
创建目录
mkdir Demo_build_bin
cd Demo_build_bin准备打包脚本
主要原理就是将我们的安装脚本和源码文件封装一个可以执行的文件里面xxx.bin 运行脚本时先把源码文件提取出来进行对应的操作
vim build_bin.sh
#!/bin/sh -e
DIR$(dirname readlink -f $0)
version$1
if [ ! $version ]; thenecho Please enter version infoexit -1
fi
git_versiongit log -n1 --pretty%H | cut -c 1-11
if [ ! $git_version ] ; thenecho Please enter git versiongit_version123456#exit -1
fi
if [ -e source_install.tar ]; thenrm source_install.tar
fi
echo ${DIR}
pushd $DIR
if [ -e ./source_install.tar ];thenecho rm ./source_install.tarrm ./source_install.tar
fi
tar -zcf source_install.tar ./source_installbuild_exe(){
architecturearch
timedate %Y%m%d
md5_source$(md5sum source_install.tar | awk {print $1})
file_nameDemo_V${version}_${architecture}_Debian10_${time}_Git${git_version}.bin
sed -e s/%%source_md5%%/$md5_source/ ./install.sh $file_name
cat source_install.tar ${file_name}
chmod x ${file_name}
echo Source md5 : $md5_source
echo New install bin file generated: ${file_name}
}
if [ $? -ne 0 ];thenecho Package fusionnos cli fail
elsebuild_exepopd
fi准备源码目录
mkdir source_install
cd source_install
echo hello world!! hello_world将hello_world文件拷贝到opt目录
编辑install.sh脚本用于执行xxx.bin包
#!/bin/sh -e
outnamepwd
tail -n 25 $0 $outname/source_install.tar
source_md5%%source_md5%%
echo Source md5 : $source_md5
md5_sourcemd5sum source_install.tar | awk { print $1 }
if [ $md5_source ! $source_md5 ];thenechoecho ERROR: Unable to verify source archive checksumecho Expected: $md5_sourceecho Found : $source_md5exit 1
elseecho Md5 verify pass!
fiecho Unzip fusionnos cli dependences
tar -xvf source_install.tar /dev/nul
cd ./source_install
cp ./hello_world /opt
cd ..
rm -rf source_install source_install.tar
echo Install complete!
exit 0打包
这里我们对生成的文件进行了md5验证放置在文件的传输过程中或者安装过程中损坏了
root:/home/tiger/Study/Demo_build_bin# ./build_bin.sh 1.0
/home/tiger/Study/Demo_build_bin
/home/tiger/Study/Demo_build_bin /home/tiger/Study/Demo_build_bin
Source md5 : 829bd47bca2856081b27768c984230b0
New install bin file generated: Demo_V1.0_aarch64_Debian10_20231206_Git123456.bin
/home/tiger/Study/Demo_build_bin执行查看效果
./Demo_V1.0_aarch64_Debian10_20231206_Git123456.bin
rootfusionnos:/home/tiger/Study/Demo_build_bin/test# ls /opt/hello_word
/opt/hello_word