#!/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
#git項目路徑
gitPath="/www/wwwroot/$1"
#git 網址
gitHttp="https://git.xxxxx.net/abc/$1.git"
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
echo "設置目錄權限"
sudo chown -R www:www $gitPath
echo "End"
exit
else
echo "該項目路徑不存在"
echo "新建項目目錄"
mkdir $gitPath
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
echo "設置目錄權限"
sudo chown -R www:www $gitPath
echo "End"
exit
fi