Fix curl-pipe menu exiting immediately by reading from /dev/tty.

Re-exec manage.sh with terminal stdin after clone or when repo exists, and route all prompts through cm_read.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-12 12:36:34 +08:00
parent 95895d53b6
commit acb61a413b
4 changed files with 37 additions and 7 deletions
+15 -2
View File
@@ -87,17 +87,30 @@ detect_server_ip() {
confirm_yes() { confirm_yes() {
local msg="$1" local msg="$1"
local ans="" local ans=""
read -r -p "${msg} [y/N] " ans cm_read ans "${msg} [y/N] "
[[ "${ans}" == [yY] || "${ans}" == [yY][eE][sS] ]] [[ "${ans}" == [yY] || "${ans}" == [yY][eE][sS] ]]
} }
confirm_uninstall() { confirm_uninstall() {
local ans="" local ans=""
echo "此操作将停止全部 PM2 进程并移走安装目录." echo "此操作将停止全部 PM2 进程并移走安装目录."
read -r -p "输入 UNINSTALL 确认卸载: " ans cm_read ans "输入 UNINSTALL 确认卸载: "
[[ "${ans}" == "UNINSTALL" ]] [[ "${ans}" == "UNINSTALL" ]]
} }
# curl | bash 时 stdin 是管道,须从 /dev/tty 读取用户输入
cm_read() {
local __var="$1"
local __prompt="$2"
local __val=""
if [[ -r /dev/tty ]]; then
IFS= read -r -p "${__prompt}" __val </dev/tty || true
else
IFS= read -r -p "${__prompt}" __val || true
fi
printf -v "${__var}" '%s' "${__val}"
}
repo_ready() { repo_ready() {
[[ -f "${1}/deploy/setup_env.sh" && -f "${1}/deploy/manage.sh" ]] [[ -f "${1}/deploy/setup_env.sh" && -f "${1}/deploy/manage.sh" ]]
} }
+1 -1
View File
@@ -52,7 +52,7 @@ handle_existing_install() {
echo " b) 修复环境(重建 venv,保留 .env 与数据库)" echo " b) 修复环境(重建 venv,保留 .env 与数据库)"
echo " c) 深度重装(保留 .env,清库,见 reinstall.sh)" echo " c) 深度重装(保留 .env,清库,见 reinstall.sh)"
local choice="" local choice=""
read -r -p "请选择 [a/b/c]: " choice cm_read choice "请选择 [a/b/c]: "
case "${choice}" in case "${choice}" in
b|B) b|B)
install_repair install_repair
+1 -1
View File
@@ -59,7 +59,7 @@ show_update_menu() {
echo " 3-3) 深度重装(保留 .env,清库)" echo " 3-3) 深度重装(保留 .env,清库)"
echo " 0) 返回主菜单" echo " 0) 返回主菜单"
local choice="" local choice=""
read -r -p "请选择 [0/3-1/3-2/3-3]: " choice cm_read choice "请选择 [0/3-1/3-2/3-3]: "
case "${choice}" in case "${choice}" in
3-1|31|1) update_quick; break ;; 3-1|31|1) update_quick; break ;;
3-2|32|2) update_deps; break ;; 3-2|32|2) update_deps; break ;;
+20 -3
View File
@@ -31,6 +31,22 @@ unset _script_src
set -u set -u
# curl | bash: stdin 为管道,clone 后或已有仓库时改从终端读入
reexec_with_tty_if_needed() {
if [[ -t 0 ]]; then
return 0
fi
local script=""
if [[ -f "${INSTALL_ROOT}/deploy/manage.sh" ]]; then
script="${INSTALL_ROOT}/deploy/manage.sh"
elif [[ -n "${DEPLOY_DIR}" && -f "${DEPLOY_DIR}/manage.sh" ]]; then
script="${DEPLOY_DIR}/manage.sh"
fi
if [[ -n "${script}" ]]; then
exec bash "${script}" "$@" </dev/tty
fi
}
repo_ready() { repo_ready() {
[[ -f "${1}/deploy/setup_env.sh" && -f "${1}/deploy/manage.sh" ]] [[ -f "${1}/deploy/setup_env.sh" && -f "${1}/deploy/manage.sh" ]]
} }
@@ -71,7 +87,7 @@ bootstrap_repo() {
fi fi
mkdir -p "$(dirname "${INSTALL_ROOT}")" mkdir -p "$(dirname "${INSTALL_ROOT}")"
git clone -b "${GIT_BRANCH}" "${GIT_URL}" "${INSTALL_ROOT}" git clone -b "${GIT_BRANCH}" "${GIT_URL}" "${INSTALL_ROOT}"
exec bash "${INSTALL_ROOT}/deploy/manage.sh" "$@" exec bash "${INSTALL_ROOT}/deploy/manage.sh" "$@" </dev/tty
} }
show_banner() { show_banner() {
@@ -113,7 +129,7 @@ main_menu() {
show_banner show_banner
show_menu show_menu
local choice="" local choice=""
read -r -p "请选择 [0-3]: " choice cm_read choice "请选择 [0-3]: "
case "${choice}" in case "${choice}" in
1) 1)
bash "${LIB_DIR}/install.sh" bash "${LIB_DIR}/install.sh"
@@ -133,8 +149,9 @@ main_menu() {
;; ;;
esac esac
echo "" echo ""
read -r -p "按 Enter 返回菜单..." _ cm_read _ "按 Enter 返回菜单..."
done done
} }
reexec_with_tty_if_needed "$@"
main_menu "$@" main_menu "$@"