Add scripts to create myops-getqueryview:
[myops.git] / web / collect / client / get_bootcd_version.sh
diff --git a/web/collect/client/get_bootcd_version.sh b/web/collect/client/get_bootcd_version.sh
new file mode 100755 (executable)
index 0000000..5ab3465
--- /dev/null
@@ -0,0 +1,76 @@
+#!/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