diff --git a/README.md b/README.md index 5e779d0..c680ae4 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,11 @@ MT5 **黄金** 下单辅助中控:**网页登录 → 下载通用 exe → 首 # 新服务器(推荐) curl -fsSL https://git.bz121.com/dekun/gold_monitor/raw/branch/main/deploy/manage.sh | bash +# 已安装后仅快速更新(非交互): +curl -fsSL https://git.bz121.com/dekun/gold_monitor/raw/branch/main/deploy/manage.sh | bash -s -- update +# 或: +bash /opt/gold_monitor/deploy/manage.sh update + # 或手动 cd /opt git clone https://git.bz121.com/dekun/gold_monitor.git gold_monitor diff --git a/deploy/manage.sh b/deploy/manage.sh index 1b12b57..658f86a 100644 --- a/deploy/manage.sh +++ b/deploy/manage.sh @@ -4,9 +4,13 @@ # 新服务器(免克隆): # curl -fsSL https://git.bz121.com/dekun/gold_monitor/raw/branch/main/deploy/manage.sh | bash # -# 已安装: +# 已安装(推荐,可交互): # bash /opt/gold_monitor/deploy/manage.sh # +# 非交互快速更新: +# bash /opt/gold_monitor/deploy/manage.sh update +# curl -fsSL .../deploy/manage.sh | bash -s -- update +# set -e if [ -n "${BASH_VERSION:-}" ]; then set -o pipefail @@ -22,6 +26,7 @@ if [[ -n "${_script_src}" && -f "${_script_src}" ]]; then REPO_ROOT="$(cd "${DEPLOY_DIR}/.." && pwd)" LIB_DIR="${DEPLOY_DIR}/lib" else + # curl | bash 时脚本从 stdin 执行,无本地路径 DEPLOY_DIR="" REPO_ROOT="" LIB_DIR="" @@ -80,6 +85,38 @@ bootstrap_repo() { exec bash "${INSTALL_ROOT}/deploy/manage.sh" "$@" &2 + echo "请改用下列任一方式:" >&2 + echo " bash ${INSTALL_ROOT}/deploy/manage.sh" >&2 + echo " bash ${INSTALL_ROOT}/deploy/manage.sh update" >&2 + echo " curl -fsSL https://git.bz121.com/dekun/gold_monitor/raw/branch/main/deploy/manage.sh | bash -s -- update" >&2 + exit 1 +} + +run_update_quick() { + export REPO_ROOT DEPLOY_DIR LIB_DIR INSTALL_ROOT GIT_URL GIT_BRANCH + # shellcheck source=/dev/null + source "${LIB_DIR}/common.sh" + need_root + echo "快速更新: git pull + pm2 restart" + git -C "${REPO_ROOT}" pull --ff-only + pm2 restart gold_monitor + echo "更新完成" +} + show_banner() { local ip path path="${INSTALL_ROOT}" @@ -111,8 +148,30 @@ show_menu() { } main_menu() { - bootstrap_repo + bootstrap_repo "$@" export REPO_ROOT DEPLOY_DIR LIB_DIR INSTALL_ROOT GIT_URL GIT_BRANCH + + local cmd="${1:-}" + case "${cmd}" in + update|3) + # shellcheck source=/dev/null + source "${LIB_DIR}/common.sh" + run_update_quick + exit 0 + ;; + update-deps) + # shellcheck source=/dev/null + source "${LIB_DIR}/common.sh" + need_root + git -C "${REPO_ROOT}" pull --ff-only + bash "${REPO_ROOT}/deploy/setup_env.sh" + pm2 restart gold_monitor + echo "依赖更新完成" + exit 0 + ;; + esac + + ensure_interactive_tty "$@" # shellcheck source=/dev/null source "${LIB_DIR}/common.sh" show_banner diff --git a/docs/deploy.md b/docs/deploy.md index fe867b2..474fb71 100644 --- a/docs/deploy.md +++ b/docs/deploy.md @@ -14,6 +14,14 @@ ```bash curl -fsSL https://git.bz121.com/dekun/gold_monitor/raw/branch/main/deploy/manage.sh | bash + +已安装后若只要更新,用非交互命令(`curl|bash` 直接进菜单会因 stdin 被占用而失败): + +```bash +curl -fsSL https://git.bz121.com/dekun/gold_monitor/raw/branch/main/deploy/manage.sh | bash -s -- update +# 或本机: +bash /opt/gold_monitor/deploy/manage.sh update +``` ``` 菜单: