mirror of
https://github.com/OLmatter/glm-coding-helper.git
synced 2026-10-07 14:58:39 +08:00
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 `<venv>/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.
This commit is contained in:
+11
-4
@@ -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
|
||||
|
||||
|
||||
@@ -272,15 +272,43 @@ else
|
||||
fi
|
||||
|
||||
# ── 7. 完成 ────────────────────────────────────────────────────
|
||||
cat <<EOF
|
||||
print_completion_hints() {
|
||||
local mode py has_cpu=0 has_gpu=0
|
||||
|
||||
完成。启动后端:
|
||||
for mode in "${SELECTED[@]}"; do
|
||||
case "$mode" in
|
||||
cpu) has_cpu=1 ;;
|
||||
gpu) has_gpu=1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
GUI 模式:
|
||||
$ROOT/.venv_paddle/bin/python $ROOT/scripts/tools/start_backend.py --mode auto
|
||||
echo ""
|
||||
echo "完成。启动后端:"
|
||||
echo ""
|
||||
|
||||
headless 模式:
|
||||
$ROOT/.venv_paddle/bin/python $ROOT/scripts/tools/start_backend.py --headless --mode auto
|
||||
for mode in "${SELECTED[@]}"; do
|
||||
if [ "$mode" = "gpu" ]; then
|
||||
py="$ROOT/.venv_paddle_gpu/bin/python"
|
||||
else
|
||||
py="$ROOT/.venv_paddle/bin/python"
|
||||
fi
|
||||
echo " ${mode^^} 环境:"
|
||||
echo " GUI: $py $ROOT/scripts/tools/start_backend.py --mode $mode"
|
||||
echo " headless: $py $ROOT/scripts/tools/start_backend.py --headless --mode $mode"
|
||||
echo ""
|
||||
done
|
||||
|
||||
Linux 支持 CPU;如 NVIDIA/CUDA/PaddlePaddle 环境可用,也支持 GPU/auto 模式。
|
||||
EOF
|
||||
if [ "$has_gpu" -eq 1 ] && [ "$has_cpu" -eq 1 ]; then
|
||||
echo " auto 模式(GPU 优先,失败回退 CPU):"
|
||||
echo " $ROOT/.venv_paddle_gpu/bin/python $ROOT/scripts/tools/start_backend.py --headless --mode auto"
|
||||
echo ""
|
||||
elif [ "$has_gpu" -eq 1 ]; then
|
||||
echo " 提示:使用 auto 模式前,建议再安装 CPU 回退环境:"
|
||||
echo " ./scripts/setup_backend_linux.sh --target cpu"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo " Linux 支持 CPU;如 NVIDIA/CUDA/PaddlePaddle 环境可用,也支持 GPU/auto 模式。"
|
||||
}
|
||||
|
||||
print_completion_hints
|
||||
|
||||
Reference in New Issue
Block a user