Fix curl|bash manage.sh: reattach /dev/tty; add update subcommand.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
# 已安装后仅快速更新(非交互):
|
||||||
|
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
|
cd /opt
|
||||||
git clone https://git.bz121.com/dekun/gold_monitor.git gold_monitor
|
git clone https://git.bz121.com/dekun/gold_monitor.git gold_monitor
|
||||||
|
|||||||
+61
-2
@@ -4,9 +4,13 @@
|
|||||||
# 新服务器(免克隆):
|
# 新服务器(免克隆):
|
||||||
# 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
|
||||||
#
|
#
|
||||||
# 已安装:
|
# 已安装(推荐,可交互):
|
||||||
# bash /opt/gold_monitor/deploy/manage.sh
|
# 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
|
set -e
|
||||||
if [ -n "${BASH_VERSION:-}" ]; then
|
if [ -n "${BASH_VERSION:-}" ]; then
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
@@ -22,6 +26,7 @@ if [[ -n "${_script_src}" && -f "${_script_src}" ]]; then
|
|||||||
REPO_ROOT="$(cd "${DEPLOY_DIR}/.." && pwd)"
|
REPO_ROOT="$(cd "${DEPLOY_DIR}/.." && pwd)"
|
||||||
LIB_DIR="${DEPLOY_DIR}/lib"
|
LIB_DIR="${DEPLOY_DIR}/lib"
|
||||||
else
|
else
|
||||||
|
# curl | bash 时脚本从 stdin 执行,无本地路径
|
||||||
DEPLOY_DIR=""
|
DEPLOY_DIR=""
|
||||||
REPO_ROOT=""
|
REPO_ROOT=""
|
||||||
LIB_DIR=""
|
LIB_DIR=""
|
||||||
@@ -80,6 +85,38 @@ bootstrap_repo() {
|
|||||||
exec bash "${INSTALL_ROOT}/deploy/manage.sh" "$@" </dev/tty
|
exec bash "${INSTALL_ROOT}/deploy/manage.sh" "$@" </dev/tty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# curl|bash 时 stdin 是脚本管道,菜单 read 会立刻失败;改挂到真实终端
|
||||||
|
ensure_interactive_tty() {
|
||||||
|
if [[ -t 0 ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local local_mgr="${INSTALL_ROOT}/deploy/manage.sh"
|
||||||
|
if [[ -n "${REPO_ROOT}" && -f "${REPO_ROOT}/deploy/manage.sh" ]]; then
|
||||||
|
local_mgr="${REPO_ROOT}/deploy/manage.sh"
|
||||||
|
fi
|
||||||
|
if [[ -r /dev/tty && -f "${local_mgr}" ]]; then
|
||||||
|
echo "检测到非交互 stdin(多为 curl|bash),改从终端重新启动管理器…"
|
||||||
|
exec bash "${local_mgr}" "$@" </dev/tty
|
||||||
|
fi
|
||||||
|
echo "错误: 需要交互终端才能显示菜单。" >&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() {
|
show_banner() {
|
||||||
local ip path
|
local ip path
|
||||||
path="${INSTALL_ROOT}"
|
path="${INSTALL_ROOT}"
|
||||||
@@ -111,8 +148,30 @@ show_menu() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main_menu() {
|
main_menu() {
|
||||||
bootstrap_repo
|
bootstrap_repo "$@"
|
||||||
export REPO_ROOT DEPLOY_DIR LIB_DIR INSTALL_ROOT GIT_URL GIT_BRANCH
|
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
|
# shellcheck source=/dev/null
|
||||||
source "${LIB_DIR}/common.sh"
|
source "${LIB_DIR}/common.sh"
|
||||||
show_banner
|
show_banner
|
||||||
|
|||||||
@@ -14,6 +14,14 @@
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
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
|
||||||
|
|
||||||
|
已安装后若只要更新,用非交互命令(`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
|
||||||
|
```
|
||||||
```
|
```
|
||||||
|
|
||||||
菜单:
|
菜单:
|
||||||
|
|||||||
Reference in New Issue
Block a user