shellスクリプトjarパッケージのClassファイルを一括置換
2575 ワード
次はshellスクリプトのjarパッケージのClassファイルの一括置換です.
#!/bin/sh
#JAVA home path set
JAVA_HOME=/usr/local/web/fit/WAS/install/61x/java
export PATH=${PATH}:${JAVA_HOME}/bin
#param 1 is jar file path. Sample path: /root/jar/app.jar
appJar=$1
#param 2 is folder path which stores class files. Sample path: /root/classfiles
filesTobeUpdated=$2
tempDir=$filesTobeUpdated/temp
echo "delete temp directory"
if [ -d $tempDir ]
then
rm -rf $tempDir
fi
echo "create temp file path:"$path
mkdir $tempDir
for i in `ls -l $filesTobeUpdated|grep ^- | awk '{print $9}'`
do
echo "finding file:"$i
path=""
num=0
for j in `jar tf $appJar`
do
if [ `echo $j |grep -c $i` -gt 0 ];then
echo "found file"
path="$path
$j"
num=`expr $num + 1`
if [ $num -eq 1 ];then
pathForNum1=$j
fi
fi
done
echo $num
if [ $num -gt 1 ];then
fileNum=0
while [ $fileNum != 1 ]
do
echo "$path"
echo "More than 1 file matched, input filePath:"
read filePath
fileNum=`jar tf $appJar $filePath | wc -l`
#for k in `jar tf $appJar`
#do
# if [ `echo $k |grep -c $filePath` -gt 0 ];then
# fileNum=`expr $fileNum + 1`
# fi
#done
done
path=$filePath
elif [ $num == 0 ]; then
echo "Looks like this is newly added file, input filePath:"
read filePath
echo $filePath
path=$filePath
else
path=$pathForNum1
fi
cd $tempDir
pathCut=$path
while [ `echo $pathCut |grep -c '/'` -gt 0 ]
do
element=`echo $pathCut | awk -F '/' '{print $1}'`
if [ ! -d $element ]
then
echo "directory is not exist, create:"$element
mkdir $element
fi
cd $element
pathCut=${pathCut#*/}
echo "pathCut is:"$pathCut
done
cp -f $filesTobeUpdated/$pathCut $tempDir/$path
cd $tempDir
jar uf $appJar $path
echo "replace done"
done
echo "delete temp directory"
if [ -d $tempDir ]
then
rm -rf $tempDir
fi