From d7f27554a7da3b2ef47822ac41864edafc6ea7c9 Mon Sep 17 00:00:00 2001 From: hoywu Date: Wed, 24 Jun 2026 11:45:46 +0800 Subject: [PATCH] fix(setup): silence prompt on non-tty stdin and emit per-target launch hints The Linux one-click-start and setup_backend_linux scripts were both assuming interactive stdin: - one-click-start.sh called `read -r -p ...` on every fatal exit path (non-Linux host, missing release files, install failure, missing weight). When the script is launched from a desktop entry, systemd user unit, CI, or any other context where stdin is not a TTY, `read` would block waiting for input that will never come, hanging the process instead of exiting promptly. Replace each site with a small `pause_if_tty` helper that only prompts when `[ -t 0 ]`, so the script still pauses for a user at a real terminal but returns immediately when run unattended. - scripts/setup_backend_linux.sh printed a single, hard-coded launch block that only mentioned `.venv_paddle` (CPU). After the previous --target auto/cpu/gpu/both refactor, the user could have built any combination of CPU and GPU venvs but the hints always pointed at the CPU one. Wrap the post-install message in `print_completion_hints`, iterate over the actually-selected modes to print the correct `/bin/python` for each (CPU -> .venv_paddle, GPU -> .venv_paddle_gpu), and add an auto-mode command line when both venvs exist or a hint to install the CPU fallback when only GPU was built. No behaviour change for the install flow itself; only the prompt handling and the post-install guidance. --- one-click-start.sh | 15 ++++++++---- scripts/setup_backend_linux.sh | 44 +++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/one-click-start.sh b/one-click-start.sh index 8b9fce1..03f6e69 100755 --- a/one-click-start.sh +++ b/one-click-start.sh @@ -85,11 +85,18 @@ EOF # ── 1. 检查系统和 Release 文件 ──────────────────────────────── if [ "$(uname -s)" != "Linux" ]; then echo "[错误] 此脚本仅支持 Linux。" >&2 - read -r -p "按回车键退出..." + pause_if_tty "按回车键退出..." exit 1 fi # ── 辅助函数 ─────────────────────────────────────────────────── +pause_if_tty() { + local prompt="${1:-按回车键退出...}" + if [ -t 0 ]; then + read -r -p "$prompt" + fi +} + has_nvidia_gpu() { command -v nvidia-smi >/dev/null 2>&1 && nvidia-smi -L >/dev/null 2>&1 } @@ -152,7 +159,7 @@ assert_required_files() { echo " - $item" >&2 done echo "Please re-extract the full latest release zip and retry." >&2 - read -r -p "Press Enter to exit" + pause_if_tty "Press Enter to exit" exit 1 fi } @@ -255,7 +262,7 @@ if [ "$READY" -eq 0 ]; then echo " Auto mode already attempted GPU/CPU fallback." >&2 fi echo " 完整安装日志已保存到 logs/backend-install.log,排查请提供此文件。" >&2 - read -r -p "按回车键退出..." + pause_if_tty "按回车键退出..." exit 1 fi fi @@ -273,7 +280,7 @@ WEIGHT="$SCRIPT_DIR/models/weights/yolo-captcha-detector.pt" if [ ! -f "$WEIGHT" ]; then echo "[错误] 缺少检测权重:$WEIGHT" >&2 echo " 请从 Release 包补齐 models/weights/yolo-captcha-detector.pt 后再启动。" >&2 - read -r -p "按回车键退出..." + pause_if_tty "按回车键退出..." exit 1 fi diff --git a/scripts/setup_backend_linux.sh b/scripts/setup_backend_linux.sh index aaae02d..e98a344 100755 --- a/scripts/setup_backend_linux.sh +++ b/scripts/setup_backend_linux.sh @@ -272,15 +272,43 @@ else fi # ── 7. 完成 ──────────────────────────────────────────────────── -cat <