feat: Linux one-click start pulls from Gitea ai_site

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-07-31 10:20:46 +08:00
parent 6366859bb3
commit 3d2851a1f1
5 changed files with 86 additions and 14 deletions

View File

@@ -384,18 +384,57 @@ ${pub_line}
EOF
}
git_pull_hard() {
local branch="${GIT_BRANCH:-master}"
echo "拉取代码branch=$branch..."
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "错误: 当前不是 git 仓库,跳过拉取。" >&2
# 默认代码源(可用 AIJZ_GIT_URL / GIT_BRANCH 覆盖)
AIJZ_GIT_URL_DEFAULT="https://gitea.yuxindazhineng.com/whm/ai_site.git"
ensure_git_origin() {
local url="${1:-${AIJZ_GIT_URL:-$AIJZ_GIT_URL_DEFAULT}}"
if ! command -v git >/dev/null 2>&1; then
echo "错误: 未安装 git无法拉取代码。请先安装 git。" >&2
return 1
fi
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "当前目录不是 git 仓库,初始化并关联 origin -> $url"
git init
git remote add origin "$url"
return 0
fi
if git remote get-url origin >/dev/null 2>&1; then
local cur
cur="$(git remote get-url origin)"
if [ "$cur" != "$url" ]; then
echo "更新 origin: $cur -> $url"
git remote set-url origin "$url"
fi
else
echo "添加 origin -> $url"
git remote add origin "$url"
fi
}
# 从 Gitea ai_site 拉取并与远程对齐(默认硬重置,保留未跟踪文件如 .env
# 环境变量:
# AIJZ_GIT_URL 仓库地址(默认 https://gitea.yuxindazhineng.com/whm/ai_site.git
# GIT_BRANCH 分支(默认 main
# FORCE_GIT_RESET 1=reset --hard 对齐远程(默认 10=仅快进合并
git_pull_hard() {
local url="${AIJZ_GIT_URL:-$AIJZ_GIT_URL_DEFAULT}"
local branch="${GIT_BRANCH:-main}"
echo "拉取代码($url branch=$branch..."
ensure_git_origin "$url" || return 1
if ! git fetch origin --progress; then
echo "错误: git fetch 失败。私有仓库请配置凭据,或设置 AIJZ_GIT_URL 为带 token 的地址。" >&2
return 1
fi
if ! git rev-parse --verify "origin/$branch" >/dev/null 2>&1; then
echo "错误: 远程不存在分支 origin/$branch" >&2
return 1
fi
git fetch origin --progress
if [ "${FORCE_GIT_RESET:-1}" = "1" ]; then
git checkout -B "$branch" "origin/$branch"
git reset --hard "origin/$branch"
else
git checkout "$branch" 2>/dev/null || true
git checkout "$branch" 2>/dev/null || git checkout -b "$branch" "origin/$branch"
git merge --ff-only "origin/$branch"
fi
echo "当前: $(git rev-parse --short HEAD) $(git log -1 --pretty=%s)"