fix: handle Ubuntu VERSION_ID in sysctl config

This commit is contained in:
严浩
2026-04-10 00:17:11 +08:00
parent a2fca42ff9
commit 31516fd206
+20 -19
View File
@@ -38,6 +38,25 @@ load_shared_script() {
fi fi
} }
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
}
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
print_red "请使用 sudo 运行此脚本" print_red "请使用 sudo 运行此脚本"
exit 1 exit 1
@@ -82,25 +101,7 @@ sysctl_config() {
SYSCTL_CONF="/etc/sysctl.conf" SYSCTL_CONF="/etc/sysctl.conf"
SYSCTL_CLEANUP_FILES=("/etc/sysctl.conf" "/etc/sysctl.d/99-sysctl.conf" "/etc/sysctl.d/999-custom.conf") SYSCTL_CLEANUP_FILES=("/etc/sysctl.conf" "/etc/sysctl.d/99-sysctl.conf" "/etc/sysctl.d/999-custom.conf")
if [ "$SYSTEM_TYPE" = "debian" ]; then if [ "$SYSTEM_TYPE" = "debian" ]; then
get_debian_major_version() { DEBIAN_VERSION=$(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 if [ -z "$DEBIAN_VERSION" ]; then
echo "无法确定 Debian 版本,使用默认配置文件" echo "无法确定 Debian 版本,使用默认配置文件"