之前写大部分只能针对一个项目来部署,这回改成多个项目自动部署。
- #!/bin/bash
- echo ""
- #输出当前时间
- date --date='0 days ago' "+%Y-%m-%d %H:%M:%S"
- echo "Start"
- #判断宝塔WebHook参数是否存在
- if [ ! -n "$1" ];
- then
- echo "param参数错误"
- echo "End"
- exit
- fi
- #解析参数 例abc/efg
- param="$1"
- obj_user=${param%\/*}
- obj_name=${param#*\/}
- #git项目路径
- gitPath="/www/wwwroot/we7.71yunduan.top/addons/$obj_name/"
- if [ ! -d "$gitPath" ]; then
- mkdir $gitPath
- fi
- #git 网址
- gitHttp="git@gitlib.71yunduan.top:$obj_user/$obj_name.git"
-
- echo "Web站点路径:$gitPath"
- echo "Git项目地址:$gitHttp"
-
- #判断项目路径是否存在
- if [ -d "$gitPath" ]; then
- cd $gitPath
- #判断是否存在git目录
- if [ ! -d ".git" ]; then
- echo "在该目录下克隆 git"
- git clone $gitHttp gittemp
- mv gittemp/.git .
- rm -rf gittemp
- fi
- #拉取最新的项目文件
- git reset --hard origin/master
- git pull
- #设置目录权限
- chown -R www:www $gitPath
- echo "End"
- exit
- else
- echo "该项目路径不存在"
- echo "End"
- exit
- fi