替换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
}

你可能感兴趣的:(jar包)