linux gradle java增量打包工具

时间:2022-05-31 15:53:35
#!/bin/sh
if [ ! -f "/root/upspace/list.txt" ];then
    echo "ERROR:/root/upspace/list.txt不存在"
        exit 1;
fi

if [ $# -ne 1 ];
then
   echo "usage:$1 升级包名称"
   exit 1;
fi

basecode="/opt/src/shop/mmhlive-com"
cd ${basecode}
git checkout master
git clean -dfx ""
git stash
git pull
gradle clean war
cd -
lcount=`cat /root/upspace/list.txt|wc -l`
if [ $lcount -lt 1 ];then
      echo "文件内容不合法!$lcount"
      exit 1;
fi
basecode="/opt/src/shop/mmhlive-com"
echo ${darr[$i]}
echo "数据清洗"

cp /root/upspace/list.txt /root/upspace/list.txt.src
a1='\\'
a2='\/'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.src
sed -i 's/\r//g' /root/upspace/list.txt.src

a1='\.java'
a2='\.class'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.src

a1='src\/main\/java'
a2='build\/classes\/main'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.src

a1='src\/main\/resources'
a2='build\/resources\/main'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.src

rm -f /root/upspace/list.txt.dest
cp /root/upspace/list.txt.src /root/upspace/list.txt.dest

echo "生成html和ftl文件打包路径"
a1='ejavashop-seller\/src\/main\/webapp\/WEB-INF'
a2='mmhlive.com\/eshop\/seller\/webapps\/ROOT\/WEB-INF'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-h5\/src\/main\/webapp\/WEB-INF'
a2='mmhlive.com\/eshop\/h5\/webapps\/ROOT\/WEB-INF'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-front\/src\/main\/webapp\/WEB-INF'
a2='mmhlive.com\/eshop\/front\/webapps\/ROOT\/WEB-INF'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-admin\/src\/main\/webapp\/WEB-INF'
a2='mmhlive.com\/eshop\/admin\/webapps\/ROOT\/WEB-INF'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

echo "生成js和css文件打包路径"
a1='ejavashop-seller\/src\/main\/webapp\/static'
a2='mmhlive.com\/eshop\/seller\/webapps\/ROOT\/static'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-h5\/src\/main\/webapp\/static'
a2='mmhlive.com\/eshop\/h5\/webapps\/ROOT\/static'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-front\/src\/main\/webapp\/static'
a2='mmhlive.com\/eshop\/front\/webapps\/ROOT\/static'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-admin\/src\/main\/webapp\/static'
a2='mmhlive.com\/eshop\/admin\/webapps\/ROOT\/static'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

echo "生成xml打包路径"
a1='ejavashop-seller\/build\/resources\/main'
a2='mmhlive.com\/eshop\/seller\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-h5\/build\/resources\/main'
a2='mmhlive.com\/eshop\/h5\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-front\/build\/resources\/main'
a2='mmhlive.com\/eshop\/front\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-admin\/build\/resources\/main'
a2='mmhlive.com\/eshop\/admin\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-service-impl\/build\/resources\/main'
a2='mmhlive.com\/eshop\/core\/webapps\/eshopcore\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

echo "生成class打包路径"
a1='ejavashop-seller\/build\/classes\/main'
a2='mmhlive.com\/eshop\/seller\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-h5\/build\/classes\/main'
a2='mmhlive.com\/eshop\/h5\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-front\/build\/classes\/main'
a2='mmhlive.com\/eshop\/front\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-admin\/build\/classes\/main'
a2='mmhlive.com\/eshop\/admin\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

a1='ejavashop-service-impl\/build\/classes\/main'
a2='mmhlive.com\/eshop\/core\/webapps\/eshopcore\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest


a1='ejavashop-service\/build\/classes\/main'
a2='mmhlive.com\/eshop\/api\/webapps\/ROOT\/WEB-INF\/classes'
sed -i "s/$a1/$a2/g" /root/upspace/list.txt.dest

darr=()
#声明整型
i=0
for dfile in `cat /root/upspace/list.txt.dest`
do
    darr[$i]=$dfile
    ((i++));        
done

echo "开始打包class文件"
i=0
destpath=/root/upspace/`date '+%Y-%m-%d_%H_%M_%S'`
mkdir -p $destpath
echo "打包目的地$destpath"
echo "------------------------------"
for file in `cat /root/upspace/list.txt.src`
do
    fullpath=${destpath}/${darr[$i]}
    srcpath=${basecode}/$file
    echo "开始处理`basename $srcpath`"
    echo $srcpath
    echo $fullpath
    mkdir -p $fullpath
    rm -rf $fullpath
    cp $srcpath $fullpath
    ((i++));        
done
echo "-------------------------------"
echo "开始打升级包"

if [ -d "${destpath}/mmhlive.com/eshop/api" ];then
    cd ${destpath}/mmhlive.com/eshop
    echo "处理API"
    mkdir {admin,seller,front,core,h5}
    cp -r api/* admin
    cp -r api/* seller
    cp -r api/* front
    cp -r api/* h5
        cp -r api/webapps/ROOT/* core/webapps/eshopcore
fi

cd $destpath
zipname=`basename $destpath`--$1
zip -r ../${zipname}.zip ./mmhlive.com/*
echo "升级包路径:`pwd`/${zipname}.zip"
echo "打包完毕,清理临时文件"
rm -Rf $destpath
#rm -f /root/upspace/list.txt.dest

linux gradle java增量打包工具