From afa0d5a5bdbb27af89d6cddc9fa547e1aba6cbf0 Mon Sep 17 00:00:00 2001 From: Sora39831 <540587985@qq.com> Date: Wed, 22 Apr 2026 09:45:56 +0800 Subject: [PATCH] fix: accept direct panel port input in install flow --- .../2026-04-22-fix-panel-port-input-flow.md | 43 +++++++++++++++++++ install.sh | 27 ++++++------ tests/panel_port_prompt_test.sh | 28 ++++++++++++ 3 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 docs/Tasktracking/2026-04-22-fix-panel-port-input-flow.md create mode 100644 tests/panel_port_prompt_test.sh diff --git a/docs/Tasktracking/2026-04-22-fix-panel-port-input-flow.md b/docs/Tasktracking/2026-04-22-fix-panel-port-input-flow.md new file mode 100644 index 00000000..99a9e37f --- /dev/null +++ b/docs/Tasktracking/2026-04-22-fix-panel-port-input-flow.md @@ -0,0 +1,43 @@ +Task Record: + +Date: 2026-04-22 +Related Module: install script (`install.sh`) +Change Type: Fix + +Background + +The panel port setup in fresh install used a `y/n` confirmation before reading the port. +When users directly entered a numeric port like `443` at the confirmation prompt, it was treated as non-`y` and the script generated a random port, causing unexpected behavior. + +Changes + +Replaced the two-step `y/n` + port input flow with a single direct input flow in `install.sh`. +Now the script asks for panel port directly: +- Empty input: generate random panel port. +- Valid numeric port (`1-65535`): use as panel port. +- Invalid input: show error and prompt again. + +Added `tests/panel_port_prompt_test.sh` to verify the expected prompt and validation logic exists and the legacy `y/n` prompt is removed. + +Impact + +Affected files: +- `install.sh` +- `tests/panel_port_prompt_test.sh` + +No API, database schema, or build pipeline changes. +Runtime install interaction is changed for fresh install panel-port setup only. + +Verification + +Commands: +- `bash tests/panel_port_prompt_test.sh` +- `bash tests/mariadb_install_switch_test.sh` + +Result: +- Both scripts passed. + +Risks And Follow-Up + +Current verification is static prompt/logic assertion, not full interactive E2E install simulation. +If needed, add an automated pty-based interaction test to validate runtime behavior across shells. diff --git a/install.sh b/install.sh index c3b07acf..9b419932 100644 --- a/install.sh +++ b/install.sh @@ -1092,22 +1092,21 @@ config_after_install() { echo -e "${green}已生成随机 Web 路径:${config_webBasePath}${plain}" fi - read -rp "是否要自定义面板端口?(否则将使用随机端口)[y/n]:" config_confirm - if [[ "${config_confirm}" == "y" || "${config_confirm}" == "Y" ]]; then - while true; do - read -rp "请设置面板端口:" config_port - config_port="${config_port// /}" - if ! [[ "${config_port}" =~ ^[0-9]+$ ]] || ((config_port < 1 || config_port > 65535)); then - echo -e "${red}无效端口,请输入 1-65535 之间的数字。${plain}" - continue - fi + while true; do + read -rp "请输入面板端口(留空将随机生成):" config_port + config_port="${config_port// /}" + if [[ -z "${config_port}" ]]; then + config_port=$(shuf -i 1024-62000 -n 1) + echo -e "${yellow}已生成随机端口:${config_port}${plain}" break - done + fi + if ! [[ "${config_port}" =~ ^[0-9]+$ ]] || ((config_port < 1 || config_port > 65535)); then + echo -e "${red}无效端口,请输入 1-65535 之间的数字。${plain}" + continue + fi echo -e "${yellow}您的面板端口为:${config_port}${plain}" - else - local config_port=$(shuf -i 1024-62000 -n 1) - echo -e "${yellow}已生成随机端口:${config_port}${plain}" - fi + break + done read -rp "Database type [mariadb]: " db_type db_type=$(echo "${db_type:-mariadb}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]') diff --git a/tests/panel_port_prompt_test.sh b/tests/panel_port_prompt_test.sh new file mode 100644 index 00000000..888442f2 --- /dev/null +++ b/tests/panel_port_prompt_test.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +assert_contains() { + local file="$1" + local pattern="$2" + if ! grep -Fq "$pattern" "$file"; then + echo "missing pattern in $file: $pattern" >&2 + return 1 + fi +} + +assert_not_contains() { + local file="$1" + local pattern="$2" + if grep -Fq "$pattern" "$file"; then + echo "unexpected pattern in $file: $pattern" >&2 + return 1 + fi +} + +assert_contains "install.sh" "请输入面板端口(留空将随机生成):" +assert_contains "install.sh" "if [[ -z \"\${config_port}\" ]]; then" +assert_contains "install.sh" "已生成随机端口:" +assert_contains "install.sh" "无效端口,请输入 1-65535 之间的数字。" +assert_not_contains "install.sh" "是否要自定义面板端口?(否则将使用随机端口)[y/n]:" + +echo "panel port prompt flow looks correct"