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 } # 改进的端口配置函数