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 版本,使用默认配置文件"