home *** CD-ROM | disk | FTP | other *** search
/ ftp.jcu.edu.au / 2014.06.ftp.jcu.edu.au.tar / ftp.jcu.edu.au / v6.3.2b / install_verify < prev    next >
Text File  |  2005-03-23  |  7KB  |  329 lines

  1. #!/bin/sh
  2.  
  3.  
  4. #    Copyright (c) 1996-2004 Brocade Communications Systems, Inc.
  5. #    All rights reserved.
  6. #
  7. #    Description:
  8. #      Verification of an install for a particular platform.
  9. #
  10.  
  11.  
  12. usage() {
  13.     program=`basename $0`
  14.  
  15.     echo "Usage: $program <platform> <TEST | EXTENDED> package"
  16.     echo "  platform      <Optional> hardware must be this platform."
  17.     echo "  TEST          Perofrm read/write testing of compact flash memory."
  18.     echo "  EXTENDED      Perform extended testing of compact flash memory."
  19.     echo "  package       Package to install."
  20.  
  21.     echo ""
  22.     echo "Platform \"$PLATFORM\" packages are:"
  23.     ls ./$PLATFORM/*.plist 2>/dev/null | cut -d"/" -f3 | cut -d "." -f1
  24.     exit 1
  25. }
  26.  
  27. #
  28. # exit_out
  29. #
  30. exit_out()
  31. {
  32.     if [ $error = TRUE ]
  33.     then
  34.     echo "SCRIPT: verify FAILED with $warn_count warnings."
  35.     exit 1
  36.     else
  37.     if [ $warn_count -gt 0 ]
  38.     then
  39.         echo "SCRIPT: verify PASSED with $warn_count warnings."
  40.     else
  41.         echo "SCRIPT: verfiy PASSED."
  42.     fi
  43.     exit 0
  44.     fi
  45. }
  46.  
  47. #
  48. # do_command <warn/error> <command...>
  49. #
  50. do_command()
  51. {
  52.     warn=$1
  53.     shift
  54.     $*
  55.     if [ $? -ne 0 ]
  56.     then
  57.     if [ $warn = TRUE ]
  58.     then
  59.         echo "SCRIPT: Warning - failed $*"
  60.         warn_count=`expr $warn_count + 1`
  61.         return 1
  62.     else
  63.         echo "SCRIPT: ERROR - failed $*"
  64.         continue=FALSE
  65.         error=TRUE
  66.         exit_out
  67.     fi
  68.     fi
  69.     return 0
  70. }
  71. #
  72. # verify-rpms <plist> <root>
  73. #
  74. verifyrpms()
  75. {
  76.     /bin/rm -f /tmp/partition_error
  77.  
  78.     LIST=$PLATFORM/$1
  79.  
  80.     if [ ! -f $LIST ] || [ ! -r $LIST ]; then
  81.     echo "SCRIPT: Cannot open/read package list to verify."
  82.     exit 1
  83.     fi
  84.  
  85.     if [ ! -z $2 ]; then
  86.     ROOT=$2
  87.     else
  88.         ROOT=/
  89.     fi
  90.  
  91.     RPM="rpm  -V -p --root $ROOT"
  92.  
  93.     echo "SCRIPT: Verifying  RPMs from $LIST rooted at $ROOT..."
  94.  
  95.     for package in `cat $LIST | dd skip=18 bs=16 2> /dev/null | grep -v '#' | xargs`;
  96.     do
  97.         result="`$RPM $package | \
  98.             grep -e '5' -e 'missing' -e 'failed' | \
  99.             grep -v ' c ' | \
  100.             grep -v '/etc/inittab' | \
  101.             grep -v '/etc/modules.conf' | \
  102.             grep -v '/etc/rc.d/rc.pwdinit' | \
  103.             grep -v '/etc/idle.conf' | \
  104.             grep -v '/fabos/share/SWBD' | \
  105.             grep -v '/etc/services' | \
  106.             grep -v '/etc/raslog.conf' | \
  107.             grep -v '/etc/config/webtools' | \
  108.             grep -v '/boot/bootrom.bin'`"
  109.         if [ ! -z "$result" ]
  110.         then
  111.         $RPM $package | \
  112.             grep -e '5' -e 'missing' -e 'failed' | \
  113.             grep -v ' c ' | \
  114.             grep -v '/etc/inittab' | \
  115.             grep -v '/etc/modules.conf' | \
  116.             grep -v '/etc/rc.d/rc.pwdinit' | \
  117.             grep -v '/etc/idle.conf' | \
  118.             grep -v '/fabos/share/SWBD' | \
  119.             grep -v '/etc/services' | \
  120.             grep -v '/etc/raslog.conf' | \
  121.             grep -v '/etc/config/webtools' | \
  122.             while read line
  123.         do
  124.             file=`echo "$line" | cut -d"/" -f3-`
  125.             if [ ! -f ./$PLATFORM/Mfgtests/$file ]
  126.             then
  127.                 echo ""
  128.                 echo "FAILED verify of rpm ${DEVICE}${partition} $package because of:"
  129.                 echo $line
  130.                 touch /tmp/partition_error
  131.             fi
  132.         done
  133.         else
  134.         echo -n "."
  135. #        echo "passed verify of rpm ${DEVICE}${partition} $package"
  136.         fi
  137.     done
  138.     if [ -f /tmp/partition_error ]
  139.     then
  140.     partition_error=1
  141.     /bin/rm -f /tmp/partition_error
  142.     fi
  143. }
  144.  
  145. #
  146. # test_for_product <candidate>
  147. #
  148. test_for_product()
  149. {
  150.     # Normalize the argument
  151.     candidate=`echo $1 | tr "A-Z" "a-z"`
  152.  
  153.     #
  154.     # Look up the name in the list of known names for the platform ID
  155.     #
  156.     target=`grep $PLATFORM platform_names`
  157.     if [ "$target" == "" ]
  158.     then
  159.     echo "SCRIPT: Unknown Platform found $PLATFORM"
  160.     usage
  161.     fi
  162.     if [ "`echo $target | grep $candidate`" = "" ]
  163.     then
  164.     # It is not the one we are, is it a different product?
  165.     if [ "`grep $candidate platform_names`" != "" ]
  166.     then
  167.         # output error message if valid product, otherwise it is not a 
  168.         # product argument, and we use PLATFORM
  169.         echo "SCRIPT: Actual platform ($PLATFORM) does not match specified platform $1."
  170.         echo "SCRIPT: ERROR - failed $0 $*"
  171.         continue=FALSE
  172.         error=TRUE
  173.         exit_out
  174.     fi
  175.     echo FALSE
  176.     else
  177.     echo $PLATFORM
  178.     fi
  179. }
  180.  
  181. #
  182. # test_for_test <candidate>
  183. #
  184. test_for_test()
  185. {
  186.     if [ "$1" = "TEST" ]
  187.     then
  188.     echo 1
  189.     else
  190.     if [ "$1" = "EXTENDED" ]
  191.     then
  192.         echo 2
  193.     else
  194.         echo FALSE
  195.     fi
  196.     fi
  197. }
  198.  
  199. #
  200. # test_for_package <candidate>
  201. #
  202. test_for_package()
  203. {
  204.     abc=`echo $1 | tr -s '[:upper:]' '[:lower:]'`
  205.  
  206.     #
  207.     # See if first parameter was a PACKAGE
  208.     #
  209.     if [ -f ./$PLATFORM/$abc.plist ]
  210.     then
  211.     echo $abc
  212.     else
  213.     echo FALSE
  214.     fi
  215. }
  216. #
  217. # parse the command line arguments
  218. #
  219. parse_arguments()
  220. {
  221.     # check explicitly for package and test parameters, and assume 
  222.     # anything else is the plaftorm validation
  223.     #
  224.     while [ $# -gt 0 ]
  225.     do
  226.     result=`test_for_product $1`
  227.     if [ "$result" = "FALSE" ]
  228.     then
  229.         result=`test_for_test $1`
  230.         if [ "$result" = "FALSE" ]
  231.         then
  232.         result=`test_for_package $1`
  233.         if [ "$result" = "FALSE" ]
  234.         then
  235.             printf "SCRIPT: Unknown parameter %s\n" $1
  236.             usage
  237.         else
  238.             PACKAGE=$result
  239.         fi
  240.         else
  241.         do_test=$result
  242.         fi
  243.     else
  244.         PLATFORM=$result
  245.     fi
  246.     shift
  247.     done
  248.  
  249.     #######################
  250.     # Check the parameters
  251.     #
  252.     if [ ! -f ./$PLATFORM/$PACKAGE.plist ]
  253.     then
  254.     printf "SCRIPT: Incorrect package %s\n" $PACKAGE
  255.     usage
  256.     fi
  257.  
  258.     case $PLATFORM in
  259.     "SWBD12" ) REVISION=3;;
  260.     *) REVISION=0;;
  261.     esac
  262. }
  263. #------------------------------
  264. # BEGIN MAIN PART OF THE SCRIPT
  265. # BEGIN MAIN PART OF THE SCRIPT
  266. #------------------------------
  267.  
  268. if [ -z `pwd | grep load` ]
  269. then
  270.     echo "SCRIPT: ERROR verification directory is not mounted on /load."
  271.     exit 1
  272. fi
  273.  
  274. for mnt in `mount | cut -d" " -f3 | grep "/mnt"`
  275. do
  276.     umount $mnt
  277. done
  278.  
  279. DEVICE='hda'
  280. TMPMNT='/mnt'
  281.  
  282. warn_count=0
  283. continue=TRUE
  284. error=FALSE
  285.  
  286. PLATFORM=`sin | \
  287.           /bin/grep Platform | \
  288.           /usr/bin/cut -d" " -f2 | \
  289.           /usr/bin/cut -d"," -f1`
  290.  
  291. REVISION=`sin | \
  292.           /bin/grep Platform | \
  293.           /usr/bin/cut -d" " -f4`
  294.  
  295. ######################
  296. # parse the arguments
  297. #
  298. parse_arguments $*
  299.  
  300. ##############################################
  301. # Let's get down to it and install this thing
  302. #
  303. echo "SCRIPT: VERIFYING installation for platform: $PLATFORM revision: $REVISION package $PACKAGE"
  304.  
  305. for partition in 1 2; do
  306.   if [ $continue = TRUE ]
  307.   then
  308.     echo "SCRIPT: Checking file system on /dev/${DEVICE}${partition}..."
  309.  
  310.     do_command FALSE mount /dev/${DEVICE}${partition} ${TMPMNT}
  311.  
  312.     partition_error=0
  313.     verifyrpms $PACKAGE.plist ${TMPMNT}
  314.     echo ""
  315.     if [ $partition_error -ne 0 ]
  316.     then
  317.     echo "SCRIPT: verification FAILED on partition ${DEVICE}${partition}"
  318.     error=TRUE
  319.     else
  320.     echo "SCRIPT: verification PASSED on partition ${DEVICE}${partition}"
  321.     fi
  322.     echo "SCRIPT: Unmounting file system..."
  323.  
  324.     do_command FALSE umount ${TMPMNT}
  325.   fi
  326. done
  327.  
  328. exit_out
  329.