#!/bin/sh
#获取git中两版本间发生变动的文件列表(区间 前$1开 后$2闭)
git_files=($(git log --pretty=format:"" --name-only "$1..$2"))
#待打包文件列表(空格分割)
res_files=""
# 重复文件列表
repeat_files=()
ignore_files=(shopxx.xml shopxx.properties pom.xml)
# tomcat部署的项目路径
web_dir="/home/wcq/projects/gj/src/main/webapp"
work_dir=$PWD
cd $web_dir
#处理文件,找到需要打包的文件
for ss in ${git_files[@]}; do
#去掉重复的文件: 采取如下遍历方案
for ss_repeat in ${repeat_files[@]}; do
if [[ $ss_repeat == $ss ]]; then
# echo "重复:"$ss
ss=""
break
fi
done
repeat_files=(${repeat_files[@]} $ss)
#过滤掉不想打包的文件
for ss_ignore in ${ignore_files[@]}; do
if [[ $ss == */$ss_ignore ]]; then
#echo "排除:"$ss;
ss=""
break
fi
done
#开始处理文件路径
# 页面文件(jsp、ftl、js、css、图片等等)
if [[ $ss == src/main/webapp/* ]]; then
ss=$(echo $ss | sed 's/^src\/main\/webapp\///g')
# 系统配置文件
elif [[ $ss == src/main/resources/* ]]; then
ss=$(echo $ss | sed 's/^src\/main\/resources/WEB-INF\/classes/g')
# 后端Java文件
elif [[ $ss == src/main/java/* ]]; then
ss_temp=${ss##*/}
ss_temp=${ss_temp/".java"/"*.class"}
ss_dir=$(echo $ss | sed 's/^src\/main\/java\///g')
ss_dir=${ss_dir%/*}
ss=""
find WEB-INF/classes/$ss_dir -name $ss_temp >$work_dir"/"git-package_.tmp
while read line; do
ss=$ss" "$line
done <$work_dir"/"git-package_.tmp
rm -rf $work_dir"/"git-package_.tmp
# 其他不处理
else
ss=""
fi
# 将待处理的文件加入列表
if [[ $ss ]]; then
res_files=$res_files" "$ss
fi
done
#文件打包
package_name="update_$(date +%Y%m%d_%H%M%S).zip"
#tar -zcvf $package_name".tar.gz" $res_files
zip -q $package_name $res_files
mv $package_name $work_dir/$package_name
cd $work_dir
echo "patch success: $package_name"