#!/bin/bash # ============================================================ # Git Auto Sync Script # ============================================================ # 自动同步代码到 Gogs 仓库 # ============================================================ set -e GOGS_URL="https://git.zhonjin.com:40717/steven_roc" REPO_NAME="hikvision-isup-client" ACCESS_TOKEN="1942ce3d6478f7a572fee3dd4891e49f6c416aad" FULL_URL="${GOGS_URL}/${REPO_NAME}.git" echo "=== Git Repository Sync ===" echo "" # 检查 git if ! command -v git &> /dev/null; then echo "Error: git is not installed" exit 1 fi # 初始化仓库(如果尚未初始化) if [ ! -d ".git" ]; then echo "[1/5] Initializing git repository..." git init git branch -M main fi # 配置用户 git config user.name "steven_roc" 2>/dev/null || true git config user.email "steven_roc@zhonjin.com" 2>/dev/null || true # 添加远程仓库 if ! git remote get-url origin &> /dev/null; then echo "[2/5] Adding remote origin..." git remote add origin "https://steven_roc:${ACCESS_TOKEN}@git.zhonjin.com:40717/steven_roc/${REPO_NAME}.git" fi # 添加所有文件 echo "[3/5] Staging files..." git add -A # 检查是否有变更 if git diff --staged --quiet; then echo "No changes to commit" else # 提交 echo "[4/5] Committing changes..." git commit -m "$(date '+%Y-%m-%d %H:%M:%S') - Auto sync update" # 推送(注意: 不要使用 -o 参数,Gogs 可能不支持 push options) echo "[5/5] Pushing to Gogs..." git push -u origin main fi echo "" echo "=== Sync complete ===" echo "Repository: ${FULL_URL}"