Author: jfthomps
Date: Thu Mar 15 19:57:37 2012
New Revision: 1301171

URL: http://svn.apache.org/viewvc?rev=1301171&view=rev
Log:
added code to better handle when the node only has one disk but it is detected 
as /dev/sdb instead of /dev/sda
corrected and improved some error messages
added loop at end of script to sleep forever if 'reboot' was not passed on the 
kernel command line

Modified:
    incubator/vcl/sandbox/xcat2partimageng/partimageng

Modified: incubator/vcl/sandbox/xcat2partimageng/partimageng
URL: 
http://svn.apache.org/viewvc/incubator/vcl/sandbox/xcat2partimageng/partimageng?rev=1301171&r1=1301170&r2=1301171&view=diff
==============================================================================
--- incubator/vcl/sandbox/xcat2partimageng/partimageng (original)
+++ incubator/vcl/sandbox/xcat2partimageng/partimageng Thu Mar 15 19:57:37 2012
@@ -1,6 +1,5 @@
 #!/bin/bash
 export PATH=/bin:/usr/bin:/sbin:/usr/sbin
-unalias ls
 
 partimageinstall () {
     # based on install.sh from xcat 1.3 by Egan Ford
@@ -9,31 +8,41 @@ partimageinstall () {
     myimage=$(basename $1 .img) # needs to be image without path or .gz
     disk=$(basename $2) # needs to be disk - i.e. sda
 
+    altdisk=$disk
+    if [[ "$disk" = "sdb" ]] &&
+        dmesg | grep -q 'SCSI device sdb' &&
+        ! dmesg | grep -q 'SCSI device sda' &&
+        [[ -f $myimage-sda.sfdisk ]] &&
+        [[ ! -f $myimage-sdb.sfdisk ]] ; then
+            altdisk="sda"
+    fi
+
     DONE=0
     OLD=""
 
     cd $imgpath
-    NUMPART=$(cat $myimage-$disk.sfdisk | grep "^/dev/$disk" | grep -v Win95 | 
grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v "Id= 5" | grep -v 
"Id=82" | grep -v swap | awk '{print $1}' | wc -l)
-    for i in $(cat $myimage-$disk.sfdisk | grep "^/dev/$disk" | grep -v Win95 
| grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v "Id= 5" | grep 
-v "Id=82" | grep -v swap | awk '{print $1}')
+    NUMPART=$(cat $myimage-$altdisk.sfdisk | grep "^/dev/$altdisk" | grep -v 
Win95 | grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v "Id= 5" | 
grep -v "Id=82" | grep -v swap | awk '{print $1}' | wc -l)
+    for i in $(cat $myimage-$altdisk.sfdisk | grep "^/dev/$altdisk" | grep -v 
Win95 | grep -v Extended | grep -v Empty | grep -v "Id= 0" | grep -v "Id= 5" | 
grep -v "Id=82" | grep -v swap | awk '{print $1}')
     do
-        PARTNAME=$(basename $i)
+        PARTNAME=$(basename ${i/$altdisk/$disk})
         if (("$NUMPART" > "1"))
         then
-            PARTNAMEIMG=${PARTNAME/#??/part}
+            #PARTNAMEIMG=${PARTNAME/#??/part}
+            PARTNAMEIMG=$(basename $i | sed 's/^../part/')
             INPUTFILE=$myimage-$PARTNAMEIMG.gz
         else
             INPUTFILE=$myimage.gz
         fi
         if [ "$DONE" = "0" ]
         then
-            if [ -r $myimage-$disk.sfdisk ]
+            if [ -r $myimage-$altdisk.sfdisk ]
             then
-                sfdisk /dev/$disk <$myimage-$disk.sfdisk
+                sfdisk /dev/$disk <$myimage-$altdisk.sfdisk
             fi
-            if [ -r $myimage-$disk.mbr ]
+            if [ -r $myimage-$altdisk.mbr ]
             then
-                dd if=$myimage-$disk.mbr of=/dev/$disk
-                sfdisk /dev/$disk <$myimage-$disk.sfdisk
+                dd if=$myimage-$altdisk.mbr of=/dev/$disk
+                sfdisk /dev/$disk <$myimage-$altdisk.sfdisk
             else
                 OLD=".6.0"
                 partimage$OLD -b -f3 restmbr $INPUTFILE
@@ -74,6 +83,13 @@ partimagesave () {
     myimage=$(basename $1 .img) # needs to be image without path or .gz
     disk=$(basename $2) # needs to be disk - i.e. sda
 
+    altdisk=$disk
+    if [[ "$disk" = "sdb" ]] &&
+        dmesg | grep -q 'SCSI device sdb' &&
+        ! dmesg | grep -q 'SCSI device sda' ; then
+            altdisk="sda"
+    fi
+
     logger -t xcat "Getting partitons for $disk"
     echo "Partitions for $disk"
     sfdisk -l /dev/$disk
@@ -82,11 +98,15 @@ partimagesave () {
     NUMPART=$(sfdisk -l /dev/$disk | grep "^/dev/$disk" | grep -v Win95 | grep 
-v Extended | grep -v Empty | grep -v "Id= 0" | grep -v swap | awk '{print $1}' 
| wc -l)
     logger -t xcat "number of partitions found: $NUMPART"
 
-    dd if=/dev/$disk of=$imgpath/$myimage-$disk.mbr count=1 bs=512
+    dd if=/dev/$disk of=$imgpath/$myimage-$altdisk.mbr count=1 bs=512
     sfdisk /dev/$disk -d >$imgpath/$myimage-$disk.sfdisk.tmp
     if [ -s $imgpath/$myimage-$disk.sfdisk.tmp ]
     then
         mv -f $imgpath/$myimage-$disk.sfdisk.tmp $imgpath/$myimage-$disk.sfdisk
+                 if [[ "$disk" != "$altdisk" ]]; then
+                         cat $imgpath/$myimage-$disk.sfdisk | sed 
"s/$disk/$altdisk/" > $imgpath/$myimage-$altdisk.sfdisk
+                         rm -f $imgpath/$myimage-$disk.sfdisk
+        fi
     else
         rm -f $imgpath/$myimage-$disk.sfdisk.tmp
     fi
@@ -108,6 +128,7 @@ partimagesave () {
         if ! partimage -z1 -f3 -odbc save /dev/$PARTNAME $OUTPUTFILE; then
             echo partimage exited with a non-zero status, failing
             logger -t xcat "partimage exited with a non-zero status, failing"
+            exit # do we exit or return a value to fail?
             return 1
         fi
     done
@@ -141,6 +162,8 @@ if ! ping -c 1 $MASTER &> /dev/null; the
     /sbin/reboot
     exit
 fi
+
+logger -t xcat "mounting $IMAGELIBSERVER:$IMAGELIBINSTALLDIR --> /install"
 mount -o nfsvers=3,tcp,nolock,rw $IMAGELIBSERVER:$IMAGELIBINSTALLDIR /install
 
 reboot=''
@@ -172,16 +195,16 @@ done
 
 sleep 10
 
-devices=`ls -l /dev/disk/by-id | awk '{print $11}'`
+devices=`\ls -l /dev/disk/by-id | awk '{print $11}'`
 logger -t xcat "disks: $devices"
 
 if [ "x$device" == "x" ] ; then
-    device=$(ls /dev/disk/by-id -l | grep -v total | head -1 | awk '{print 
$11}' | sed 's/[\.\/]//g')
+    device=$(\ls /dev/disk/by-id -l | grep -v total | head -1 | awk '{print 
$11}' | sed 's/[\.\/]//g')
     if ! echo $device | egrep -q '(sda|hda)'; then
         device=$(cat /proc/partitions  | egrep -v '(ram|major)' | egrep '\w' | 
head -1 | awk '{print $4}')
     fi
     if ! echo $device | egrep -q '(sda|hda)'; then
-        device=$(ls /dev/disk/by-id -l | grep -v total | head -1 | awk '{print 
$11}' | sed 's/[\.\/]//g')
+        device=$(\ls /dev/disk/by-id -l | grep -v total | head -1 | awk 
'{print $11}' | sed 's/[\.\/]//g')
         if ! echo $device | egrep -q '(sdb|hdb)'; then
             device=$(cat /proc/partitions  | egrep -v '(ram|major)' | egrep 
'\w' | head -1 | awk '{print $4}')
         fi
@@ -202,36 +225,48 @@ fi
 if [ "x$action" == "xsave" ] ; then
     touch /tmp/save
     if [ "$usepartimageng" = "0" ]; then
+                 cmd="partimage"
         partimagesave $image $device
         rc=$?
+        if [ "$rc" = "0" ]; then
+            echo "partimage successfully saved image"
+            logger -t xcat "partimage successfully saved image"
+        else
+            echo "partimage failed to saved image"
+            logger -t xcat "partimage failed to saved image"
+        fi
     else
+                 cmd="partimage-ng"
         echo running /sbin/partimage-ng -b $blocks save $device $image
         logger -t xcat "running /sbin/partimage-ng -p -b $blocks save $device 
$image"
         /sbin/partimage-ng -p -b $blocks save $device $image > /tmp/partimageng
-        echo gzipping $image
-        logger -t xcat "gzipping $image"
-        touch /tmp/savegzip
-        if gzip $image; then
-            echo gzipping finished, removing .gz extension from filename
-            logger -t xcat "gzipping finished, removing .gz extension from 
filename"
-            mv $image.gz $image
-        else
-            echo "gzipping failed"
-            logger -t xcat "gzipping failed"
-        fi
         rc=$?
+        if [ "$rc" = "0" ]; then
+            echo gzipping $image
+            logger -t xcat "gzipping $image"
+            touch /tmp/savegzip
+            if gzip $image; then
+                echo gzipping finished, removing .gz extension from filename
+                logger -t xcat "gzipping finished, removing .gz extension from 
filename"
+                mv $image.gz $image
+            else
+                echo "gzipping failed"
+                logger -t xcat "gzipping failed"
+            fi
+        fi
     fi
     if [ "$rc" = "0" ]; then
         touch $image.capturedone
-        logger -t xcat "partimage-ng exited normally"
+        logger -t xcat "$cmd exited normally"
     else
         touch $image.capturefailed
-        logger -t xcat "partimage-ng failed with exit code $rc"
+        logger -t xcat "$cmd failed with exit code $rc"
     fi
 elif [ "x$action" == "xrestore" ] ; then
     touch /tmp/restore
     testfile=$(echo $image | awk -F '.' '{print $1}')
-    if ls -1 $testfile*.mbr > /dev/null; then
+    if \ls -1 $testfile*.mbr > /dev/null; then
+        partimageinstall $image $device
         partimageinstall $image $device
         rc=$?
         if [ "$rc" = "0" ]; then
@@ -271,4 +306,6 @@ fi
 
 if [ "x$reboot" == "xreboot" ] ; then
     /sbin/reboot
+else
+       while : ; do sleep 3600 ; done
 fi


Reply via email to