替换JAR包中的文件

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
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值