summaryrefslogtreecommitdiffstats
path: root/functions
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-01-13 02:12:03 +0100
committerDave Reisner <dreisner@archlinux.org>2013-01-13 02:12:03 +0100
commit1fb67220211a6b49870107bff052623c51ecbffb (patch)
treefc47d210c401b916a8985d4eb6b3c88d3ba4d129 /functions
parentbe1e0c6506ed892a7e8031d69b1a7110a79070d4 (diff)
downloadmkinitcpio-1fb67220211a6b49870107bff052623c51ecbffb.tar.gz
mkinitcpio-1fb67220211a6b49870107bff052623c51ecbffb.tar.xz
factor out kver detection to functions file
This leaves bash completion with a duplication, but this is intentional to avoid pulling in the entire functions file and worrying about pollution. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Diffstat (limited to 'functions')
-rw-r--r--functions22
1 files changed, 22 insertions, 0 deletions
diff --git a/functions b/functions
index 5a44ac9..8be43ed 100644
--- a/functions
+++ b/functions
@@ -133,6 +133,28 @@ parseopts() {
return 0
}
+kver() {
+ # this is intentionally very loose. only ensure that we're
+ # dealing with some sort of string that starts with something
+ # resembling dotted decimal notation. remember that there's no
+ # requirement for CONFIG_LOCALVERSION to be set.
+ local kver re='^[[:digit:]]+(\.[[:digit:]]+)+'
+
+ # scrape the version out of the kernel image. locate the offset
+ # to the version string by reading 2 bytes out of image at at
+ # address 0x20E. this leads us to a string of, at most, 128 bytes.
+ # read the first word from this string as the kernel version.
+ local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1")
+ [[ $offset = +([0-9]) ]] || return 1
+
+ read kver _ < \
+ <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
+
+ [[ $kver =~ $re ]] || return 1
+
+ printf '%s' "$kver"
+}
+
plain() {
local mesg=$1; shift
printf " $_color_bold$mesg$_color_none\n" "$@" >&1