"Fossies" - the Fresh Open Source Software Archive

Member "aoe-aoe6-86/aoetools-36/coraid-update" (4 Jul 2015, 2184 Bytes) of archive /linux/misc/aoe-aoe6-86.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #! /bin/sh
    2 # usage: coraid-update {update file} {AoE target}
    3 # coraid-update depends upon sysfs mounted on /sys
    4 
    5 # The destination must be,
    6 #   1) an AoE target ready for I/O, and
    7 #   2) not too big to be an update target
    8 #
    9 # Later, when CORAID appliances mark update targets with special ATA
   10 # device identify content or special target content, a prompt should
   11 # be added after the check of the target's size if the identifying
   12 # content is not detected.
   13 # 
   14 # The update file must either, 
   15 #   1) be an SR tarc file that looks OK to the local tar, or
   16 #   2) any file not ending in ".tarc".
   17 
   18 # size of update LUN in /proc/partitions is 40000
   19 max=70000
   20 
   21 usage="usage: coraid-update {update file} {AoE device}"
   22 if test "$#" != 2; then
   23     echo "$usage" 1>&2
   24     exit 1
   25 fi
   26 update="$1"
   27 ulb="$2"
   28 
   29 # if it's an update target, it should be in `aoe-stat`
   30 aoe-stat | awk -vt="`basename $ulb`" '
   31 BEGIN{fail=1}
   32 $1==t{fail=0}
   33 END{exit fail}' || {
   34     exec 1>&2
   35     echo "coraid-update Error: \"$ulb\" is not an AoE target"
   36     echo "$usage"
   37     exit 1
   38 }
   39 
   40 # it should have a size no larger than $max in /proc/partitions
   41 t="`echo $ulb | sed 's!^/dev/!!'`"
   42 awk -vt="$t" '$NF==t{print $3}' /proc/partitions |
   43 awk -vhi=$max -vdev="$ulb" '
   44 BEGIN{
   45     err = "could not get size of " dev
   46 } {
   47     err = "none"
   48     if ($1 > hi) {
   49         err = dev " is too large to be an update target"
   50         exit
   51     }
   52 } END{
   53     if (err != "none") {
   54         print "Error coraid-update: " err > "/dev/stderr"
   55         exit 1
   56     }
   57     exit 0
   58 }' || exit 1
   59 
   60 # this test should be removed when it is performed on the appliance
   61 # 
   62 # For a 2734080-byte tarc file, an incomplete file of 2727450 bytes passes
   63 # this test, but one of 2727400 does not.  So this test isn't fullproof.
   64 # 
   65 if test "`echo \"$update\" | grep '\.tarc$'`"; then
   66     tar tf "$update" > /dev/null 2>&1 || {
   67         exec 1>&2
   68         echo "coraid-update Error: \"$update\" does not appear to be a valid tarc file"
   69         exit 1
   70     }
   71 fi
   72 if test ! -r "$update"; then
   73     echo "coraid-update Error: \"$update\" is not readable" 1>&2
   74     exit 1
   75 fi
   76 
   77 # send it over and complain on error
   78 if ! dd if="$update" of="$ulb" 2> /dev/null || ! sync; then
   79     exec 1>&2
   80     echo "coraid-update Error: could not successfully write \"$update\" to \"$ulb\""
   81     exit 1
   82 fi