From 59a693ff1562a6ab73c2d03677f12c37273be2c7 Mon Sep 17 00:00:00 2001 From: WanWanYun Date: Thu, 13 Nov 2025 01:12:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=A3=80=E6=B5=8B=E5=9C=A8set=20-e=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E5=AF=BC=E8=87=B4=E8=84=9A=E6=9C=AC=E9=80=80?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题描述: - check_port_status函数返回非零值导致脚本在set -e模式下退出 - 使用grep -oP在某些Debian系统上不兼容 修复内容: - 修改check_port_status始终返回0,避免触发set -e退出 - 将grep -oP替换为sed命令,提高兼容性 - 通过echo返回状态字符串而非返回码 测试场景: - Debian 12系统验证通过 - 端口检测功能正常工作 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- install.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/install.sh b/install.sh index e93f482..dae76fd 100644 --- a/install.sh +++ b/install.sh @@ -694,27 +694,27 @@ check_port_status() { fi if [[ -z "$process" ]] && command -v ss &> /dev/null; then - process=$(ss -tulnp 2>/dev/null | grep ":${port} " | grep -oP '\".*?\"' | tr -d '"' | cut -d',' -f1 | head -1) + # 使用sed替代grep -oP以提高兼容性 + process=$(ss -tulnp 2>/dev/null | grep ":${port} " | sed -n 's/.*users:(("\([^"]*\)".*/\1/p' | head -1) fi - # 3. 根据进程返回状态 + # 3. 根据进程返回状态(始终返回0以避免set -e导致脚本退出) if [[ -z "$process" ]]; then # 无法获取进程名(可能权限不足) echo "occupied" - return 1 elif [[ "$process" == "nginx" ]] || [[ "$process" =~ ^nginx: ]]; then # Nginx占用 echo "nginx" - return 1 elif [[ "$process" == "apache2" ]] || [[ "$process" == "httpd" ]] || [[ "$process" =~ apache ]]; then # Apache占用 echo "apache" - return 2 else # 其他进程 echo "other:$process" - return 3 fi + + # 始终返回0,避免set -e导致脚本退出 + return 0 } # 改进的端口配置函数