From 8c14759e78fa2a808557ec148e79e4c2c2ba3293 Mon Sep 17 00:00:00 2001 From: dekun Date: Sat, 25 Jul 2026 08:54:09 +0800 Subject: [PATCH] Heal existing /opt install when manage.sh is missing on curl bootstrap. Co-authored-by: Cursor --- deploy/manage.sh | 100 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 17 deletions(-) diff --git a/deploy/manage.sh b/deploy/manage.sh index 66ee351..039fda4 100755 --- a/deploy/manage.sh +++ b/deploy/manage.sh @@ -32,22 +32,93 @@ unset _script_src set -u repo_ready() { - [[ -f "${1}/deploy/manage.sh" && -f "${1}/deploy/pull_and_restart.sh" ]] + [[ -f "${1}/deploy/manage.sh" && -f "${1}/deploy/pull_and_restart.sh" && -d "${1}/deploy/lib" ]] +} + +ensure_git_cli() { + if command -v git >/dev/null 2>&1; then + return 0 + fi + if command -v apt-get >/dev/null 2>&1; then + export DEBIAN_FRONTEND=noninteractive + apt-get update -qq + apt-get install -y git ca-certificates curl + else + echo "错误: 未找到 git" >&2 + exit 1 + fi } sync_repo_if_present() { local root="$1" if [[ -d "${root}/.git" ]] && command -v git >/dev/null 2>&1; then - git -C "${root}" pull -q --ff-only 2>/dev/null || true + git -C "${root}" fetch --all --prune 2>/dev/null || true + git -C "${root}" checkout "${GIT_BRANCH}" 2>/dev/null || true + git -C "${root}" pull --ff-only origin "${GIT_BRANCH}" 2>/dev/null \ + || git -C "${root}" pull --ff-only 2>/dev/null \ + || true fi } +# 旧目录已存在但缺 manage.sh:尽量 git pull / 修复后切到仓库内脚本 +heal_existing_install() { + local root="$1" + echo "检测到已有目录但缺少管理脚本: ${root}" + echo "尝试同步最新代码…" + ensure_git_cli + + if [[ -d "${root}/.git" ]]; then + sync_repo_if_present "${root}" + if repo_ready "${root}"; then + echo "同步成功,切换到仓库内 manage.sh" + exec bash "${root}/deploy/manage.sh" "$@" &2 + exit 1 + fi + heal_existing_install "${INSTALL_ROOT}" "$@" + fi + echo "eth_hedge_sim 部署管理器 — 首次自举" echo "将克隆到: ${INSTALL_ROOT}" if [[ "$(id -u)" -ne 0 ]]; then echo "错误: 请使用 root 执行" >&2 exit 1 fi - if ! command -v git >/dev/null 2>&1; then - if command -v apt-get >/dev/null 2>&1; then - export DEBIAN_FRONTEND=noninteractive - apt-get update -qq - apt-get install -y git ca-certificates curl - else - echo "错误: 未找到 git" >&2 - exit 1 - fi - fi - if [[ -d "${INSTALL_ROOT}" ]]; then - echo "错误: ${INSTALL_ROOT} 已存在但不是有效仓库" >&2 - echo "请手动处理后再运行,或设置 INSTALL_ROOT 指向其它路径" >&2 - exit 1 - fi + ensure_git_cli mkdir -p "$(dirname "${INSTALL_ROOT}")" git clone -b "${GIT_BRANCH}" "${GIT_URL}" "${INSTALL_ROOT}" # clone 后用仓库内脚本 + 终端 stdin(管道已 EOF)