From 354c58e721f6e2a88f2991b5cc17acdb2232d217 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 16 Sep 2026 11:43:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(migrate-agent-home):=20=E6=94=BE=E5=AE=BD?= =?UTF-8?q?=20git=20=E4=BE=9D=E8=B5=96=EF=BC=8C=E6=B2=A1=20git=20=E4=B9=9F?= =?UTF-8?q?=E8=83=BD=E8=B7=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 脚本原硬要求 REPO_DIR 是 git repo,否则直接 exit。但 .11 上没装 git 的部署场景只 scp deploy/ 文件夹上来跑,git pull 那步根本不存在。 改成: * 必须有 $REPO_DIR/deploy/ipass-agent.py 文件(不强制 .git) * 如果 command -v git && [ -d .git ] 才尝试 pull,否则跳过 * 缺文件时给 scp 提示(之前的错误信息只说"仓库不存在",新用户看不懂) --- deploy/migrate-agent-home.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/deploy/migrate-agent-home.sh b/deploy/migrate-agent-home.sh index 736f700..ecb1b9a 100755 --- a/deploy/migrate-agent-home.sh +++ b/deploy/migrate-agent-home.sh @@ -24,14 +24,22 @@ c_warn() { printf '\033[33m!\033[0m %s\n' "$*"; } c_err() { printf '\033[31m✗\033[0m %s\n' "$*" >&2; } step() { printf '\n\033[36m==> %s\033[0m\n' "$*"; } -# ---------------------------------------------------------------- 1. 校验环境 -[ -d "$REPO_DIR/.git" ] || { c_err "仓库不存在:$REPO_DIR(设 REPO_DIR=...)"; exit 1; } -[ -f "$REPO_DIR/deploy/ipass-agent.py" ] || { c_err "仓库里没 deploy/ipass-agent.py"; exit 1; } +# ---------------------------------------------------------------- 1. 定位新 agent 代码 +# git 可选:装了 git 且是 repo 就 pull;否则只要文件在就行 +[ -f "$REPO_DIR/deploy/ipass-agent.py" ] || { + c_err "找不到 $REPO_DIR/deploy/ipass-agent.py" + c_err " → scp 本仓库 deploy/ 到 $REPO_DIR/ 后再跑" + c_err " → 或者设 REPO_DIR 指到 deploy/ 的父目录" + exit 1 +} -cd "$REPO_DIR" -git pull --ff-only || c_warn "git pull 失败(继续,可能无新提交或网络问题)" -NEW_SHA=$(git rev-parse --short HEAD) -step "仓库已就绪($NEW_SHA)" +NEW_SHA="" +if command -v git >/dev/null 2>&1 && [ -d "$REPO_DIR/.git" ]; then + (cd "$REPO_DIR" && git pull --ff-only) 2>/dev/null \ + || c_warn "git pull 失败(继续,可能无新提交或网络问题)" + NEW_SHA=$(git -C "$REPO_DIR" rev-parse --short HEAD 2>/dev/null || echo "") +fi +step "agent 代码:$REPO_DIR/deploy/ipass-agent.py${NEW_SHA:+(git $NEW_SHA)}" # ---------------------------------------------------------------- 2. 优雅停旧 agent step "停止旧 agent"