diff options
| author | Shiji Yang | 2025-06-17 14:06:38 +0000 |
|---|---|---|
| committer | Hauke Mehrtens | 2025-07-14 20:30:20 +0000 |
| commit | a0fe3cfb62fbf0b5f599c90e488727f493223429 (patch) | |
| tree | 0a4fee795085bf9ef084166b1ae7ce34ad8e1186 | |
| parent | b626262226a87bcb6ca7e71d776ffe059a981060 (diff) | |
| download | openwrt-a0fe3cfb62fbf0b5f599c90e488727f493223429.tar.gz | |
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 <yangshiji66@outlook.com>
Link: https://github.com/openwrt/openwrt/pull/19172
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
| -rw-r--r-- | package/base-files/files/lib/functions/system.sh | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index f43281b5dc..eaed0fba11 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 +} |