欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

相关标签: shell