#!/bin/bash echo "" #输出当前时间 date --date='0 days ago' "+%Y-%m-%d %H:%M:%S" echo "Start" #git项目路径 gitPath=" " #git 网址 gitHttp=" " #延迟高可以加https://ghproxy.com/代理
echo "Web站点路径:$gitPath" #判断项目路径是否存在 if [ -d "$gitPath" ]; then cd $gitPath #判断是否存在git目录 if [ ! -d ".git" ]; then echo "在该目录下克隆 git" sudo git clone $gitHttp gittemp sudo mv gittemp/.git . sudo rm -rf gittemp fi echo"拉取最新的项目文件" sudo git reset --hard origin/master sudo git pull origin master echo"设置目录权限" sudo chown -R www:www $gitPath date --date='0 days ago' "+%Y-%m-%d %H:%M:%S" echo "End" exit else echo "该项目路径不存在" echo "End" exit fi
Github设置Webhook
查看密钥
切换到Github项目的Settings-Webhooks
Add Webhook
Payload URL:http://服务器ip:8888?hook?access_key=xxxxx Content type:application/json Secret:Key Which events would you like to trigger this webhook? choose:Just the push event. √Active
#!/bin/bash echo "" #输出当前时间 date --date='0 days ago' "+%Y-%m-%d %H:%M:%S" echo "Start" #git项目路径 gitPath=" " #git 网址 gitSSH="https://mirror.ghproxy.com/https://github.com/username/repo" echo "Web站点路径:$gitPath" #判断项目路径是否存在 if [ -d "$gitPath" ]; then cd $gitPath #判断是否存在git目录 if [ ! -d ".git" ]; then echo "Cloning the git repository into the directory" sudo git clone $gitSSH . fi echo "拉取最新的项目文件" sudo git reset -- hard origin/master sudo git pull origin master echo "设置目录权限" sudo chown -R www:www $gitPath date --date='0 days ago' "+%Y-%m-%d %H:%M:%S" echo "End" exit else echo "该项目路径不存在" echo "End" exit fi
Copyright:
Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.