该方法将shell脚本和二进制压缩程序包融合在一个文件中,只需在系统中执行该文件即可,执行后,会自动分离出二进制压缩程序包,并根据shell脚本完成程序和文件的覆盖和安装。
如下测试在ubuntu22.04中测试和构建:
目标:构建一个安装文件InstallTestFile.bin,该安装文件可直接在系统中运行,自行解压资源并安装和覆盖程序到目录/myfile中,其中安装的资源文件为resource.tar.gz,shell脚本为test.sh,使用命令cat test.sh resource.tar.gz > InstallTestFile.bin合并。
test.sh脚本如下:
#!/bin/bash
sed -n '1,/^exit 0$/!w resource.tar.gz' $0
APP_TOP_PATH=/myfile
mkdir -p $APP_TOP_PATH
tar -zxvf resource.tar.gz -C $APP_TOP_PATH
# do other operation you want
sync
echo "success"
sleep 3
exit 0
使用cat test.sh resource.tar.gz > InstallTestFile.bin 合并构建安装程序InstallTestFile.bin
安装执行./InstallTestFile.bin 即可。