fix(migrate-agent-home): 放宽 git 依赖,没 git 也能跑

脚本原硬要求 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 提示(之前的错误信息只说"仓库不存在",新用户看不懂)
This commit is contained in:
admin committed 2026-09-16 11:43:47 +08:00
1 parent 4129d2449e
commit 354c58e721
1 file changed
+15 -7
+15 -7
View File
@@ -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"