bin/checkFileSize
#!/bin/bash
# checkFileSize
#
# Purpose:
#
# Description:
#
# History:
# Tue Jan 3 14:41:15 TST 2012, Created by jumperchen
#
#Copyright (C) 2012 Potix Corporation. All Rights Reserved.
#
if [ $# != 2 ] && [ $# != 4 ] ; then
echo Please specify two files or two folders
echo for example,
echo ./bin/checkFileSize folder1 folder2
echo To replace version number in each file/folder, put version number in front of the file/folder names
echo for example,
echo ./bin/checkFileSize 6.0.0 folder1 6.0.1 folder2
exit 1
fi
if [ $# != 4 ] ; then
folder1=$1
folder2=$2
else
ver1=$1
folder1=$2
ver2=$3
folder2=$4
fi
if [ ! -d "$folder1" ] && [ ! -f "$folder1" ] ; then
echo $folder1 is not a file or folder
exit 1
fi
if [ ! -d "$folder2" ] && [ ! -f "$folder2" ] ; then
echo $folder2 is not a file or folder
exit 1
fi
maindir="$(pwd)"
tmpdir="$maindir"
os="$(uname)"
if [ $os == "Darwin" ]; then
tmpdir=$TMPDIR
fi
tmp1="checktmp1"
tmp2="checktmp2"
if [ $(basename "$folder1") = "maven" ] && [ $(basename "$folder2") = "maven" ] ; then
isMaven="true"
else
isMaven="false"
fi
function checkFileSize {
echo $(pwd)/$1
if [ -d $1 ] ; then
cd $1
fi
du -ah * >> $tmpdir/$2.log
}
function checkFileSizeMaven {
if [ -d $maindir/tmp ] ; then
rm -rf $maindir/tmp
fi
mkdir $maindir/tmp
cp -r $1 $maindir/tmp
cd $maindir/tmp
unzipJar
cd $maindir/tmp
du -ah * >> $tmpdir/$2.log
rm -rf $maindir/tmp
}
function unzipJar {
for f in `ls | sort`; do
if [ -f "$f" ] ; then
if [ "$(echo "$f" | awk '/jar$/{print "yes"}')" = "yes" ] ; then
tmpDir=$(pwd)/$(basename "$f" .jar)
mkdir $tmpDir
unzip $f -d $tmpDir
rm -rf $f
else
cp $f $maindir/tmp
fi
elif [ -d "$f" ] ; then
cd $f
unzipJar
cd -
fi
done
}
if [ -f "$maindir/$tmp1.log" ] ; then
rm $maindir/$tmp1.log
fi
if [ -f "$maindir/$tmp2.log" ] ; then
rm $maindir/$tmp2.log
fi
if [ -d "$maindir/tmp" ] ; then
rm -rf $maindir/tmp
fi
if [ "$isMaven" = "true" ] ; then
checkFileSizeMaven "$folder1" "$tmp1"
checkFileSizeMaven "$folder2" "$tmp2"
else
checkFileSize "$folder1" "$tmp1"
checkFileSize "$folder2" "$tmp2"
fi
cd $tmpdir
if [ $# != 2 ] ; then
sed -i "s/$ver1/{VER}/g" $tmp1.log
sed -i "s/$ver2/{VER}/g" $tmp2.log
fi
sort -n $tmp1.log -o $tmp1.log
sort -n $tmp2.log -o $tmp2.log
diff $tmp1.log $tmp2.log
if [ $? != 0 ] ; then
if [ -f TortoiseMerge.exe ] ; then
TortoiseMerge.exe $tmp1.log $tmp2.log
elif [ $os == "Darwin" ]; then
opendiff $tmp1.log $tmp2.log
else
vimdiff $tmp1.log $tmp2.log
fi
else
echo "All files are matched!"
fi
if [ $os != "Darwin" ]; then
rm $tmp1.log
rm $tmp2.log
fi