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 / SWBD63 / fabos-6.3.2b-10.ppc.rpm / fabos-6.3.2b.10.cpio.gz / fabos-6.3.2b.10.cpio / fabos / bin / date < prev    next >
Text File  |  2010-11-10  |  6KB  |  208 lines

  1. #!/bin/sh
  2. #
  3. #    Copyright (c) 2005-2006 Brocade Communications Systems, Inc.
  4. #    All rights reserved.
  5. #
  6. #    File name:   date
  7. #    Module name: fabos/src/utils/sys
  8. #
  9. #    This script is wrapper to the traditional /bin/date command
  10. #    to be able to save the changed date into flash. It also
  11. #    propagates date to the counterpart CP.
  12. #
  13. export PATH=/fabos/sbin:/fabos/bin:/bin:/usr/bin:/sbin
  14.  
  15. #
  16. # check_time_lic_present
  17. #
  18. # Checks whether the temporary licenses are 
  19. # installed on the switch
  20. #
  21. # Return value:
  22. #    0 if temporary licenses are installed
  23. #    1 if temporary licenses are not installed
  24. #
  25. check_time_lic_present()
  26. {
  27.     /fabos/link_bin/licenseshow | /bin/grep Expiry > /dev/null 2>&1
  28.     if [ $? -eq 0 ]
  29.     then
  30.         return 0
  31.     else
  32.         return 1
  33.     fi
  34. }
  35.  
  36.  
  37. # Skip checking Director Clock Alert Mode of FICON-CUP if first param is -nDCAM
  38. # This parameter is used when setting date through MS-API.
  39. chk_DCAM=1
  40. if [ "$1" = "-nDCAM" ]; then
  41.    chk_DCAM=0
  42.    shift
  43. fi
  44.  
  45. if [ $# -eq 0 ]; then
  46.     # Check RBAC permission on command.
  47.     /fabos/libexec/rbac_check `basename $0`
  48. else
  49.     # Check RBAC permission on identified options. 
  50.     /fabos/libexec/rbac_check `basename $0` $1
  51. fi
  52.  
  53. if [ $? -ne 0 ]; then
  54.     exit 127
  55. fi
  56.  
  57.  
  58. if [ $# -eq 0 ]; then
  59.    /bin/date
  60. elif [ $# -eq 1 ] || \
  61.      [ "$1" = "-u" ] || \
  62.      [ "$1" = "--utc" ] || \
  63.      [ "$1" = "--universal" ] || \
  64.      [ `echo $1|cut -d' ' -f1|  wc --bytes 2> /dev/null` -gt 2  -a \
  65.        `echo $1 |cut -c -2 2> /dev/null` = "-s"    ] || \
  66.      [ `echo $1|cut -d' ' -f1|  wc --bytes 2> /dev/null` -gt 2  -a \
  67.        `echo $1 |cut -c -3 2> /dev/null` = "--s"    ]; then
  68.  
  69.         user=`/usr/bin/whoami`
  70. #Find whether it is read or write command.
  71.     setOp=0
  72.  
  73.  
  74.         if [ `echo $1|cut -d' ' -f1|  wc --bytes 2> /dev/null` -gt 2 ] && [ `echo $1 |cut -c -2` = "-s" \
  75.               -o `echo $1 |cut -c -3` = "--s" ]; then
  76.                setOp=1
  77.         elif [ $# -eq 1 ]; then
  78.            arg=`echo $1 |cut -c -1`
  79.                if [ "$arg" != "-" \
  80.                     -a "$arg" != "+" ]; then
  81.                 setOp=1
  82.            fi
  83.     elif [ $# -gt 1 ]; then
  84.                if [ "$1" = "-u" \
  85.                  -o "$1" = "--utc" \
  86.                     -o "$1" = "--universal" ]; then
  87.           setOp=2
  88.                fi
  89.     fi
  90.  
  91.     #Check for Time based licenses.
  92.     if [ $setOp -eq 1 -o $setOp -eq 2 ]; then
  93.         # Check whether the temporary licenses are 
  94.         # installed on the switch
  95.         check_time_lic_present
  96.         ret_val=$?
  97.         if [ $ret_val -eq 0 ]; then
  98.             # Temporary licenses are installed
  99.             # Exit without changing the date
  100.             echo "Cannot change the date since temporary licenses are installed on the switch"
  101.             exit
  102.         fi
  103.     fi
  104.  
  105. #Check for active CP or non Ulys switch. 
  106.     chassis_info=`getchassisconfig`
  107.     ischassis=`echo $chassis_info | \
  108.         sed -n -e 's/.*Chassis based system: //gp' | \
  109.         sed -n -e 's/ .*//gp'`
  110.     num_switches=`echo $chassis_info | \
  111.         sed -n -e 's/Number of switches: //gp' | \
  112.         sed -n -e 's/ .*//gp'`
  113.     if [ "$ischassis" = "Yes" ]; then
  114.         cp=`/fabos/bin/hashow | /bin/grep Local | \
  115.         /bin/sed -e "s/[ ]*//g" | /usr/bin/cut -d: -f2 | \
  116.         /usr/bin/cut -d, -f1 2> /dev/null`
  117.     fi
  118.  
  119.     if [ $setOp -eq 0 ]; then
  120.             /bin/date "$*"
  121. #It is a write command so check if it is Active CP.
  122.         elif [ "$cp" = "Active" -o "$ischassis" != "Yes" ]; then
  123.  
  124. #Check with Time Service if date can be changed
  125.              tsIsUpdatable
  126.  
  127. # ERROR is non-zero; OK is zero
  128.              ts_ret=$?
  129.  
  130.              if [ $ts_ret -ne 0 ]; then
  131.                  exit
  132.              fi
  133.  
  134. #
  135. # Warn the user if the Director Clock Alert Mode of FICON-CUP is ON.
  136. # This check is not performed for Access Gateway
  137. #
  138.          AG_FILENAME=/etc/fabos/ag_platform.$FABOS_SWITCHNO
  139.          if [ -f $AG_FILENAME ]; then
  140.                  SWITCH_AGMODE=1
  141.          else
  142.                  SWITCH_AGMODE=0
  143.          fi
  144.          if [ $SWITCH_AGMODE -eq 0 -a $chk_DCAM -eq 1 ]; then
  145.                  ficoncupshow modereg DCAM |grep 1  > /dev/null 2>&1
  146.                  if [ $? -eq 0 ]; then
  147.                     echo "date: Warning! Director time stamp is about to be modified."
  148.                     echo "      Do you want to continue? [y/n] :"
  149.                     read response
  150.                     if [ "$response" != "y" -a "$response" != "Y" ]; then
  151.                         echo "date: Aborting date modification..."
  152.                         exit
  153.                     fi
  154.                  fi
  155.              fi
  156.  
  157.         if [ $setOp -eq 1 ]; then
  158.                /bin/date "$*"
  159.         else
  160.                /bin/date $*    
  161.         fi
  162.  
  163.                 if [ $? -eq 0 ]; then
  164.  
  165.                    /sbin/hwclock -w --utc
  166. #Find if counterpart CP exists and then proceed.
  167.                    output=`/sbin/sin|grep "Processor No"  2> /dev/null`
  168.                if [ $? -eq 0 ]; then    
  169.                       IDX=`sin |grep "Processor No"| cut -d: -f2 2> /dev/null`
  170.                       if [ $IDX -eq 0 ]; then
  171.                          RIDX=6
  172.                       else
  173.                          RIDX=5
  174.                       fi
  175.            fi
  176.  
  177.                output=`/fabos/bin/hashow 2>/dev/null`    
  178.                    if [ $? -eq 0 -a "$cp" = "Active" ]; then
  179.                       redundant=`/fabos/bin/hashow |grep "Remote" |cut -d' ' -f6 2> /dev/null`
  180.               if [ "$redundant" = "Standby" -a $setOp -eq 1 ]; then
  181.                          /usr/bin/rsh 10.0.0.$RIDX rdate -s 10.0.0.`expr $IDX + 5`
  182.                   elif [ "$redundant" = "Standby" -a $setOp -eq 2 ]; then
  183.                          /usr/bin/rsh 10.0.0.$RIDX /bin/date $*
  184.                   fi        
  185.         
  186.                       if [ "$redundant" = "Standby" -a $? -eq 0 ]; then
  187.                          /usr/bin/rsh 10.0.0.$RIDX /sbin/hwclock -w --utc
  188.                       fi
  189.                    fi
  190.                 fi
  191. # Propagate date change to fabric
  192.                 tsDateChange
  193.         else # if [ $? -eq 0 ] date write command successful
  194.            echo "date: cannot set date: operation not permitted"
  195.         fi
  196. else
  197.     check_time_lic_present
  198.     ret_val=$?
  199.     if [ $ret_val -eq 0 ]; then
  200.         # Temporary licenses are installed
  201.         # Exit without changing the date
  202.         echo "Cannot change the date since temporary licenses are installed on the switch"
  203.         exit
  204.     fi    
  205.     /bin/date $*
  206. fi
  207.  
  208.