From 3d99fc13ba42c1e6d96142cab5f692684f4d8fdc Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 17 Apr 2026 06:10:45 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20v2.1=20ERR=20trap=20=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=20SIGPIPE(141)=20+=20sshd=20-T=20=E7=AE=A1=E9=81=93=E6=94=B9?= =?UTF-8?q?=20grep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/stream-unlock.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/stream-unlock.sh b/scripts/stream-unlock.sh index 483b50c..ba954a4 100644 --- a/scripts/stream-unlock.sh +++ b/scripts/stream-unlock.sh @@ -27,7 +27,7 @@ set -Eeuo pipefail # ============ 常量 ============ -readonly SCRIPT_VERSION="2.0" +readonly SCRIPT_VERSION="2.1" readonly LOG_FILE="/var/log/stream-unlock.log" readonly BACKUP_ROOT="/etc/stream-unlock-backup" readonly STATE_FILE="/etc/stream-unlock.state" @@ -94,6 +94,8 @@ die() { err "$@"; exit 1; } on_err() { local rc=$? cmd=${BASH_COMMAND:-?} line=${BASH_LINENO[0]:-?} + # 141 = SIGPIPE, 管道正常关闭 (head/awk -exit 等), 不是真错误 + [[ $rc -eq 141 ]] && return 0 err "第 ${line} 行执行失败 (退出码 $rc): $cmd" err "请查看日志: $LOG_FILE" exit $rc @@ -246,7 +248,7 @@ fw_has_iptables_drop_policy() { fw_allow_ssh_first() { # 在启用 ufw / firewalld 之前无条件保证 SSH 不被锁 local ssh_port - ssh_port="$(sshd -T 2>/dev/null | awk '/^port /{print $2; exit}')" + ssh_port="$(sshd -T 2>/dev/null | grep -oP '^port \K\d+' || true)" [[ -z "$ssh_port" ]] && ssh_port=22 case "$OS" in debian|arch)