linux中用shell脚本自动管理版本号
程序员文章站
2022-06-22 20:11:53
为了统一管理版本,在编译之前调用shell脚本将版本号进行解析然后以jason 文件的格式保存。脚本源码:#/bin/bash# find current dircd ..version_dir=`pwd`echo $version_dir# version file Dirversion_file_dir="${version_dir}/bin/version"# Find the version number and assign if [ -f ${UfnNcm_ver....
为了统一管理版本,在编译之前调用shell脚本将版本号进行解析然后以jason 文件的格式保存。
脚本源码:
#/bin/bash
# find current dir
cd ..
version_dir=`pwd`
echo $version_dir
# version file Dir
version_file_dir="${version_dir}/bin/version"
# Find the version number and assign
if [ -f ${UfnNcm_version_dir} ];then
echo "${UfnNcm_version_dir} exist"
else
echo "${UfnNcm_version_dir} not exist"
fi
UfnNcm_versionNumber=`sed -nr '/Version/p' "$UfnNcm_version_dir" | sed -n '/Version/p' | sed -n 's/const char Version\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "UfnNcm Version Number:$UfnNcm_versionNumber"
if [ -f ${NupService_version_dir} ];then
echo "$NupService_version_dir exist"
else
echo "$NupService_version_dir not exist"
fi
NupService_versionNumber=`sed -nr '/sysversion/p' "$NupService_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = "NUPService //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "NupService version number: $NupService_versionNumber"
if [ -f ${ModbusService_version_dir} ];then
echo "$ModbusService_version_dir exist"
else
echo "$ModbusService_version_dir not exist"
fi
ModbusService_versionNumber=`sed -nr '/sysversion/p' "$ModbusService_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "ModbusService version number:$ModbusService_versionNumber"
if [ -f ${OnyxSyncClockService_version_dir} ];then
echo "$OnyxSyncClockService_version_dir exist"
else
echo "$OnyxSyncClockService_version_dir not exist"
fi
OnyxSyncClockService_versionNumber=`sed -nr '/sysversion/p' "$OnyxSyncClockService_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "OnyxSyncClockService version number:$OnyxSyncClockService_versionNumber"
if [ -f ${SerialPortSyncColckService_version_dir} ];then
echo "$SerialPortSyncColckService_version_dir exist"
else
echo "$SerialPortSyncColckService_version_dir not exist"
fi
SerialPortSyncColckService_versionNumber=`sed -nr '/sysversion/p' "$SerialPortSyncColckService_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "SerialPortSyncClockService version number:$SerialPortSyncColckService_versionNumber"
if [ -f ${SNTPSyncClockService_version_dir} ];then
echo "$SNTPSyncClockService_version_dir exist"
else
echo "$SNTPSyncClockService_version_dir not exist"
fi
SNTPSyncClockService_versionNumber=`sed -nr '/sysversion/p' "$SNTPSyncClockService_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "Sntpsync version number:$SNTPSyncClockService_versionNumber "
if [ -f ${CrtPrinter_version_dir} ];then
echo "$CrtPrinter_version_dir exist"
else
echo "$CrtPrinter_version_dir not exist"
fi
CrtPrinter_versionNumber=`sed -nr '/sysversion/p' "$CrtPrinter_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "crt version number:$CrtPrinter_versionNumber"
if [ -f ${PeripheralDeviceManage_version_dir} ];then
echo "$PeripheralDeviceManage_version_dir exist"
else
echo "$PeripheralDeviceManage_version_dir not exist"
fi
PeripheralDeviceManage_versionNumber=`sed -nr '/sysversion/p' "$PeripheralDeviceManage_version_dir" | sed -n '/sysversion/p' | sed -n 's/const char sysversion\[\] = //gp' | sed -n 's/;//gp' | sed -n 's/"//gp'`
echo "PeripheralDeviceManage version number:$PeripheralDeviceManage_versionNumber"
# Modify the version number in the version file
if [ -f ${version_file_dir} ];then
echo "${version_file_dir} exist"
else
echo "${version_file_dir} not exist"
fi
jq '.[1].version="'${UfnNcm_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[2].version="'${NupService_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[3].version="'${ModbusService_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[4].version="'${OnyxSyncClockService_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[5].version="'${SerialPortSyncColckService_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[6].version="'${SNTPSyncClockService_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[7].version="'${CrtPrinter_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
jq '.[8].version="'${PeripheralDeviceManage_versionNumber}'"' ${version_file_dir} | sponge ${version_file_dir}
将修改的保存的,需要安装moreutils 包,使用apt-get install moreutils, 安装后,使用指令 sponge 命令保存到磁盘。
可以正常运行,在调用shell脚本自动更新版本号到文档。
本文地址:https://blog.csdn.net/qq_25145647/article/details/108184060
上一篇: 一些小知识总结(虽然可能没用)
下一篇: 烧写uboot的三种方式
推荐阅读
-
Linux下使用Shell脚本实现ftp的自动上传下载的代码小结
-
Linux下实现SSH免密码登录和实现秘钥的管理、分发、部署SHELL脚本分享
-
linux和windows下的自动ftp脚本(shell bat)
-
linux下自动备份MySQL数据并上传到FTP上的shell脚本
-
linux下实现ftp自动备份shell脚本
-
Linux下shell脚本监控Tomcat的状态并实现自动启动的步骤
-
Shell脚本实现在Linux系统中自动安装JDK
-
linux下mysql如何自动备份shell脚本
-
Linux系统防CC攻击自动拉黑IP增强版(Shell脚本)
-
Linux VPS服务器依据系统资源自动重启bash shell脚本