+#!/bin/bash
+
+kernel=$1
+
+function get_version () {
+
+ DEVICE=$1
+ cd /tmp
+ if [ -f /mnt/boot/pl_version ]; then
+ cat /mnt/boot/pl_version
+ fi
+}
+function get_kernel_version () {
+
+ DEVICE=$1
+ cd /tmp
+ if [ -f /mnt/boot/kernel ]; then
+ strings /mnt/boot/kernel | grep planetlab
+ else
+ echo "No kernel at /mnt/boot/kernel"
+ fi
+}
+
+function mount_works () {
+ DEVICE=$1
+ msg="mount: you must specify the filesystem type"
+ r=`mount $DEVICE /mnt/boot 2>&1`
+ if [ "$r" == "$msg" ] ; then
+ return 1;
+ else
+ return 0;
+ fi
+}
+
+mkdir -p /mnt/boot
+DL=`./sysinfo/systeminfo.py | sort -n | awk '{print $2}' | head -1`
+if [ -z "$kernel" ] ; then
+ V="No BootImage Found"
+else
+ V="Unable to find kernel image"
+fi
+(
+ flock -x 400
+ for dev in /dev/cdrom /dev/cdrom1 $DL ${DL}4 ${DL}1; do
+ if [ -b $dev ] ; then
+ if mount_works $dev ; then
+ if [ -z "$kernel" ] ; then
+ V=$( get_version $dev )
+ else
+ V=$( get_kernel_version $dev )
+ fi
+ r=`umount /mnt/boot 2>&1`
+ msg2="umount: /mnt/boot: device is busy"
+ if [ "$r" == "$msg2" ] ; then
+ r=`umount /mnt/boot 2>&1`
+ fi
+ break
+ fi
+ fi
+ done
+
+ if [ -z "$kernel" ] ; then
+ if [ -z "$V" ] ; then
+ wc=$( dmesg | grep "Buffer I/O error" | wc -l )
+ if [ $wc -gt 0 ] ; then
+ echo "Multiple IO errors prevent reading: $wc"
+ else
+ echo "No BootImage Found"
+ fi
+ else
+ echo $V
+ fi
+ else
+ echo $V
+ fi
+) 400>/var/lock/myops.mount