替换JAR包中的文件

编程技术  /  houtizong 发布于 3年前   136
scriptHome=`pwd`
legoPlatHome=$scriptHome/LEGO_V100R001
echo  $scriptHome > scriptHome
echo  $legoPlatHome > legoPlatHome
log=$scriptHome/changelog


debug()
{
    echo $1 >> $log
}

showMessage()
{
    echo $1
    debug $1
}

checkFile()
{
    if [ $# != 1 ]
    then
       debug "please check the input file parameter !!!!!!!!!!!!!!"
       return 1;
    fi;
    
   

    if [ ! -f $1 ]
    then
         debug "please check $1 !!!!!!!!!!!!!!!!"
         return 1;
    fi;

    return 0;
}

checkDir()
{
    if [ $# != 1 ]
    then
       debug "please check the input dir parameter !!!!!!!!!"
       return 1;
    fi;

    if [ ! -d $1 ]
    then
         debug "please check $1 !!!!!!!!!!!!!!!!"
         return 1;
    fi;

    return 0;
}

#1 new , 2 old
checkTwoFile()
{
    if [ $# != 2 ]
    then
       debug "please check the input two file parameter !!!!!!!!!!"
       return 1;
    fi;

    diff $1 $2

   if [ $? != 0 ]
   then
      debug "the two file  $1 $2  are different,please check $1 !!!!!!!!!!!!!!!!! "
      return 1;
   fi;
}

#$1 the ism replace file's dir,$2 the file name,$3 LEGO dir
replaceFile()
{
    if [ ! -f $1/$2 ]
    then
        debug "Please check the file. $1/$2 does exist."
return 1
    fi;

    if [ ! -f $1/$2_old ]
    then
        debug "Please check the file. $1/$2_old does exist."
return 1
    fi;

    if [ ! -f $3/$2 ]
    then
        debug "Please check the file. $3/$2 does exist."
return 1
    fi;

    checkTwoFile $3/$2 $1/$2_old
    cp $1/$2 $3
}

getScriptHome()
{
    return `pwd`
}

getlegoPlatHome()
{
    scriptHome=getScriptHome
    return $scriptHome/LEGO_V100R001
}

tmpDir=/opt/`date +'%Y%m%d%I%M%S'`
export tmpDir

initJar()
{
    if [ -d $tmpDir ]
    then
        debug "The dir exists,it should be empty,please modify the scripty."
        exit 1;
    fi;

    mkdir $tmpDir

    if [ ! -f $1 ]
    then
        debug "Please check the file exists $1."
exit 1
    fi;

    if [ ! -f $2 ]
    then
         debug "Please check the file exists $2."
         exit 1
    fi;
    bundleName=`echo $2 | awk -F / '{print $NF}'`

    debug "begin to change $bundleName."

    unzip $2 -d $tmpDir > /dev/null 2>&1
}

zipFile()
{
bundleName=`echo $1 | awk -F / '{print $NF}'`
cd $tmpDir

zip -r $bundleName * > /dev/null 2>&1
bundleDir=`dirname $1`
debug "copy $bundleName to $bundleDir"
mv $bundleName $bundleDir
rm -rf $tmpDir
        debug "finish to change $bundleName."

cd $scriptHome
}

replaceFileInJar()
{
   
    replaceFileName=`echo $1 | awk -F / '{print $NF}'`

    bundleName=`echo $2 | awk -F / '{print $NF}'`

    for f in `find $tmpDir -name $replaceFileName`
    do
        debug "copying the $replaceFileName to $f"
        cp $1 $f
    done;
  
     zipFile $2

}

replaceFileInJarAll()
{
    initJar $1 $2
    replaceFileInJar $1 $2
}

#$1 file , $2 bundle, $3 old file
compareRepalceFileInJar()
{
initJar $1 $2
replaceFileName=`echo $1 | awk -F / '{print $NF}'`

        for f in `find $tmpDir -name $replaceFileName`
        do
checkTwoFile $f $3
if [ $? = 0 ]
then
debug "copying the $replaceFileName to $f"
cp $1 $f
fi;
        done;

       zipFile $2
}

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

留言需要登陆哦

技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成

网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];

      订阅博客周刊 去订阅

文章归档

文章标签

友情链接

Auther ·HouTiZong
侯体宗的博客
© 2020 zongscan.com
版权所有ICP证 : 粤ICP备20027696号
PHP交流群 也可以扫右边的二维码
侯体宗的博客