fix(sysctl): 提取 Debian 版本获取逻辑为独立函数

This commit is contained in:
严浩
2026-04-10 00:12:58 +08:00
parent 077f1259a1
commit a2fca42ff9
+19 -1
View File
@@ -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 版本,使用默认配置文件"