From: Shiji Yang Date: Tue, 17 Jun 2025 14:06:38 +0000 (+0800) Subject: base-files: introduce a function to get kernel version number X-Git-Tag: v25.12.0-rc1~1972 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0fe3cfb62fbf0b5f599c90e488727f493223429;p=thirdparty%2Fopenwrt.git base-files: introduce a function to get kernel version number A new function "get_linux_version()" to normalize and print the kernel version as an integer. In some migration scripts, it is useful for checking the Linux kernel version. Signed-off-by: Shiji Yang Link: https://github.com/openwrt/openwrt/pull/19172 Signed-off-by: Hauke Mehrtens --- diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index f43281b5dce..eaed0fba110 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -315,3 +315,10 @@ macaddr_canonicalize() { dt_is_enabled() { grep -q okay "/proc/device-tree/$1/status" } + +get_linux_version() { + local ver=$(uname -r) + local minor=${ver%\.*} + + printf "%d%02d%03d" ${ver%%\.*} ${minor#*\.} ${ver##*\.} 2>/dev/null +}