Remove garbage before "Linux version"

Kernel 6.1 onwards seems to have strings re-arranged so that a newline
no long happens right before the "Linux version" string.

Tested with:

4650945eaabe1297985759ef8e3d4153  archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20230306-1_armhf.deb
93830b458685feabf2262f474be4a0e0  archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20230317-1_armhf.deb
5449f3dd337c594491f3e73b6ee97cbf  archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20230405-1_armhf.deb

29384 5.15.84+
28712 6.1.19+ 6.1.21+
This commit is contained in:
Hin-Tak Leung 2023-04-10 20:36:18 +01:00
parent 977a7ff321
commit a57389693c

View file

@ -68,7 +68,7 @@ function get_kernel_version() {
ZIMAGE=/boot/kernel.img
[ -f /boot/firmware/vmlinuz ] && ZIMAGE=/boot/firmware/vmlinuz
IMG_OFFSET=$(LC_ALL=C grep -abo $'\x1f\x8b\x08\x00' $ZIMAGE | head -n 1 | cut -d ':' -f 1)
_VER_RUN=$(dd if=$ZIMAGE obs=64K ibs=4 skip=$(( IMG_OFFSET / 4)) 2>/dev/null | zcat | grep -a -m1 "Linux version" | strings | awk '{ print $3; }')
_VER_RUN=$(dd if=$ZIMAGE obs=64K ibs=4 skip=$(( IMG_OFFSET / 4)) 2>/dev/null | zcat | grep -a -m1 "Linux version" | LC_ALL=C sed -e 's/^.*Linux/Linux/' | strings | awk '{ print $3; }')
}
echo "$_VER_RUN"
return 0