寶塔webHook自動同步代碼的使用


#!/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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM