3 # Check if the running kernel has the same version string as the on-disk
6 # Copyright 2008 Peter Palfrader
8 # Permission is hereby granted, free of charge, to any person obtaining
9 # a copy of this software and associated documentation files (the
10 # "Software"), to deal in the Software without restriction, including
11 # without limitation the rights to use, copy, modify, merge, publish,
12 # distribute, sublicense, and/or sell copies of the Software, and to
13 # permit persons to whom the Software is furnished to do so, subject to
14 # the following conditions:
16 # The above copyright notice and this permission notice shall be
17 # included in all copies or substantial portions of the Software.
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 $i = index(<>, "'"$needle"'");
43 print $i,"\n"' < "$file"
47 local image GZHDR1 GZHDR2 off
51 GZHDR1="\x1f\x8b\x08\x00"
52 GZHDR2="\x1f\x8b\x08\x08"
54 off=`get_offset "$image" $GZHDR1`
55 [ "$?" != "0" ] && off="-1"
56 if [ "$off" -eq "-1" ]; then
57 off=`get_offset "$image" $GZHDR2`
58 [ "$?" != "0" ] && off="-1"
60 if [ "$off" -eq "0" ]; then
62 elif [ "$off" -ne "-1" ]; then
63 (dd ibs="$off" skip=1 count=0 && dd bs=512k) < "$image" 2>/dev/null | zcat 2>/dev/null
66 echo "ERROR: Unable to extract kernel image." 2>&1
69 on_disk_compressed="/boot/vmlinuz-`uname -r`"
70 on_disk_uncompressed="/boot/vmlinux-`uname -r`"
72 if [ -e "$on_disk_compressed" ]; then
73 on_disk="$on_disk_compressed"
74 on_disk_version="`get_image "$on_disk" | strings | grep 'Linux version' | head -n1`"
75 elif [ -e "$on_disk_uncompressed" ]; then
76 on_disk="$on_disk_uncompressed"
77 on_disk_version="`cat "$on_disk" | strings | grep 'Linux version' | head -n1`"
79 echo "WARNING: Neither $on_disk_uncompressed nor $on_disk_compressed do exist - I have no idea which kernel I am running"
83 if [ -z "$on_disk_version" ] ; then
84 echo "UNKNOWN: Failed to get a version string from image $on_disk"
88 running_version="`cat /proc/version`"
89 if [ -z "$running_version" ] ; then
90 echo "UNKNOWN: Failed to get a version string from running system"
94 if [ "$running_version" != "$on_disk_version" ]; then
95 echo "WARNING: Running kernel does not match on-disk kernel image: [$running_version != $on_disk_version]"
98 echo "OK: Running kernel matches on disk image: [$running_version]"