From a2fca42ff9bd40539b7b0955c8e1757b424bb6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Fri, 10 Apr 2026 00:12:58 +0800 Subject: [PATCH] =?UTF-8?q?fix(sysctl):=20=E6=8F=90=E5=8F=96=20Debian=20?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=E4=B8=BA?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/1.sh b/1.sh index f1c47de..962ae7a 100644 --- a/1.sh +++ b/1.sh @@ -82,7 +82,25 @@ sysctl_config() { SYSCTL_CONF="/etc/sysctl.conf" SYSCTL_CLEANUP_FILES=("/etc/sysctl.conf" "/etc/sysctl.d/99-sysctl.conf" "/etc/sysctl.d/999-custom.conf") if [ "$SYSTEM_TYPE" = "debian" ]; then - DEBIAN_VERSION=$(grep -oP 'VERSION_ID="\K[^"]+' /etc/os-release 2>/dev/null || cat /etc/debian_version 2>/dev/null | cut -d. -f1) + get_debian_major_version() { + local version_id="" + + if [ -r /etc/os-release ]; then + version_id=$(sed -n 's/^VERSION_ID="\?\([^"[:space:]]*\)"\?$/\1/p' /etc/os-release | head -n 1) + fi + + if [ -z "$version_id" ] && [ -r /etc/debian_version ]; then + version_id=$(head -n 1 /etc/debian_version) + fi + + version_id=${version_id%%/*} + version_id=${version_id%%.*} + + if [[ "$version_id" =~ ^[0-9]+$ ]]; then + echo "$version_id" + fi + } + DEBIAN_VERSION=$(get_debian_major_version) if [ -z "$DEBIAN_VERSION" ]; then echo "无法确定 Debian 版本,使用默认配置文件"