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"