#!/bin/bash
#author by jackluo
#要过滤的文件
ExcludeFile=(api.md dev.md .git .gitignore .htaccess .project README.md)
#定义要copy的目录
new_git_code_dir=/data/projects/你自己的git仓库路径
production_code_dir=/data/projects/你生产上面的路径/
#检查这个字段是否存在这个数组中
function in_array()
{
local f=($1)
local a=($2)
for i in ${a[*]};do
#检查是否在在过滤文件中,在就返回 1,不在就返回 0
if [[ $i = $f ]];then
return 1;
fi
done
}
cd $new_git_code_dir
echo "拉取代码..."
start=$(date +%s)
git pull
end=$(date +%s)
time=$(( $end - $start ))
echo "代码拉取完成...完成用了 $time 秒"
#列出目录中所有的文件
LISTDIR=`ls $new_git_code_dir`
echo "开始复制代码..."
start=$(date +%s)
for d in $LISTDIR;do
#检查是不在拷的范围内
in_array "$d" "${ExcludeFile[*]}"
if [[ $? = 1 ]] ; then
continue
else
echo "正在拷 $d..."
/bin/cp -a ${new_git_code_dir}/$d ${production_code_dir}
fi
done
end=$(date +%s)
time=$(( $end - $start ))
echo "复制代码完成... 完成用了 $time 秒"
echo "更改目录权限..."
chown fpm:fpm ${production_code_dir} -R &> /dev/null
echo "部署完成"