#!/bin/bash
echo ""
#输出当前时间
date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
echo "Start"
#判断宝塔WebHook参数是否存在
if [ ! -n "china" ];
then
          echo "param参数错误"
          echo "End"
          exit
fi
#git项目路径
gitPath="/www/wwwroot/testwww.jhcs888.com/website"
#git 网址
gitHttp="http://git.lcpcp.cc/zhf/website.git"
echo "Web站点路径：$gitPath"
#判断项目路径是否存在
if [ -d "$gitPath" ]; then
        cd $gitPath
        #判断是否存在git目录
        if [ ! -d ".git" ]; then
                echo "在该目录下克隆 git"
           sudo      git clone $gitHttp gittemp
                 mv gittemp/.git .
                 rm -rf gittemp
        fi
        echo "拉取最新的项目文件"
        # git reset --hard origin/master
      sudo   git pull
        echo "设置目录权限"


else
        echo "该项目路径不存在"
                echo "新建项目目录"
        mkdir $gitPath
        cd $gitPath
        #判断是否存在git目录
        if [ ! -d ".git" ]; then
                echo "在该目录下克隆 git"
              sudo   git clone $gitHttp gittemp
                 mv gittemp/.git .
                 rm -rf gittemp
        fi
        echo "拉取最新的项目文件"
        # git reset --hard origin/master
       sudo  git pull
        echo "设置目录权限"

fi
  chown -R root:root $gitPath
 #echo "切换分支"
 # git checkout census
 date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
 echo "更新项目包"
 sudo  npm i
   date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
    echo "项目代码发布"
     sudo npm run build:test
      date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
     echo "代码移动覆盖"
     sudo rsync   -a ./dist/* ../
      echo "End"
       exit
