#!/bin/bash

#push 变动文件目录
update_path=/var/www/update
#git 文件路径
path=$1
# shellcheck disable=SC2164
cd "$update_path"
# shellcheck disable=SC2035
rm -rf *

#将项目文件中3分钟之前改动的文件存到update文件
# shellcheck disable=SC2038
# shellcheck disable=SC2185
#find -mmin -3 |grep -v .git|xargs -I {} cp -r {} -u -t $update_path
#find -mtime -1 |grep -v .git|grep -v vendor|xargs -I {} cp -r {} /var/www/update/

# shellcheck disable=SC2045
# shellcheck disable=SC2006
#for file in `ls $update_path`
#     do
#        if [ "composer.json" = "$file" ]; then
#            sudo composer install
#        fi
#    done

for menu in `cd "$path" && find -type f -mmin -5 |grep -v .git|grep -v vendor`
    do
    #判断文件夹是否存在
        if [ $(dirname "${menu#./}") != "." ]; then
             mkdir -p $(dirname "${menu#./}") && cp "$path"/"${menu#./}" /var/www/update/$(dirname "${menu#./}")
            else
                cp -r "$path"/"${menu#./}" /var/www/update
        fi
    done
