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 / SWBD32 / preinst < prev    next >
Text File  |  2010-11-07  |  59KB  |  2,215 lines

  1. #!/bin/sh
  2. #
  3. #    Copyright (c) 2004-2009 Brocade Communications Systems, Inc.
  4. #    All rights reserved.
  5. #
  6. #    Description:
  7. #
  8. #        This pre-install script will be run before firmware
  9. #        download or firmwarerestore starts.  It checks the
  10. #     combination of platform (21=meteor/cp128, 42=saturn/cp256),
  11. #     chassis option (1=single switch/CER, 2=dual switch, etc),
  12. #     and other switch features to see if the firmware download
  13. #     or firmwarerestore will be accepted.
  14. #
  15. #     It can run some preprocessing code before the commands start,
  16. #     e.g. removing some files to free up disk space, etc.
  17. #
  18. #     WARNING: This file is run before firmwarerestore also. If
  19. #     you add code that only applies to firmwaredownload, you will
  20. #     need to use the "TYPE" flag to exclude firmwarerestore.
  21. #
  22. #        This version of the script is for starting firmware version 5.1.
  23. #        It needs to be updated for every minor release.
  24. #
  25.  
  26. # Trap / Ignore SIGINT so user cannot interrupt this script with ^C
  27. trap "" 2
  28. trap "" SIGPIPE
  29. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  30. #
  31. # Passed in version numbers
  32. #
  33. TO_MAJOR=$1
  34. TO_MINOR=$2
  35. TO_PATCH=$3
  36.  
  37. CUR_MAJOR=0
  38. CUR_MINOR=0
  39. CUR_PATCH=0
  40.  
  41. ENC_VERSION_STR="6.1.1_enc"
  42. ENC_VERSION_STR_DEV="6.1.1orion"
  43. CEE_VERSION_STR="6.1.2_cee"
  44. RELEASE_FILE="/tmp/release.plist"
  45. #
  46. # When firmwaredownload is invoking this script,
  47. # TYPE should be NULL; when firmwarerestore is
  48. # invoking it, TYPE is "restore"
  49. #
  50. TYPE=$4
  51.  
  52. #
  53. # Common variables
  54. #
  55. CHASSISCONFIG=/bin/getchassisconfig
  56. NULL=/dev/null
  57.  
  58. if [ "$DEBUG" = 1 ]; then
  59.     ECHO='echo -e'
  60. else
  61.     ECHO=:
  62. fi
  63.  
  64. # This should match the file name in src/lib/upgrade/upgrade.c
  65. STATUS_FILE=/tmp/fwdl_err.txt
  66. # clear status file
  67. echo > $STATUS_FILE
  68. echo " " > $STATUS_FILE
  69. if [ -z $TYPE ]; then
  70.     echo "The following item(s) need to be addressed before downloading the specified firmware:" >> $STATUS_FILE
  71. else
  72.     echo "The following items need to be addressed before restoring the specified firmware:" >> $STATUS_FILE
  73. fi
  74.  
  75. #
  76. # Error codes - these have to match the error codes
  77. # in fwdl.h.
  78. #
  79. STS_OK=0
  80. ERR_CONF_LSANMATRIX=75        # FWDL_ERR_SECMODE 0x51
  81. STS_ERR=255
  82.  
  83. RET=${STS_OK}
  84. OVERALL_STS=$STS_OK
  85.  
  86. #
  87. # cpid
  88. #
  89. # Retrieve the current Control Processor ID
  90. #
  91. cpid() {
  92.     sed -n -e 's/^Control.\+No: \([[:digit:]]\{1,\}\)$/\1/gp'
  93. }
  94.  
  95. #
  96. # swbd
  97. #
  98. # Retrieve the current system platform name, of the form "SWBDn", where n
  99. # is cardinal number, assuming a sin/hinv input stream.
  100. #
  101. swbd() {
  102.     sed -n -e 's/^.\+\(SWBD[[:digit:]]\{1,\}\).\+$/\1/gp'
  103. }
  104.  
  105. # Determine the system platform identifier.
  106. SWBD=`sin | swbd 2> ${NULL}`
  107. CPID=`sin | cpid 2> ${NULL}`
  108.  
  109.  
  110. otherhost(){
  111. #        printf 10.0.0.$((5+$(othercp)))
  112.     case ${SWBD##SWBD} in
  113.     '62')
  114.         printf 127.1.1.$((8 - CPID % 2))
  115.         ;;
  116.     '77')
  117.         printf 127.1.1.$((6 - CPID % 2))
  118.         ;;
  119.     *)
  120.         printf 10.0.0.$((6 - CPID % 2))
  121.         ;;
  122.     esac
  123. }
  124.  
  125. HASHOW="$(/fabos/bin/hashow)"
  126. hashow_cmd=$(ls /fabos/cliexec/hashow)
  127. if [ "$hashow_cmd" != "/fabos/cliexec/hashow" ]; then
  128.            hashow_cmd="/fabos/bin/hashow"
  129. fi
  130.  
  131. othercp(){
  132.         that=${HASHOW#*Remote CP \(Slot}
  133.         that="${that%%,*}"
  134.         printf $(($that - 5))
  135. }
  136.  
  137. add_err_status(){
  138.     echo "$1" >> $STATUS_FILE
  139. }
  140.  
  141. ha_role() {
  142.      case "$($hashow_cmd | ( read a; echo $a ))" in
  143.         *Local*Active*)
  144.         printf "ACTIVE"
  145.          ;;
  146.         *Local*Standby*)
  147.         printf "STANDBY"
  148.          ;;
  149.         *"Not supported"*)
  150.         printf "ACTIVE"
  151.          ;;
  152.         *)
  153.         printf "STANDBY"
  154.         ;;
  155.     esac
  156. }
  157.  
  158. if [ $(ha_role) == "ACTIVE" ]; then
  159.     ACTIVECP=1
  160. fi
  161.  
  162. ha_state() {
  163.     sync=`/fabos/cliexec/hashow | sed -n -e 's/^.\+\(State sync\).\+$/\1/gp'`
  164.  
  165.     if [ "$sync" != "State sync" ]; then
  166.         printf "NOSYNC"
  167.     else
  168.         printf "SYNC"
  169.     fi
  170. }
  171.  
  172. is_fwdl_arg() {
  173.  
  174.     #
  175.     # Reads command line args passed to firmwaredownload
  176.     # and checks if the required argument is specified
  177.     #
  178.     for arg in $(/usr/bin/tr '\0' ' ' < /proc/$PPID/cmdline)
  179.     do
  180.             case $arg in
  181.             (-*$1*)
  182.         return $STS_OK
  183.         ;;
  184.             esac
  185.         done
  186.         return $STS_ERR
  187. }
  188.  
  189. allow_nondisruptive_fwdl() {
  190.     # Skip for restore
  191.     if [ -n "$TYPE" ]; then
  192.         $ECHO " running firmwarerestore"
  193.         return $STS_OK
  194.     fi
  195.  
  196.     # Allow 6.1.2_cee <-> 6.3 HCL on Elara
  197.     # For others, allow only disruptive fwdl
  198.     case ${SWBD##SWBD} in
  199.     '76')
  200.         ;;
  201.     *)
  202.         is_fwdl_arg "s"
  203.         local singlemode=$?
  204.         is_fwdl_arg "f"
  205.         local forcemode=$?
  206.         if [ $singlemode -ne 0 -o $forcemode -ne 0 ]; then
  207.             return $STS_ERR
  208.         fi
  209.         ;;
  210.     esac
  211.  
  212.     return $STS_OK
  213. }
  214.  
  215.  
  216. TEST() {
  217.  
  218.     $ECHO  -n "TEST $1 "
  219.     if [ $(ha_role) == "STANDBY" ] && [ $(ha_state) == "NOSYNC" ]; then
  220.         return $STS_OK
  221.     fi
  222.  
  223.     $1
  224.      if [ $? -ne $STS_OK ]; then
  225.         $ECHO "failed"
  226.         add_err_status "$2"
  227.         RET_CODE=$STS_ERR
  228.         return $STS_ERR
  229.     fi
  230.  
  231.     $ECHO "passed"
  232.     return $STS_OK
  233. }
  234.  
  235. ###################################################
  236. ### The messages are for firmwarerestore.    ###
  237. ###################################################
  238. FWDL_RUNNING_MSG="Firmwaredownload or firmwarecommit is already running. Please wait for it to complete first."
  239. FWRESTORE_DISALLOWED_MSG="No need to run firmwarerestore because firmware has already been committed, or there is no firmwaredownload performed."
  240. FWRESTORE_VER_DISALLOWED_MSG="Firmwarerestore from v6.3.x to v6.1.2_cee is not supported. Please run firmwarecommit first and then download the new firmware."
  241.  
  242. ###################################################
  243. ###################################################
  244. ####                                           ####
  245. ####                                           ####
  246. ####     PRESINSTALL MESSAGES SECTION          ####
  247. ####    ------------------------------         ####
  248. ####                                           ####
  249. ###################################################
  250. ###################################################
  251. IRONMANMSG="The FC4-16IP (type 31) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  252. POSITRONMSG="The FC4-48 (type 36) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  253. SCIMITARMSG="The FA4-18 (type 33) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  254. SABREMSG="This platform is not supported by the target firmware. Please try to download another firmware."
  255. XENONMSG="The FC10-6 (type 39) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  256. TRITONMSG="The FC8-48 (type 51) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  257. LARISSAMSG="The FC8-32 (type 55) is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  258. DESPINAMSG="The FC8-16 (type 37) is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  259. MACEMSG="This platform is not supported by the target firmware. Please try to download another firmware."
  260. LANCEMSG="The FS8-18 (type 43) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  261. EUROPAMSG="The FCOE10-24 (type 74) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  262. STRIKERMSG="The FX8-24 (type 75) blade is not supported by the target firmware. Please use slotshow to find out which slot it is in and remove it first."
  263. ADSPOLICYMSG="ADS policy of Access Gateway is enabled. Please use \"ag --policydisable ads\" to remedy this."
  264. UNSUPPORTED_DL_VERMSG="Cannot downgrade to 6.1 or lower. Please downgrade to 6.2 first and then download the desired firmware version."
  265. UNSUPPORTED_UP_VERMSG="Cannot upgrade directly to 6.3. Please upgrade to 6.2 first and then upgrade to 6.3."
  266. UNSUPPORTED_VF_DISABLE_MSG="Downgrade is not allowed because VF is enabled. Please run \"lscfg --config\" and \"lscfg --delete\" commands to remove the non-default LS first, then run \"fosconfig --disable vf\" to disable VF before proceeding."
  267. UNSUPPORTED_ETHSW_DISABLE_MSG="Downgrade is not allowed because Ethernet Switch Service is enabled. Please run \"fosconfig --disable ethsw\" command to disable it before proceeding."
  268. UNSUPPORTED_AG_ON_SPIRIT_MSG="Downgrade is not allowed because AG is enabled. Please run \"ag --modedisable\" command to disable AG mode before proceeding."
  269. UNSUPPORTED_AG_ON_MACE_MSG="Downgrade is not allowed because AG is enabled. Please run \"ag --modedisable\" command to disable AG mode before proceeding."
  270. UNSUPPORTED_AG_ON_ELARA_MSG="Downgrade is not allowed because AG is enabled. Please run \"ag --modedisable\" command to disable AG mode before proceeding."
  271. AG_QOS_PORT_ACTIVE_MSG="Downgrade is not allowed because one or more ports are in active QoS(AoQ) mode. Please use \"portdisable [slot/]port\" command to disable the ports in active QoS mode."
  272. QOS_DI_ZONE_EXISTANCE_MSG="Downgrade is not allowed because defined and/or active configurations have QoS DI zones in one or more contexts. Please use \"zonedelete zone_name\" command to delete the QoS DI Zones before proceeding."
  273. AGPGMODESMSG="One or more port groups are operating in a special mode (lb, mfnm, etc). Please use \"ag --pgdelmodes\" to remedy this."
  274. PID_CORE_MSG="PID Format needs to be set to Core. Please use \"switchdisable\" to disable the switch then use \"configure\" to change the Switch PID Format."
  275. PERF_MSG="Upgrade is not allowed because both Top talker monitors and FC Router are configured and the new firmware doesn't support co-existence of both the features. Pleae use \"perfttmon --del\" or \"fosconfig --disable fcr\" commands to delete top talkers or disable FC Router feature before upgrading."
  276. METEORPLATFORMMSG="Cannot upgrade to firmware v6.1. This firmware does not support Silkworm 24000 platform."
  277. NON_ENC_PLATFORMMSG="This platform is not supported by the target firmware. Please try to download another firmware."
  278. UNSUPPORTEDPLATFORMMSG="Cannot download the requested firmware because the firmware doesn't support this platform. Please enter another firmware path."
  279. TACONFIGUREDMSG="Downgrade is not allowed because one or more trunk areas have been configured. Please use \"porttrunkarea --disable\" to disable trunk areas before downgrading."
  280. CRRECOVCONFIGUREDMSG="Downgrade is not allowed because one or more ports have credit recovery enabled. Please use \"islshow\" to show ports with credit recovery. Use the command \"portdisable\" to disable credit recovery ports."
  281. LSANMATRIXMSG="Firmware to downgrade does not support the FCR matrix. Please use the fcrlsanmatrix CLI command to put the FCR matrix configuration back to default since this feature will not be supported in the older firmware."
  282. TEMPLICENSEPRESENT="Temporary license is present on the switch. Please remove that before performing firmware downgrade."
  283. AGTRUNKCONFIGUREDMSG="One or more N_Port trunks are enabled. Downgrade is not allowed because one or more trunk areas have been configured on the switch attached to this AG. Please execute \"porttrunkarea --disable\" CLI on the attached switch to remedy this."
  284. DOWNGRADEWITHC2EX="One or more Integrated Routing EX_Ports are enabled. Please use \"portcfgexport\" CLI to disable these ports before continuing."
  285. DOWNGRADEWITH7500EMSG="7500E platform is not supported by the target firmware. Please try to download another firmware version. 7500E requires FOS V6.1.1 or higher."
  286. MAXFCPORTSEXCEEDED_7500EMSG="Exceeded maximum number of FC ports for 7500E configuration. Only FC ports 0 and 1 are allowed to be used for 7500E. Please use \"portcfgpersistentdisable\" to persistently disable all remaining FC ports and try again, or install the 7500E Upgrade License."
  287. MAXTUNNELEXCEEDED_7500EMSG="Exceeded maximum number of tunnels for 7500E configuration. Only 1 FCIP tunnel configuration allowed per GE port. Please use \"portcfg fciptunnel\" or \"portcfgdefault\" to remove any extra tunnel configurations and try again, or install the 7500E Upgrade License."
  288. MAXBANDWIDTHEXCEEDED_7500EMSG="Exceeded maximum bandwidth allocation for 7500E configuration. Minimum bandwidth is 1400 and maximum bandwidth is 50000 (50Mbps). Please use \"portcfg fciptunnel\" or \"portcfgdefault\" to set a commited rate in range for all FCIP tunnels and try again, or install the 7500E Upgrade License."
  289. FCIPTAPEACC_7500EMSG="The 7500E does not support the tape pipelining feature. This is only available via upgrade license. Please use \"portcfg fciptunnel\" or \"portcfgdefault\" to remove the tape pipelining funcionality for all FCIP tunnels and try again, or install the 7500E Upgrade License."
  290. FCIPIPSEC_7500EMSG="The 7500E does not support the IPSec feature. This is only available via upgrade license. Please use \"portcfg fciptunnel\" or \"portcfgdefault\" to remove all IPSec policies from the FCIP tunnels and try again, or install the 7500E Upgrade License."
  291. FCIPFICON_7500EMSG="The 7500E does not support FICON emulation. This is only available via upgrade license. Please use \"portcfg ficon\" or \"portcfgdefault\" to remove any FICON tunnels and try again, or install the 7500E Upgrade License."
  292. DOWNGRADE_WITH_C2_PORT_MIRROR="Downgrade is not allowed because port mirroring is enabled for one or more ports. Please use \"portcfg mirrorport\" and \"portmirror --show in Default and in all Logical switches (if any)\" to disable them before downgrading"
  293. TIFCRCONFIGUREDMSG="Downgrade is not allowed because one or more TI over FCR zones have been configured. Please use \"zone --remove\" or \"zone --delete\" to remove/delete them before downgrading."
  294. IOD_DELAY_CONFIGURED="Downgrade is not allowed because IOD Delay value is configured for one or more domains. Please use \"ioddelayshow and ioddelayreset\" to disable them before downgrading."
  295. RDINTEROP2CONFIGUREDMSG="Downgrade is not allowed because Frame Redirect zones are configured with McDATA Interop Mode enabled. Use \"interopmode\" and/or \"zone --rddelete\" commands."
  296. RDINTEROP3CONFIGUREDMSG="Downgrade is not allowed because Frame Redirect zones are configured with McDATA Open Mode enabled. Use \"interopmode\" and/or use \"zone --rddelete\" commands to remove/delete them before downgrading."
  297. DOMOFFSETINTEROPCONFIGMSG="Downgrade is not allowed because McDATA/OpenMcData Mode is enabled and domain offset is not configured to default McDATA/OpenMcData offset. Use \"interopmode\" command to remove/delete/reconfigure/modify them before downgrading."
  298. MSFRZONEORCFGNAMEFOUNDMSG="Upgrade is not allowed because one of the Zones or configs defined on this switch is using a reserved naming prefix \"msfr_zn\" or \"msfr_cfg\" please rename them before upgrading."
  299. SWITCH_FAULTY_MSG="Firmwaredownload is not allowed since the switchState is Faulty. Use \"switchShow\" to see the switch state. Please recover the switch before proceeding."
  300.  
  301. AG_QOS_PORT_ACTIVE_FABRIC_SIDE_MSG="Downgrade is not allowed because one or more F-ports on the switch are connected to AG (with active QoS). Please use \"portdisable [slot/]port\" command to disable those F-ports."
  302. UNSUPPORTED_PERSISTENT_ALPA_ON_DOWNGRADE="Downgrade is not allowed because persistent alpa in enabled. Please use \"ag --persistentalpaenable 0\" to disable the feature before downgrading."
  303. UNSUPPORTED_SFLOW_ON_DOWNGRADE="Downgrade is not allowed because sflow is enabled in startup/running config. Please use \"show running-config/show-startup-config\" to check sflow config and remove them before downgrading."
  304. UNSUPPORTED_DOT1X_ON_DOWNGRADE="Downgrade is not allowed because dot1x is enabled in startup/running config. Please use \"show running-config/show-startup-config\" to check dot1x config and remove them before downgrading."
  305. UNSUPPORTED_SYSTEMCARD_FEATURE_ON_DOWNGRADE="Downgrade is not allowed because System Card is enabled. Please use \"cryptocfg --set -systemcard disable\" to disable System Card feature before downgrading."
  306. UNSUPPORTED_QOURUMCARD_SIZE_NON_ZERO="Downgrade is not allowed because Qourum size is greater than zero. Please change the qourum size to zero before downgrading."
  307. UNSUPPORTED_TWO_RKM_KVS_UPGRADE="Upgrade is not allowed because Secondary RKM KV is registered. Please use \"cryptocfg --dereg -keyvault <label> \" to deregister the secondary KV and then try again."
  308. UNSUPPORTED_TWO_SKM_KVS_DOWNGRADE="Downgrade is not allowed because Secondary SKM KV is registered. Please use \"cryptocfg --dereg -keyvault <label> \" to deregister the secondary KV and then try again."
  309. AREA_ASSIGNED_BEYND_MAXPHPORTS="Downgrade is not allowed because one or more of the areas assigned is greater than the maximum number of physical ports on the platform. Please user \"portaddress --show\" to display the areas currently assigned and \"--unbind and --bind\" to bind an area below max_phy_ports".
  310. UNSUPPORTED_PASSWDCFG_HISTORY_VALUE="Downgrade is not allowed because passwdcfg.history value of 0 is not supported.  Please set the history value in a range of 1 - 24 before downgrading."
  311. UNSUPPORTED_PORTFENCING_STATECHANGEMSG="Portfencing is enabled for State Change events. Kindly disable before downgrade"
  312. XFCIP_IPSEC_MSG="IPSec on FCIP tunnels for 7800 require version v6.3.1 or higher. Please use \"portcfg fciptunnel\" to disable IPSec for all FCIP tunnels and try again."
  313. XFCIP_VLAN_TAGGING_MSG="VLAN Tagging on FCIP tunnels for 7800/FX8-24 requires version v6.3.1 or higher. Please use \"portcfg fcipcircuit <VE-Port> modify\" to disable VLAN Tagging on all FCIP Circuits."
  314. WEBLINKER_MSG="Both http and Secure http are disabled. Please use \"webdconfigure\" command to enable http."
  315.  
  316. ###################################################
  317. ###################################################
  318.  
  319. ###################################################
  320. ###################################################
  321. ####                                           ####
  322. ####                                           ####
  323. ####       PRESINSTALL CHECK SECTION           ####
  324. ####    ------------------------------         ####
  325. ####                                           ####
  326. ###################################################
  327. ###################################################
  328.  
  329. ficon_check_active()
  330. {
  331.      FICONCHECK=`/fabos/cliexec/configshow | grep -E "FICONTUNNEL" | wc -l`
  332.      if [ $FICONCHECK -eq 0 ]; then
  333.          return $STS_OK
  334.      fi
  335.      return $STS_ERR
  336. }
  337.  
  338. ficon_check_standby()
  339. {
  340.     FICONCHECK=`/usr/bin/rsh -n $(otherhost) ROLE_ID=root LOGIN_ID=root CURRENT_AD=0 /fabos/cliexec/configshow | grep -E "FICONTUNNEL" | wc -l`
  341.  
  342.     if [ $FICONCHECK -eq 0 ]; then
  343.           return $STS_OK
  344.     fi
  345.  
  346.     return $STS_ERR
  347. }
  348.  
  349. ficon_configured()
  350. {
  351.     if [ $ACTIVECP ]; then
  352.     ficon_check_active
  353.     else
  354.     ficon_check_standby
  355.     fi
  356. }
  357.  
  358. #
  359. # chassisopt
  360. #
  361. # Retrieve the current chassisconfig option.
  362. #
  363. chassisopt() {
  364.     sed -n -e 's/^Cur.\+on: \([[:digit:]]\{1,\}\).*$/\1/gp'
  365. }
  366.  
  367. #
  368. # marathon_present
  369. #
  370. # Check whether there are any marathon blades enabled in the system.
  371. #
  372. marathon_present() {
  373.  
  374.     MARATHON=$(/fabos/cliexec/slotshow | grep " 24 " | wc -l)
  375.     return $MARATHON
  376. }
  377.  
  378. #
  379. # ironman_present
  380. #
  381. # Check whether there are any ironman blades enabled in the system.
  382. #
  383. ironman_present() {
  384.  
  385.     IRONMAN=$(/fabos/cliexec/slotshow | grep " 31 " | wc -l)
  386.     return $IRONMAN
  387. }
  388.  
  389. #
  390. # positron_present
  391. #
  392. # Check whether there are any positron blades enabled in the system.
  393. #
  394. positron_present() {
  395.  
  396.     POSITRON=$(/fabos/cliexec/slotshow | grep " 36 " | wc -l)
  397.     return $POSITRON
  398. }
  399.  
  400.  
  401. #
  402. # scimitar_present
  403. #
  404. # Check whether there are any marathon blades enabled in the system.
  405. #
  406. scimitar_present() {
  407.  
  408.     SCIMITAR=$(/fabos/cliexec/slotshow | grep " 33 " | wc -l)
  409.     return $SCIMITAR
  410. }
  411.  
  412. #
  413. # sabre_present
  414. #
  415. # Check whether there are any marathon blades enabled in the system.
  416. #
  417. sabre_present() {
  418.  
  419.     SABRE=$(/fabos/cliexec/slotshow -d576 | grep " 38 " | wc -l)
  420.     return $SABRE
  421. }
  422.  
  423. #
  424. # xenon_present
  425. #
  426. # Check whether there are any marathon blades enabled in the system.
  427. #
  428. xenon_present() {
  429.  
  430.     XENON=$(/fabos/cliexec/slotshow | grep " 39 " | wc -l)
  431.     return $XENON
  432. }
  433.  
  434. #
  435. # triton_present
  436. #
  437. # Check whether there are any zontron blades enabled in the system.
  438. #
  439. triton_present() {
  440.  
  441.     TRITON=$(/fabos/cliexec/slotshow | grep " 51 " | wc -l)
  442.     return $TRITON
  443. }
  444.  
  445. #
  446. # larissa_present
  447. #
  448. # Check whether there are any zontron blades enabled in the system.
  449. #
  450. larissa_present() {
  451.  
  452.     LARISSA=$(/fabos/cliexec/slotshow | grep " 55 " | wc -l)
  453.     return $LARISSA
  454. }
  455.  
  456. #
  457. # despina_present
  458. #
  459. # Check whether there are any zontron blades enabled in the system.
  460. #
  461. despina_present() {
  462.  
  463.     DESPINA=$(/fabos/cliexec/slotshow | grep " 37 " | wc -l)
  464.     return $DESPINA
  465. }
  466.  
  467. #
  468. # lance_present
  469. #
  470. # Check whether there are any lance blades enabled in the system.
  471. #
  472. lance_present() {
  473.  
  474.     LANCE=$(/fabos/cliexec/slotshow | grep " 43 " | wc -l)
  475.     return $LANCE
  476. }
  477.  
  478. #
  479. # mace_present
  480. #
  481. # Check whether there are any mace blades enabled in the system.
  482. #
  483. mace_present() {
  484.  
  485.     MACE=$(/fabos/cliexec/slotshow -d576 | grep " 42 " | wc -l)
  486.     return $MACE
  487. }
  488.  
  489. #
  490. # europa_present
  491. #
  492. # Check whether there are any europa blades enabled in the system.
  493. #
  494. europa_present() {
  495.  
  496.     EUROPA=$(/fabos/cliexec/slotshow -d576 | grep " 74 " | wc -l)
  497.     return $EUROPA
  498. }
  499.  
  500. #
  501. # striker_present
  502. #
  503. # Check whether there are any striker blades enabled in the system.
  504. #
  505. striker_present() {
  506.  
  507.     STRIKER=$(/fabos/cliexec/slotshow -d576 | grep " 75 " | wc -l)
  508.     return $STRIKER
  509. }
  510.  
  511. #
  512. # pluto_chassis
  513. #
  514. # Check whether there are any zontron blades enabled in the system.
  515. #
  516. pluto_chassis() {
  517.  
  518.         case ${SWBD##SWBD} in
  519.         '77')
  520.         return $STS_ERR
  521.         ;;
  522.     *)
  523.             return $STS_OK
  524.         ;;
  525.     esac
  526. }
  527.  
  528.  
  529. #
  530. # Routing policy
  531. #
  532. # Check what routing policy it is.
  533. #
  534. routing_policy() {
  535.     /fabos/sbin/aptpolicy | sed -n -e 's/^ Cur.\+Policy: \([[:digit:]]\{1,\}\).*$/\1/gp'
  536. }
  537.  
  538. #
  539. # portmirror_present
  540. #
  541. # Check whether there are any port mirror connections enabled in the system.
  542. # If there are not portmirror connections, portmirrorshow:
  543. #     switch:root> portmirrorshow
  544. #    There are no port mirror connections configured
  545. #
  546. portmirror_present() {
  547.     CMD='s/^mirror\.portmirrorcnt:\([0-9]*\).*$/\1/p'
  548.     mrr_cnt=`PATH=/bin:/fabos/cliexec:/fabos/bin  configshow | sed -n -e "$CMD"`
  549.     return $mrr_cnt
  550. }
  551.  
  552. # ag_persistent_alpa_enabled
  553. # Check is Persistent ALPA is enabled or not
  554.  
  555. ag_persistent_alpa_enabled() {
  556.         ag_persistent_alpa=`/fabos/bin/ag --printalpamap | grep -c "ag --printalpamap"`
  557.         return $ag_persistent_alpa
  558. }
  559.  
  560. #
  561. # ag_mode_enabled
  562. #
  563. # Check whether the switch is currently in AG mode
  564. #
  565. # JOE
  566. ag_mode_enabled() {
  567.  
  568.     ag_mode=`/fabos/link_bin/switchshow | grep -c "Access Gateway Mode"`
  569.     return $ag_mode
  570.  
  571. }
  572.  
  573.  
  574. #
  575. # ads_policy_enabled
  576. #
  577. # Check whether ADS policy of the AG is enabled
  578. #
  579. ads_policy_enabled() {
  580.     /fabos/bin/ag --policyshow | grep ads | grep Enabled > /dev/null 2>&1
  581.     rc=$?
  582.     if [ $rc -eq 0 ]; then
  583.         return $STS_ERR
  584.     else
  585.         return $STS_OK
  586.     fi
  587. }
  588.  
  589.  
  590. pid_format_two() {
  591.     #
  592.     # Block upgrade if PID format is set to 2
  593.     #
  594.     pid_format=`/fabos/cliexec/configshow | grep pidFormat | cut -f 2 -d ':'`
  595.     if [ $pid_format -eq 2 ]; then
  596.         return $STS_ERR
  597.     fi
  598.     return $STS_OK
  599. }
  600.  
  601. perf_mon_check() {
  602.  
  603.     # Run this check only on C2 and GEYE2 family of platforms.
  604.     case ${SWBD##SWBD} in
  605.         '71'|'62'|'66'|'64'|'77'|'42'|'72'|'73'|'75'|'67')
  606.         #
  607.         # Block upgrade if TT monitor are installed
  608.         #
  609.         /fabos/cliexec/configshow | grep "ttmonc" > /dev/null 2>&1
  610.         rc=$?
  611.         if [ $rc -eq 0 ]; then
  612.             check_fcr_enabled
  613.             if [ $? -ne $STS_OK ]; then
  614.                 return $STS_ERR
  615.             fi
  616.         fi
  617.         ;;
  618.     *)
  619.         return $STS_OK
  620.         ;;
  621.     esac
  622.  
  623.     return $STS_OK
  624. }
  625.  
  626.  
  627. # Check if certificate is installed.
  628. # Presence of non-zero length files under /etc/fabos/certs/sw0 directory
  629. # implies certificate is installed on the switch.
  630.  
  631. check_nz_cert() {
  632.    shopt -s nullglob
  633.    for i in /etc/fabos/certs/sw0/*
  634.    do
  635.       [ ! -z "$i" ] && return 0
  636.    done
  637.       return 1
  638. }
  639.  
  640. check_http_enabled() {
  641.     F=/etc/fabos/fabos.0.conf
  642.  
  643.     #
  644.     # If http.enabled is set to 1, return OK.
  645.     #
  646.     grep -q '^http\.enabled:1' $F  && return $STS_OK
  647.  
  648.     #
  649.     # if certs are  not installed (chck_nz_cert == 1)
  650.     # return error.
  651.     #
  652.     check_nz_cert || return $STS_ERR
  653.  
  654.     #
  655.     # if certs are  installed but http.ssl.enabled is set to 0
  656.     # return error.
  657.     #
  658.     grep -q '^http\.ssl\.enabled:0' $F && return $STS_ERR
  659.     return $STS_OK
  660. }
  661.  
  662.  
  663. correcthost() {
  664.     if [ $ACTIVECP ] ; then
  665.     "$@"
  666.     else
  667.     /usr/bin/rsh -n $(otherhost) ROLE_ID=root LOGIN_ID=root CURRENT_AD=0 "$@"
  668.     fi
  669. }
  670.  
  671. check_trunkarea_configured() {
  672.  
  673.     case $(correcthost /fabos/sbin/porttrunkarea --show enabled 2>&1) in
  674.     ("No ports have Trunk Area enabled") return $STS_OK;;
  675.     ("Error: This command is not supported in AG mode") return $STS_OK;;
  676.     (*"No such file or directory") return $STS_OK;;
  677.     (*) return $STS_ERR;;
  678.     esac
  679. }
  680.  
  681. #
  682. # check if any TI over FCR zones are configured.
  683. # i.e. look for a -1 or WWN in zone --show output.
  684. # define local variable dd == 2 hex digits for ease of readability
  685. # of the case pattern
  686. #
  687. check_ti_over_fcr_zone_configured() {
  688.     local dd='[0-9a-fA-F][0-9a-fA-F]'
  689.     local v=$(correcthost /fabos/cliexec/zone --show 2>/${NULL})
  690.     case "$v" in
  691.     (*$dd:$dd:$dd:$dd:$dd:$dd:$dd:$dd*) return $STS_ERR;;
  692.     (*-1*) return $STS_ERR;;
  693.     (*) return $STS_OK;;
  694.     esac
  695. }
  696.  
  697. #
  698. # check for Frame Redirect zones configured
  699. # along with Interopmode 2.
  700. #
  701. check_for_rd_zones_with_mode_2_configured() {
  702.  
  703.     # first check interop
  704.  
  705.     if correcthost /fabos/cliexec/configshow | grep -q switch.interopMode.*0 &&
  706.        correcthost /fabos/cliexec/configshow | grep -q switch.mcdtFabricMode.*1; then
  707.         $ECHO mode 2
  708.     else
  709.         return $STS_OK
  710.     fi
  711.  
  712.     # check for frame redirect zones
  713.  
  714.     if correcthost /fabos/cliexec/cfgshow | grep -q zone.*red_0917; then
  715.         return $STS_ERR
  716.     fi
  717.  
  718.         if correcthost /fabos/cliexec/cfgshow | grep -q zone.*red_1109; then
  719.         return $STS_ERR
  720.     fi
  721.  
  722.  
  723.     if correcthost /fabos/cliexec/cfgshow | grep -q zone.*red_______base; then
  724.         return $STS_ERR
  725.     fi
  726.  
  727.         return $STS_OK
  728. }
  729.  
  730. #
  731. # check for Frame Redirect zones configured
  732. # along with Interopmode 3.
  733. #
  734. check_for_rd_zones_with_mode_3_configured() {
  735.  
  736.     # first check interop
  737.  
  738.     if correcthost /fabos/cliexec/configshow | grep -q switch.interopMode.*1 &&
  739.        correcthost /fabos/cliexec/configshow | grep -q switch.mcdtFabricMode.*1; then
  740.         $ECHO mode 2
  741.     else
  742.         return $STS_OK
  743.     fi
  744.  
  745.     # check for frame redirect zones
  746.  
  747.     if correcthost /fabos/cliexec/cfgshow | grep -q zone.*red_0917; then
  748.         return $STS_ERR
  749.     fi
  750.  
  751.         if correcthost /fabos/cliexec/cfgshow | grep -q zone.*red_1109; then
  752.         return $STS_ERR
  753.     fi
  754.  
  755.  
  756.     if correcthost /fabos/cliexec/cfgshow | grep -q zone.*red_______base; then
  757.         return $STS_ERR
  758.     fi
  759.  
  760.         return $STS_OK
  761. }
  762. #
  763. # if upgrading to 6.3 make sure that
  764. # no zones or configs are named with the msfr prefix
  765. #
  766. check_for_msfr_zone_names() {
  767.  
  768.  
  769.  
  770.     # check for msfr zone and config names
  771.     # return good if both the zone name and config name are found
  772.     # this is to protect agenst a Downgrade upgrade action where msfr zones
  773.     # could be valid.  This will only throw an error if the zone name or the
  774.     # config name match the msfr header but not both.
  775.  
  776.     if correcthost /fabos/cliexec/cfgshow | grep -q msfr_zn_; then
  777.         if correcthost /fabos/cliexec/cfgshow | grep -q msfr_cfg_; then
  778.             return $STS_OK
  779.         else
  780.             return $STS_ERR
  781.         fi
  782.     fi
  783.     if correcthost /fabos/cliexec/cfgshow | grep -q msfr_cfg_; then
  784.             return $STS_ERR
  785.     fi
  786.  
  787.         return $STS_OK
  788. }
  789.  
  790. #
  791. # check_did_offset_with_im_enabled
  792. # This checks whether the domain ID offset is configured with default offset mode
  793. # or not with Interopmode enabled(McData mode and Open Mcdata mode)
  794. #
  795. check_did_offset_with_im_enabled() {
  796.  
  797.     # first check interop
  798.  
  799.     if correcthost /fabos/cliexec/configshow | grep -q switch.interopMode.*0 &&
  800.        correcthost /fabos/cliexec/configshow | grep -q switch.mcdtFabricMode.*1; then
  801.         $ECHO mode 2
  802.     elif correcthost /fabos/cliexec/configshow | grep -q switch.interopMode.*1 &&
  803.          correcthost /fabos/cliexec/configshow | grep -q switch.mcdtFabricMode.*1; then
  804.         $ECHO mode 3
  805.     else
  806.         return $STS_OK
  807.     fi
  808.  
  809.     # Check the domain ID offset
  810.  
  811.     if correcthost /fabos/cliexec/configshow | grep -q switch.domain_id_offset.*96; then
  812.         return $STS_OK
  813.     fi
  814.  
  815.     return $STS_ERR
  816.  
  817. }
  818.  
  819. check_default_did_offset_in_im() {
  820.     check_vf_enabled
  821.     if [ $? -ne $STS_OK ]; then
  822.         for_all_contexts check_did_offset_with_im_enabled
  823.     else
  824.         check_did_offset_with_im_enabled
  825.     fi
  826. }
  827.  
  828. #
  829. #   Check if portfencing bit is set for State Change 
  830. #   for all instance of switches. 
  831. #
  832. check_pf_statechange_set() {
  833.  
  834.     PORTPFBIT=`/fabos/cliexec/configshow  | grep thresh | grep port.State | grep -E  '[^0-9][3-6][0-9]'| grep -v -E '[^0-9]3[0-1]' | wc -l`
  835.  
  836.     if [ $PORTPFBIT -gt 0 ]; then
  837.        return $STS_ERR
  838.     else
  839.        return $STS_OK
  840.     fi
  841. }
  842.  
  843. check_pf_statechange_set_allinstances() {
  844.  
  845.     check_vf_enabled
  846.  
  847.     if [ $? -ne $STS_OK ]; then
  848.        for_all_contexts check_pf_statechange_set
  849.     else
  850.        check_pf_statechange_set
  851.     fi
  852. }
  853.  
  854.  
  855. #
  856. #
  857. # credit_recovery_check_active
  858. # This checks the active CP for any credit recovery active ports.
  859. #
  860. credit_recovery_check_active() {
  861.     string=`/fabos/cliexec/islshow | grep -c "CR_RECOV"`
  862.     return $string
  863. }
  864.  
  865. #
  866. # credit_recovery_check_standby
  867. # This is run for stand by CP. Run rsh to check from active CP for credit recovery ports.
  868. #
  869. credit_recovery_check_standby() {
  870.     string=`/usr/bin/rsh -n $(otherhost) ROLE_ID=root LOGIN_ID=root CURRENT_AD=0 /fabos/cliexec/islshow | grep -c "CR_RECOV"`
  871.     return $string
  872. }
  873.  
  874. #
  875. # credit_recovery_enabled
  876. #
  877. # Check if credit recovery is enabled on any local ports. If it is
  878. # configured we fail the firmware downgrade cases.
  879. #
  880. credit_recovery_enabled() {
  881.  
  882.     if [ $ACTIVECP ]; then
  883.     credit_recovery_check_active
  884.     else
  885.     credit_recovery_check_standby
  886.     fi
  887. }
  888.  
  889. #
  890. # check_ag_trunk_configured
  891. #
  892. # Check whether any of N_Port trunks are enabled or not
  893. #
  894. check_ag_trunk_configured() {
  895.     if [ -f "/etc/fabos/ag_platform.0" ]; then
  896.         /fabos/bin/switchshow | grep -c Trunk > /dev/null 2>&1
  897.         rc=$?
  898.         if [ $rc -eq 0 ]; then
  899.             return $STS_ERR
  900.         else
  901.             return $STS_OK
  902.         fi
  903.     else
  904.         return $STS_OK
  905.     fi
  906. }
  907.  
  908. #
  909. # 7500e
  910. # Check if 7500e is present
  911. #
  912. is7500e_present()
  913. {
  914.     IS7500ECHECK=`/fabos/link_bin/chassisshow | grep -c "7500E"`
  915.  
  916.     return $IS7500ECHECK
  917. }
  918.  
  919. #
  920. # 7500e
  921. # Check if active FC ports exceeded
  922. #
  923. maxfcports_exceeded()
  924. {
  925.     # for ports 2 through 15
  926.     for i in `seq 2 15`; do
  927.         # look at the 4th nibble in flags
  928.         FCPORTCHECK=`/fabos/cliexec/configshow | grep portCfg: | grep -v lsportCfg | cut -d : -f 2 | cut -d \; -f $(($i + 1)) | cut -d , -f 2 | tail -c 5 | cut -c 1`
  929.         FCLSPORTCHECK=`/fabos/cliexec/configshow | grep lsportCfg: | cut -d : -f 2 | cut -d \; -f $(($i + 1)) | cut -d , -f 2 | tail -c 5 | cut -c 1`
  930.         # if 8 or higher (check in asci mode to allow for hex values)
  931.         if [ ! "$FCPORTCHECK" \> "7" ]; then
  932.             if [ ! "$FCLSPORTCHECK" \> "7" ]; then
  933.                 return $STS_ERR
  934.             fi
  935.         fi
  936.     done
  937.     return $STS_OK
  938. }
  939.  
  940. #
  941. # 7500e
  942. # Check if number of FCIP tunnels exceeded
  943. #
  944. maxtunnels_exceeded()
  945. {
  946.     NUMBERTUNNELS0=`/fabos/cliexec/configshow | grep -c "P0.FCIPTUNNEL"`
  947.     NUMBERTUNNELS1=`/fabos/cliexec/configshow | grep -c "P1.FCIPTUNNEL"`
  948.  
  949.     if [ $NUMBERTUNNELS0 -le 1 ] && [ $NUMBERTUNNELS1 -le 1 ]; then
  950.         return $STS_OK
  951.     fi
  952.     return $STS_ERR
  953. }
  954.  
  955. #
  956. # 7500e
  957. # Check if bandwidth exceeded on any FCIP tunnels
  958. #
  959. bandwidth_exceeded()
  960. {
  961.     NUMBERTUNNELS0=`/fabos/cliexec/configshow | grep -c "P0.FCIPTUNNEL"`
  962.     NUMBERTUNNELS1=`/fabos/cliexec/configshow | grep -c "P1.FCIPTUNNEL"`
  963.     BANDWIDTHCHECK0=`/fabos/cliexec/configshow | grep "P0.FCIPTUNNEL" | sed -n -e 's/.*CommRt=//' -e '1 s/,.*//p'`
  964.     BANDWIDTHCHECK1=`/fabos/cliexec/configshow | grep "P1.FCIPTUNNEL" | sed -n -e 's/.*CommRt=//' -e '1 s/,.*//p'`
  965.  
  966.     # Check the first tunnel for port 0. If more than one tunnel the
  967.     # maxtunnels_exceeded() will fail
  968.     if [ $NUMBERTUNNELS0 -gt 0 ]; then
  969.         if [ $BANDWIDTHCHECK0 -ge 1400 ] && [ $BANDWIDTHCHECK0 -le 50000 ]; then
  970.             RET0=$STS_OK
  971.         else
  972.             RET0=$STS_ERR
  973.         fi
  974.     else
  975.         RET0=$STS_OK
  976.     fi
  977.  
  978.     # Check the first tunnel for port 1. If more than one tunnel the
  979.     # maxtunnels_exceeded() will fail
  980.     if [ $NUMBERTUNNELS1 -gt 0 ]; then
  981.         if [ $BANDWIDTHCHECK1 -ge 1400 ] && [ $BANDWIDTHCHECK1 -le 50000 ]; then
  982.             RET1=$STS_OK
  983.         else
  984.             RET1=$STS_ERR
  985.         fi
  986.     else
  987.         RET1=$STS_OK
  988.     fi
  989.  
  990.     if [ $RET0 -eq $STS_OK ] && [ $RET1 -eq $STS_OK ]; then
  991.         return $STS_OK
  992.     fi
  993.     return $STS_ERR
  994. }
  995.  
  996. #
  997. # 7500e
  998. # Check if TapePipelining enabled
  999. #
  1000. tapepipe_configured()
  1001. {
  1002.     TAPEPIPECHECK=`/fabos/cliexec/configshow | grep -c "TapeAcc=1"`
  1003.  
  1004.     if [ $TAPEPIPECHECK -eq 0 ]; then
  1005.         return $STS_OK
  1006.     fi
  1007.     return $STS_ERR
  1008. }
  1009.  
  1010. #
  1011. # 7500e
  1012. # Check if IPSec enabled
  1013. #
  1014. ipsec_configured()
  1015. {
  1016.     IPSECCHECK=`/fabos/cliexec/configshow | grep -c "IPSEC=[^0]"`
  1017.  
  1018.     if [ $IPSECCHECK -eq 0 ]; then
  1019.         return $STS_OK
  1020.     fi
  1021.     return $STS_ERR
  1022. }
  1023.  
  1024. #
  1025. # 7500e
  1026. # Check if configured for a 7500e and if so, validate the configuration
  1027. # of the FCIP tunnels.
  1028. #
  1029. check_7500e_configuration()
  1030. {
  1031.     $ECHO check_7500e_configuration
  1032.  
  1033.     # 7500 must be active cp. If not, then chassis can't be a 7500e
  1034.     is7500e_present
  1035.     if [ $? -eq 1 ]; then
  1036.         ISUPGRADELICENSECHECK=`/fabos/cliexec/licenseshow | grep -c "7500E Upgrade license"`
  1037.         if [ $ISUPGRADELICENSECHECK -eq 0 ]; then
  1038.             TEST maxfcports_exceeded "$MAXFCPORTSEXCEEDED_7500EMSG"
  1039.  
  1040.             TEST maxtunnels_exceeded "$MAXTUNNELEXCEEDED_7500EMSG"
  1041.  
  1042.             TEST bandwidth_exceeded "$MAXBANDWIDTHEXCEEDED_7500EMSG"
  1043.  
  1044.             TEST tapepipe_configured "$FCIPTAPEACC_7500EMSG"
  1045.  
  1046.             TEST ipsec_configured "$FCIPIPSEC_7500EMSG"
  1047.  
  1048.             TEST ficon_configured "$FCIPFICON_7500EMSG"
  1049.         fi
  1050.     else
  1051.         return $STS_OK
  1052.     fi
  1053.     return $RET_CODE
  1054. }
  1055.  
  1056. #
  1057. # 7800/FX8-24
  1058. # Check if IPSec is configured on any xfcip tunnels
  1059. #
  1060. check_xfcip_ipsec_configured()
  1061. {
  1062.     if correcthost /fabos/cliexec/configshow | grep -q "XFCIPTUNNEL.*IPSec=[^0]"; then
  1063.         return $STS_ERR
  1064.     fi
  1065.     return $STS_OK
  1066. }
  1067.  
  1068. #
  1069. # 7800/FX8-24
  1070. # Check if VLAN Tagging is configured on any xfcip circuits
  1071. #
  1072. check_xfcip_vlan_tagging_configured()
  1073. {
  1074.     if correcthost /fabos/cliexec/configshow | grep -q "XFCIPCIRCUIT.*VlanId=[^0]"; then
  1075.         return $STS_ERR
  1076.     fi
  1077.     return $STS_OK
  1078. }
  1079.  
  1080. CHASSISCMD=""
  1081. cliidx=0
  1082.  
  1083. context_switch()
  1084. {
  1085.     if [ "$1" != "chassis" ]
  1086.     then
  1087.         eval $(/fabos/cliexec/lscfg_util --switch $1)
  1088.     else
  1089.         eval $(/fabos/cliexec/lscfg_util --chassis)
  1090.     fi
  1091.     export ROLE_ID=root
  1092. }
  1093.  
  1094. cmd_chassis() {
  1095.  
  1096.   context_switch chassis
  1097.  
  1098.   if [ "$CONFIG" = "TRUE" ]; then
  1099.     echo -n . > $TTY
  1100.     cliidx=`/usr/bin/expr $cliidx + 1`
  1101.     echo "$cliidx $1 $2 $3 $4 $5 $6 $7 $8 $9" >> $cshow
  1102.     echo -e "$1 $2 $3 $4 $5 $6 $7 $8 $9:"
  1103.       echo "** $1 $2 $3 $4 $5 $6 $7 $8 $9: Command:$rc **" >> $cshow
  1104.   else
  1105.     echo -e "$1 $2 $3 $4 $5 $6 $7 $8 $9:"
  1106.     $1 $2 $3 $4 $5 $6 $7 $8 $9
  1107.   fi
  1108. }
  1109.  
  1110. #
  1111. # On the active CP, check for the presence of Mirror port in
  1112. # Switchshow and also check the config database for mirrorresource
  1113. # Count. Block the downgrade even if one of them is active.
  1114. #
  1115. check_c2_mirror_on_active() {
  1116.  
  1117.     CHASSISCMD="cmd_chassis"
  1118.     COUNTER=1
  1119.     FID=0
  1120.     mirror_port=0
  1121.  
  1122. #    NON-VF CASE
  1123.  
  1124.     num_status=0
  1125.  
  1126.     /fabos/bin/fosconfig --show | grep "Virtual Fabric" | grep enabled > /dev/null 2>&1
  1127.     if [ $? -ne 0 ]; then
  1128.         num_mirror_cnt_configshow=`/fabos/cliexec/configshow  | grep -i portmirrorcnt | grep "1\|2\|3\|4" | cut -d ":" -f2 | wc -l`
  1129.          num_mirror_conn=`/fabos/bin/switchshow | grep -i "Mirror Port" | wc -l`
  1130.         num_status=`/usr/bin/expr $num_mirror_cnt_configshow + $num_mirror_conn`
  1131.  
  1132.         if [ "$num_status" -eq  0 ] ; then
  1133.             return $STS_OK
  1134.         else
  1135.             return $STS_ERR
  1136.         fi
  1137.     fi
  1138.  
  1139. #    VF CASE
  1140.     mirror_cnt=`$CHASSISCMD /fabos/cliexec/configshow -all | grep -i "portmirrorcnt" | grep "1\|2\|3\|4" | cut -d ":" -f2 | wc -l`
  1141.  
  1142.     if [ $mirror_cnt -ne 0 ]; then
  1143.         return $STS_ERR
  1144.     fi
  1145.  
  1146.     # This should use "for_all_contexts" in the future
  1147.     COUNT=`$CHASSISCMD /fabos/cliexec/configshow -all | grep -i "Fabric ID" | cut -d "=" -f2 | wc -l`
  1148.  
  1149.     while [ "$COUNTER" -le "$COUNT" ]
  1150.     do
  1151.         FID=`$CHASSISCMD /fabos/cliexec/configshow -all | grep -i "Fabric ID" | cut -d "=" -f2  | head -$COUNTER | tail -1`
  1152.         COUNTER=`/usr/bin/expr $COUNTER + 1`
  1153.         context_switch $FID
  1154.           mirror_port=`/fabos/bin/switchshow | grep -i "Mirror Port" | wc -l`
  1155.         if [ "$mirror_port" -ne 0 ]; then
  1156.             return $STS_ERR
  1157.         fi
  1158.     done
  1159.     return $STS_OK
  1160.  
  1161. }
  1162.  
  1163. # Helper function. It sets the global variable CONTEXTS to be a list of fabric IDs.
  1164. # Typical usage is seen in the function for_all_contexts, where we use CONTEXTS if it
  1165. # is defined, and otherwise call this function. This means we only need to do
  1166. # the configshow once for each run of preinst, rather than once for each test
  1167. # that wants to run in all contexts
  1168. get_all_contexts(){
  1169.     CONTEXTS=$($CHASSISCMD /fabos/cliexec/configshow -all | sed -n 's/Fabric ID =//p')
  1170.     echo $CONTEXTS
  1171. }
  1172.  
  1173. # Helper function. Loop over the valid fabric IDs running the test that is passed as
  1174. # a parameter. As soon as one test fails then return $STS_ERR. If all pass then
  1175. # return $STS_OK.
  1176. # WARNING. This command will change to a random context (The first one that fails
  1177. # the test or the last context if all pass). Random terms in case someone is searching
  1178. # this file, VF Virtual Fabric AD setcontext FID context and wants to find this warning
  1179. for_all_contexts(){
  1180.     for FID in ${CONTEXTS:-$(get_all_contexts)} ; do
  1181.         context_switch $FID
  1182.         if "$@"
  1183.         then    $ECHO -n "$FID-passed "
  1184.         else    $ECHO -n "$FID-failed "
  1185.                 return $STS_ERR
  1186.         fi
  1187.     done
  1188.     return $STS_OK
  1189. }
  1190.  
  1191.  
  1192. #
  1193. # Check if port mirroring feature is being used currently in
  1194. # Neptune, Thor, Spirit and THawk. If so, downgrade has to be
  1195. # blocked.
  1196. #
  1197. check_c2_mirror_connection() {
  1198.  
  1199.     # Run this check only on C2 family of platforms.
  1200.     case ${SWBD##SWBD} in
  1201.         '71' | '62' | '66' | '64' | '77' | '92')
  1202.         if [ $ACTIVECP ]; then
  1203.             check_c2_mirror_on_active
  1204. #        else
  1205.     #On a Standby ASIC is not attached. Reading the proc switch/*/info makes call to the ASIC driver.
  1206.     #As the ASIC object is not attached on the Standby, the ioctl fails and ASIC logs message C2-5824 to Raslog.
  1207.     #This continuous streaming of message eventually triggers FFDC.
  1208.     #Avoiding reading this proc on Standby and working on way to get the mirror information.
  1209. #            check_c2_mirror_on_standby
  1210.         fi
  1211.         ;;
  1212.     *)
  1213.         return $STS_OK
  1214.         ;;
  1215.     esac
  1216. }
  1217.  
  1218. #
  1219. # Check if Switch is a Spirit and currenly in AG mode.
  1220. # If so, downgrade has to be blocked, because AG mode
  1221. # on a Spirit is not supported before 6.2.
  1222. # And the same would apply to Gladius.
  1223. #
  1224. # JOE
  1225. check_ag_mode_enabled() {
  1226.  
  1227.     case ${SWBD##SWBD} in
  1228.         '66' | '92')
  1229.         ag_mode_enabled
  1230.         ;;
  1231.     *)
  1232.         return $STS_OK
  1233.         ;;
  1234.     esac
  1235. }
  1236.  
  1237. #
  1238. # Check if Switch is a Mace and currenly in AG mode.
  1239. # If so, downgrade has to be blocked, because AG mode
  1240. # on a Mace is not supported before 6.3.
  1241. #
  1242. check_mace_ag_mode_enabled() {
  1243.  
  1244.     case ${SWBD##SWBD} in
  1245.         '67')
  1246.         ag_mode_enabled
  1247.         ;;
  1248.     *)
  1249.         return $STS_OK
  1250.         ;;
  1251.     esac
  1252. }
  1253.  
  1254. #
  1255. # Check if Switch is an Elara and currenly in AG mode.
  1256. # If so, downgrade has to be blocked, because AG mode
  1257. # on a Elara is not supported before 6.3.
  1258. #
  1259. check_elara_ag_mode_enabled() {
  1260.  
  1261.     case ${SWBD##SWBD} in
  1262.         '76')
  1263.         ag_mode_enabled
  1264.         ;;
  1265.     *)
  1266.         return $STS_OK
  1267.         ;;
  1268.     esac
  1269. }
  1270.  
  1271. #
  1272. # check_ag_qos_port_active
  1273. #
  1274. # Check whether any port is active on QoS
  1275. #
  1276. check_ag_qos_port_active() {
  1277.     if [ -f "/etc/fabos/ag_platform.0" ]; then
  1278.         /fabos/bin/switchshow | grep -c AoQ > /dev/null 2>&1
  1279.         rc=$?
  1280.         if [ $rc -eq 0 ]; then
  1281.             return $STS_ERR
  1282.         else
  1283.             return $STS_OK
  1284.         fi
  1285.     else
  1286.         return $STS_OK
  1287.     fi
  1288. }
  1289.  
  1290. #
  1291. # vf_enabled
  1292. #
  1293. # Check whether VF is enabled
  1294. #
  1295. check_vf_enabled() {
  1296.     /fabos/bin/fosconfig --show | grep "Virtual Fabric" | grep enabled > /dev/null 2>&1
  1297.     if [ $? -eq 0 ]; then
  1298.         return $STS_ERR
  1299.     else
  1300.         return $STS_OK
  1301.     fi
  1302.  
  1303. }
  1304.  
  1305. #
  1306. # check_qos_di_zones_presence{,_internal}
  1307. #
  1308. # Check whether QoS zone(s) are either in
  1309. # defined or active configuration.
  1310. #
  1311. check_qos_di_zones_presence_internal() {
  1312.  
  1313.     qos_di_exists=`/fabos/libexec/chkSpecialZoneTypeExists qosdi | grep "exists" | wc -l`
  1314.  
  1315.     if [ $qos_di_exists -ne 0 ]; then
  1316.         return $STS_ERR
  1317.     else
  1318.         return $STS_OK
  1319.     fi
  1320. }
  1321.  
  1322. check_qos_di_zones_presence(){
  1323.     check_vf_enabled
  1324.     if [ $? -ne $STS_OK ]; then
  1325.         for_all_contexts check_qos_di_zones_presence_internal
  1326.     else
  1327.         check_qos_di_zones_presence_internal
  1328.     fi
  1329. }
  1330.  
  1331. #
  1332. # Check from fabric side if the F port to
  1333. # which AG is connected is active on QoS .
  1334. # If so, then block downgrade
  1335. #
  1336. check_ag_qos_port_active_fabric_side() {
  1337.     hashow_cmd=$(ls /fabos/cliexec/hashow)
  1338.     if [ "$hashow_cmd" != "/fabos/cliexec/hashow" ]; then
  1339.     hashow_cmd="/fabos/bin/hashow"
  1340.     fi
  1341.  
  1342.     case "$($hashow_cmd | ( read a; echo $a ))" in
  1343.         *Local*Active*)
  1344.         grep -q -s AOQ_AG /proc/fabos/switch/*/pflags_info && return $STS_ERR
  1345.         ;;
  1346.         *"Not supported"*)
  1347.         grep -q -s AOQ_AG /proc/fabos/switch/*/pflags_info && return $STS_ERR
  1348.         ;;
  1349.         *)
  1350.         ;;
  1351.     esac
  1352.     return $STS_OK
  1353. }
  1354.  
  1355. #
  1356. # Perform area range check only for Thor/Tomahawk/Spirit/Gladius
  1357. # and block fwdl upon failure.
  1358. #
  1359. check_area_range() {
  1360.     case ${SWBD##SWBD} in
  1361.         '71'|'66'|'64'|'92')
  1362.         /fabos/sbin/switchAreaRangeChk 2> /dev/null
  1363.         if [ $? -eq 0 ]; then
  1364.             return $STS_OK
  1365.         else
  1366.             return $STS_ERR
  1367.         fi
  1368.         ;;
  1369.         *)
  1370.         return $STS_OK
  1371.         ;;
  1372.     esac
  1373.     return $STS_OK
  1374. }
  1375.  
  1376. #
  1377. # Check for the config datadatabase only. Switchshow is not available
  1378. # on the standby CP.
  1379. #
  1380. check_c2_mirror_on_standby() {
  1381.  
  1382.     file_flag=0
  1383.     /bin/ln -s /fabos/cliexec/lscfg_util /fabos/link_sbin/lscfg_test 2> /dev/null
  1384.     file_flag=$?
  1385.  
  1386.     export PATH=/fabos/link_bin:/bin:/usr/bin:/sbin:/usr/sbin:/fabos/link_abin:/fabos/link_sbin:/fabos/factory:/fabos/xtool
  1387.  
  1388.     MAX_LGC=`lscfg_test --max`
  1389.       a_switch=0
  1390.       CHASSISCMD="cmd_chassis"
  1391.  
  1392.     while [ "$a_switch" -le "$MAX_LGC" ]
  1393.     do
  1394.         /bin/ls /proc/fabos/switch/$a_switch  > /dev/null 2>&1
  1395.             if [ $? -eq 0 ]; then
  1396.                 /bin/cat /proc/fabos/switch/$a_switch/info  2> /dev/null | grep -i "Mirror Port"  > /dev/null 2>&1
  1397.                 if [ $? -eq 0 ]; then
  1398.                     if [ $file_flag -eq 0 ];then
  1399.                         /bin/rm /fabos/link_sbin/lscfg_test
  1400.                     fi
  1401.                     return $STS_ERR
  1402.                 fi
  1403.             fi
  1404.         a_switch=`/usr/bin/expr $a_switch + 1`
  1405.     done
  1406.  
  1407.     mirror_cnt=`$CHASSISCMD /fabos/cliexec/configshow -all | grep -i "portmirrorcnt" | grep "1\|2\|3\|4" | cut -d ":" -f2 | wc -l`
  1408.         if [ $mirror_cnt -ne 0 ]; then
  1409.             if [ $file_flag -eq 0 ];then
  1410.                 /bin/rm /fabos/link_sbin/lscfg_test
  1411.             fi
  1412.             return $STS_ERR
  1413.         fi
  1414.  
  1415.     if [ $file_flag -eq 0 ];then
  1416.         /bin/rm /fabos/link_sbin/lscfg_test
  1417.     fi
  1418.     return $STS_OK
  1419. }
  1420.  
  1421. check_if_ioddelay_set_in_activecp ()
  1422. {
  1423.     delay_val=`/fabos/cliexec/configshow | grep -i "route.iodDelay" | cut -d ":" -f2`
  1424.     #
  1425.     # Check if any of the configured value is GT 0. This is because
  1426.     # -1 is default value.
  1427.     #
  1428.     for i in $delay_val; do
  1429.         if [ $i -gt 0 ]; then
  1430.             # Iod delay is configured. Fail the downgrade process.
  1431.             return $STS_ERR
  1432.         fi
  1433.     done
  1434.     return $STS_OK
  1435. }
  1436.  
  1437. check_if_ioddelay_set_in_standby ()
  1438. {
  1439.     delay_val=`/usr/bin/rsh -n $(otherhost) ROLE_ID=root LOGIN_ID=root CURRENT_AD=0 /fabos/cliexec/configshow | grep -i "route.iodDelay" | cut -d ":" -f2`
  1440.  
  1441.     for i in $delay_val; do
  1442.         if [ $i -gt 0 ]; then
  1443.             # Iod delay is configured on standby. Fail downgrade process
  1444.             return $STS_ERR
  1445.         fi
  1446.     done
  1447.     return $STS_OK
  1448. }
  1449.  
  1450. check_for_ioddelay_set()
  1451. {
  1452.     if [ $ACTIVECP ]; then
  1453.         check_if_ioddelay_set_in_activecp
  1454.     else
  1455.         check_if_ioddelay_set_in_standby
  1456.     fi
  1457. }
  1458.  
  1459. check_61_enc_hw_features()
  1460. {
  1461.     $ECHO check_61_enc_hw_features
  1462.  
  1463.     TEST lance_present "$LANCEMSG"
  1464.  
  1465.     TEST mace_present "$MACEMSG"
  1466.  
  1467.     return $RET_CODE
  1468. }
  1469.  
  1470. #
  1471. # This routine checks whether any of the 6.2 hardware
  1472. # is active, e.g. whether a 6.2 blade/switch is enabled
  1473. # or present.
  1474. #
  1475. check_62_hw_features()
  1476. {
  1477.     $ECHO check_62_hw_features
  1478.  
  1479.     TEST pluto_chassis "$UNSUPPORTEDPLATFORMMSG"
  1480.  
  1481.     return $RET_CODE
  1482. }
  1483.  
  1484. #
  1485. # This routine checks whether any of the 6.3 hardware
  1486. # is active, e.g. whether a 6.3 blade/switch is enabled
  1487. # or present.
  1488. #
  1489. check_63_hw_features()
  1490. {
  1491.     $ECHO check_63_hw_features
  1492.  
  1493.     TEST europa_present "$EUROPAMSG"
  1494.  
  1495.     TEST striker_present "$STRIKERMSG"
  1496.  
  1497.     return $RET_CODE
  1498. }
  1499.  
  1500. #
  1501. # is_temp_license_present
  1502. #
  1503. # Check whether the temporary license is present on
  1504. # the switch or not
  1505. #
  1506. # 6.1->6.0 no
  1507. # 6.1->5.3 no
  1508. # 5.3->6.1 yes
  1509. # 6.0->6.1 yes
  1510. #
  1511. is_temp_license_present()
  1512. {
  1513.      hashow_cmd=$(ls /fabos/cliexec/hashow)
  1514.      if [ "$hashow_cmd" != "/fabos/cliexec/hashow" ]; then
  1515.          hashow_cmd="/fabos/bin/hashow"
  1516.      fi
  1517.  
  1518.      case "$($hashow_cmd | ( read a; echo $a ))" in
  1519.             *Local*Active*)
  1520.             temp_license_check_active
  1521.              ;;
  1522.             *Local*Standby*)
  1523.             temp_license_check_standby
  1524.              ;;
  1525.             *"Not supported"*)
  1526.             temp_license_check_active
  1527.              ;;
  1528.             *)
  1529.             ;;
  1530.     esac
  1531.  
  1532.     lic_status=$?
  1533.  
  1534.     return $lic_status
  1535. }
  1536.  
  1537. #
  1538. # temp_license_check_active
  1539. #
  1540. # Check whether temporary license is installed on active CP
  1541. #
  1542. temp_license_check_active()
  1543. {
  1544.     /fabos/cliexec/licenseshow 2>${NULL} | grep "Expiry Date" > ${NULL} 2>&1
  1545.     if [ $? -eq 0 ]
  1546.     then
  1547.         return 1
  1548.     else
  1549.         return 0
  1550.     fi
  1551. }
  1552.  
  1553. #
  1554. # temp_license_check_standby
  1555. #
  1556. # Check whether temporary license is installed on standby CP
  1557. #
  1558. temp_license_check_standby()
  1559. {
  1560.     sync=`/fabos/bin/hashow | sed -n -e 's/^.\+\(State sync\).\+$/\1/gp'`
  1561.     if [ "$sync" != "State sync" ]; then
  1562.         return 0
  1563.     else
  1564.         /usr/bin/rsh -n $(otherhost) /fabos/cliexec/licenseshow 2>${NULL} | grep "Expiry Date" ${NULL} 2>&1
  1565.         if [ $? -eq 0 ]
  1566.         then
  1567.             return 1
  1568.         else
  1569.             return 0
  1570.         fi
  1571.     fi
  1572. }
  1573.  
  1574. lsan_matrix_supported()
  1575. {
  1576.     fcrmatrix=`/fabos/bin/fcrlsanmatrix | grep -E "FCR Matrix is activated"| wc -l`
  1577.     return $fcrmatrix
  1578. }
  1579.  
  1580.  
  1581. # we need to check for condor2 ex_port configuration
  1582. # before going down to 6.0. prevent any download
  1583. # if any ex_ports are configured. We only need to do
  1584. # this for Neptune since Spirit & Thor didn't show up
  1585. # until 6.1
  1586. check_condor2_ex_ports_configured() {
  1587.     case ${SWBD##SWBD} in
  1588.         '62' | '77')
  1589.  
  1590.             correcthost /fabos/bin/switchshow |
  1591.                 /bin/grep -E '\<(EX-Port|Disabled|No_Sync|No_Module|No_Light)\>'|
  1592.             while read index slot port rest
  1593.             do
  1594.               if correcthost /fabos/link_bin/portshow $slot/$port | grep -q "portType.*17" ; then
  1595.                 if correcthost /fabos/link_bin/portcfgexport $slot/$port | grep -q "Admin.*enabled" ; then
  1596.                     $ECHO "downgrading to 6.0 with " $slot "/" $port " still being condor2 ex"
  1597.                     return $STS_ERR
  1598.                 fi
  1599.               fi
  1600.             done
  1601.             # The return above exits the subshell started by the pipe
  1602.             # return here if the subshell exited early.
  1603.             if [ $? -eq $STS_ERR ] ; then return $STS_ERR ; fi
  1604.     esac
  1605.     return $STS_OK
  1606. }
  1607.  
  1608.  
  1609. #
  1610. # check_ethsw_enabled
  1611. #
  1612. # Check whether ETHSW is enabled
  1613. #
  1614. check_ethsw_enabled() {
  1615.  
  1616.     if [ ${SWBD##SWBD} == '76' ]; then
  1617.         return $STS_OK
  1618.     fi
  1619.  
  1620.     /sbin/getethsw > /dev/null 2>&1
  1621.     if [ $? -eq 1 ]; then
  1622.         return $STS_ERR
  1623.     else
  1624.         return $STS_OK
  1625.     fi
  1626.  
  1627. }
  1628.  
  1629. #
  1630. # fcr_enabled
  1631. #
  1632. # Check whether FCR is enabled
  1633. #
  1634. check_fcr_enabled() {
  1635.  
  1636.     /fabos/bin/fosconfig --show | grep "FC Routing service" | grep enabled > /dev/null 2>&1
  1637.     if [ $? -eq 0 ]; then
  1638.         return $STS_ERR
  1639.     else
  1640.         return $STS_OK
  1641.     fi
  1642. }
  1643.  
  1644. #
  1645. # check_hcl_switchstate
  1646. #
  1647. # Check the switchState if it is Faulty to block HCL
  1648. #
  1649. check_hcl_switchstate()
  1650. {
  1651.     hashow_cmd="/fabos/bin/hashow"
  1652.  
  1653.     case "$($hashow_cmd | ( read a; echo $a ))" in
  1654.         *"Not supported"*)
  1655.         ;;
  1656.         *)
  1657.         return $STS_OK
  1658.         ;;
  1659.     esac
  1660.  
  1661.     switch_state=`/fabos/bin/switchshow | sed -n -e 's/switchState://gp' | tr -d '\t'`
  1662.  
  1663.     if [ $switch_state == "Faulty" ]; then
  1664.         is_fwdl_arg "s"
  1665.         if [ $? -ne 0 ]; then
  1666.             return $STS_ERR
  1667.         fi
  1668.     fi
  1669.  
  1670.     return $STS_OK
  1671.  
  1672. }
  1673.  
  1674. CMSH_DEBUG="/fabos/factory/cmsh_debug"
  1675. #
  1676. # Check for sflow in running or startup configuration.
  1677. #
  1678. check_sflow_enabled()
  1679. {
  1680.     if [ ${SWBD##SWBD} == '76' ]; then
  1681.         sflowRunningConfig=`${CMSH_DEBUG} -e "show running-config" | grep sflow | wc -l`
  1682.         sflowStartupConfig=`${CMSH_DEBUG} -e "show startup-config" | grep sflow | wc -l`
  1683.  
  1684.         if [ $sflowRunningConfig -gt 0 ];
  1685.         then
  1686.             return $STS_ERR
  1687.         elif [ $sflowStartupConfig -gt 0 ];
  1688.         then
  1689.             return $STS_ERR
  1690.         fi
  1691.     fi
  1692.  
  1693.     return $STS_OK
  1694. }
  1695.  
  1696. #
  1697. # Check for dot1x in running or startup configuration.
  1698. #
  1699. check_dot1x_enabled()
  1700. {
  1701.     if [ ${SWBD##SWBD} == '76' ]; then
  1702.         dot1xRunningConfig=`${CMSH_DEBUG} -e "show running-config" | grep dot1x | wc -l`
  1703.         dot1xStartupConfig=`${CMSH_DEBUG} -e "show startup-config" | grep dot1x | wc -l`
  1704.  
  1705.         if [ $dot1xRunningConfig -gt 0 ];
  1706.         then
  1707.             return $STS_ERR
  1708.         elif [ $dot1xStartupConfig -gt 0 ];
  1709.         then
  1710.             return $STS_ERR
  1711.         fi
  1712.     fi
  1713.  
  1714.     return $STS_OK
  1715. }
  1716.  
  1717. #
  1718. # Check if System Card feature is enabled
  1719. #
  1720. check_syscard_enabled()
  1721. {
  1722.     SYSCARDENABLECHECK=`/fabos/cliexec/configshow | grep scEnabled | cut -f 2 -d ':'`
  1723.  
  1724.     if [ -z $SYSCARDENABLECHECK ]; then
  1725.         return $STS_OK;
  1726.     fi
  1727.  
  1728.     if [ "$SYSCARDENABLECHECK" = "0x0" ]; then
  1729.         return $STS_OK;
  1730.     fi
  1731.  
  1732.     return $STS_ERR
  1733. }
  1734.  
  1735. #
  1736. # Check if Qourum size is non-zero before downgrading
  1737. #
  1738. check_qourumcard_size()
  1739. {
  1740.     QOURUMSIZE=`/fabos/cliexec/configshow | grep spm.encrGrp.qc.msize | cut -f 2 -d ':'`
  1741.  
  1742.     if [ -z $QOURUMSIZE ]; then
  1743.         return $STS_OK;
  1744.     fi
  1745.  
  1746.     if [ "$QOURUMSIZE" = "0x0" ]; then
  1747.         return $STS_OK;
  1748.     fi
  1749.     return $STS_ERR
  1750. }
  1751. #
  1752. # Check if Secondary RKM keyvault is configured 
  1753. # before upgrading to v6.3,0
  1754. #
  1755. check_sec_rkm_kv()
  1756. {
  1757.     KVTYPE=`/fabos/cliexec/configshow | grep spm.encrGrp.kvType | cut -f 2 -d ':'`
  1758.  
  1759.     if [ -z "$KVTYPE" ]; then
  1760.         return $STS_OK;
  1761.     fi
  1762.  
  1763.     if [ "$KVTYPE" = "0x2" ]; then
  1764.         SECKV=`/fabos/cliexec/configshow | grep spm.encrGrp.secKV.cert.ip | cut -f 2 -d ':'`
  1765.  
  1766.         if [ -z "$SECKV" ]; then 
  1767.             return $STS_OK;
  1768.         else
  1769.             return $STS_ERR;
  1770.         fi
  1771.     fi
  1772.     return $STS_OK;
  1773. }
  1774.  
  1775. #
  1776. # Check if Secondary SKM keyvault is configured 
  1777. # before upgrading to v6.3,0
  1778. #
  1779. check_sec_skm_kv()
  1780. {
  1781.     KVTYPE=`/fabos/cliexec/configshow | grep spm.encrGrp.kvType | cut -f 2 -d ':'`
  1782.  
  1783.     if [ -z "$KVTYPE" ]; then
  1784.         return $STS_OK;
  1785.     fi
  1786.  
  1787.     if [ "$KVTYPE" = "0x5" ]; then
  1788.         SECKV=`/fabos/cliexec/configshow | grep spm.encrGrp.secKV.cert.ip | cut -f 2 -d ':'`
  1789.  
  1790.         if [ -z "$SECKV" ]; then 
  1791.             return $STS_OK;
  1792.         else
  1793.             return $STS_ERR;
  1794.         fi
  1795.     fi
  1796.     return $STS_OK;
  1797. }
  1798. #
  1799. # This routine checks whether any of the 6.3 software
  1800. # features are  active
  1801. #
  1802. check_63_sw_features()
  1803. {
  1804.     $ECHO check_63_sw_features
  1805.  
  1806.     TEST check_ethsw_enabled "$UNSUPPORTED_ETHSW_DISABLE_MSG"
  1807.  
  1808.     TEST check_mace_ag_mode_enabled "$UNSUPPORTED_AG_ON_MACE_MSG"
  1809.  
  1810.     TEST check_elara_ag_mode_enabled "$UNSUPPORTED_AG_ON_ELARA_MSG"
  1811.  
  1812.     TEST check_c2_mirror_connection "$DOWNGRADE_WITH_C2_PORT_MIRROR"
  1813.  
  1814.     TEST check_default_did_offset_in_im "$DOMOFFSETINTEROPCONFIGMSG"
  1815.  
  1816.     TEST check_ag_qos_port_active "$AG_QOS_PORT_ACTIVE_MSG"
  1817.  
  1818.     TEST check_qos_di_zones_presence "$QOS_DI_ZONE_EXISTANCE_MSG"
  1819.  
  1820.     TEST check_ag_qos_port_active_fabric_side "$AG_QOS_PORT_ACTIVE_FABRIC_SIDE_MSG"
  1821.  
  1822.     TEST check_area_range    "$AREA_ASSIGNED_BEYND_MAXPHPORTS"
  1823.  
  1824.     TEST ag_persistent_alpa_enabled "$UNSUPPORTED_PERSISTENT_ALPA_ON_DOWNGRADE"
  1825.  
  1826.     TEST check_sflow_enabled "$UNSUPPORTED_SFLOW_ON_DOWNGRADE"
  1827.  
  1828.     TEST check_dot1x_enabled "$UNSUPPORTED_DOT1X_ON_DOWNGRADE"
  1829.  
  1830.         TEST check_syscard_enabled "$UNSUPPORTED_SYSTEMCARD_FEATURE_ON_DOWNGRADE"
  1831.  
  1832.         TEST check_qourumcard_size "$UNSUPPORTED_QOURUMCARD_SIZE_NON_ZERO"
  1833.  
  1834.     TEST check_passwdCfg_history "$UNSUPPORTED_PASSWDCFG_HISTORY_VALUE"
  1835.  
  1836.     # Check for secondary SKM KV configuration
  1837.     TEST check_sec_skm_kv "$UNSUPPORTED_TWO_SKM_KVS_DOWNGRADE"
  1838.  
  1839.     # Check for portfencing bit for State Change
  1840.     TEST check_pf_statechange_set_allinstances "$UNSUPPORTED_PORTFENCING_STATECHANGEMSG"
  1841.  
  1842.     return $RET_CODE
  1843. }
  1844.  
  1845. #
  1846. # This routine checks whether any of the 6.2 software
  1847. # features are  active
  1848. #
  1849. check_62_sw_features()
  1850. {
  1851.     $ECHO check_62_sw_features
  1852.  
  1853.     TEST check_vf_enabled "$UNSUPPORTED_VF_DISABLE_MSG"
  1854.  
  1855.     # If AG mode enabled on Spirit, don't allow downgrade to lower that 6.2
  1856.     TEST check_ag_mode_enabled "$UNSUPPORTED_AG_ON_SPIRIT_MSG"
  1857.  
  1858.     TEST check_for_rd_zones_with_mode_3_configured "$RDINTEROP3CONFIGUREDMSG"
  1859.  
  1860.     return $RET_CODE
  1861. }
  1862.  
  1863. #
  1864. # This routine checks whether there are any features or conditions
  1865. # to be handled when upgrading
  1866. #
  1867. check_pre63_sw_features()
  1868. {
  1869.     $ECHO check_pre63_sw_features
  1870.  
  1871.     # Check zone names for compatibility with MSFR
  1872.     TEST check_for_msfr_zone_names "$MSFRZONEORCFGNAMEFOUNDMSG"
  1873.     
  1874.     # Check for secondary RKM KV configuration
  1875.     TEST check_sec_rkm_kv "$UNSUPPORTED_TWO_RKM_KVS_UPGRADE"
  1876.     
  1877.     TEST check_http_enabled "$WEBLINKER_MSG"
  1878.  
  1879.     return $RET_CODE
  1880. }
  1881.  
  1882. handle_to_63()
  1883. {
  1884.     $ECHO handle_to_63
  1885.  
  1886.     #
  1887.     # Block downgrade if any 6.3.1 specific feature is enabled
  1888.     #
  1889.     if [ $TO_MAJOR -eq 6 -a $TO_MINOR -eq 3 -a $TO_PATCH -eq 0 ]; then
  1890.         TEST check_elara_ag_mode_enabled "$UNSUPPORTED_AG_ON_ELARA_MSG"
  1891.         if [ $? -ne $STS_OK ]; then
  1892.             return $STS_ERR
  1893.         fi
  1894.  
  1895.         TEST check_xfcip_ipsec_configured "$XFCIP_IPSEC_MSG"
  1896.         if [ $? -ne $STS_OK ]; then
  1897.             return $STS_ERR
  1898.         fi
  1899.  
  1900.         TEST check_xfcip_vlan_tagging_configured "$XFCIP_VLAN_TAGGING_MSG"
  1901.         if [ $? -ne $STS_OK ]; then
  1902.             return $STS_ERR
  1903.         fi
  1904.     fi                      
  1905.  
  1906.     #
  1907.     # We don't allow 6.0 and previous to upgrade to this version
  1908.     #
  1909.     if [ $CUR_MAJOR -lt 6 ]; then
  1910.         add_err_status "$UNSUPPORTED_UP_VERMSG"
  1911.         return $STS_ERR
  1912.     elif [ $CUR_MAJOR -eq 6 -a $CUR_MINOR -eq 0 ]; then
  1913.         add_err_status "$UNSUPPORTED_UP_VERMSG"
  1914.         return $STS_ERR
  1915.     fi
  1916.  
  1917.     #
  1918.     # Allow upgrade from 6.1 only when disruptive single mode is used.
  1919.     #
  1920.     if [ $CUR_MAJOR -eq 6 -a $CUR_MINOR -eq 1 ]; then
  1921.         allow_nondisruptive_fwdl
  1922.         if [ $? -ne $STS_OK ]; then
  1923.             add_err_status "$UNSUPPORTED_UP_VERMSG"
  1924.             return $STS_ERR
  1925.         fi
  1926.     fi
  1927.  
  1928.     #
  1929.     # Check for any blocking features or conditions.
  1930.     #
  1931.     check_pre63_sw_features
  1932.     OVERALL_STS=$?
  1933.     if [ $OVERALL_STS != $STS_OK ]; then
  1934.         return $OVERALL_STS
  1935.     fi
  1936.  
  1937.     return $STS_OK
  1938. }
  1939.  
  1940. handle_to_62()
  1941. {
  1942.     $ECHO handle_to_62
  1943.  
  1944.     #
  1945.     # Block downgrade if any 6.3 specific sw feature is enabled.
  1946.     #
  1947.     check_63_sw_features
  1948.     OVERALL_STS=$?
  1949.     if [ $OVERALL_STS != $STS_OK ]; then
  1950.         return $OVERALL_STS
  1951.     fi
  1952.  
  1953.     #
  1954.     # Block downgrade if any 6.3 specific hw feature is enabled.
  1955.     #
  1956.     check_63_hw_features
  1957.     OVERALL_STS=$?
  1958.     if [ $OVERALL_STS != $STS_OK ]; then
  1959.         return $OVERALL_STS
  1960.     fi
  1961.  
  1962.     return $STS_OK
  1963. }
  1964.  
  1965. handle_to_61()
  1966. {
  1967.     $ECHO handle_to_61
  1968.  
  1969.     CHECK_STS=$STS_OK
  1970.  
  1971.     allow_nondisruptive_fwdl
  1972.     if [ $? -ne $STS_OK ]; then
  1973.         add_err_status "$UNSUPPORTED_DL_VERMSG"
  1974.         return $STS_ERR
  1975.     fi
  1976.  
  1977.     # Check for encryption firmware & its platform
  1978.     if [ -z "$TYPE" ]; then
  1979.         /bin/cat $RELEASE_FILE | /fabos/bin/grep -e $ENC_VERSION_STR -e $ENC_VERSION_STR_DEV 1>/dev/null
  1980.         if [ $? == 0 ] ; then
  1981.             #6.2-6.1_encryption_only_firmware
  1982.             case ${SWBD##SWBD} in
  1983.                 '67'|'68'|'62')
  1984.                     # continue with other 6.2-6.1 downgrade checks
  1985.                     ;;
  1986.                 *)
  1987.                     add_err_status "$NON_ENC_PLATFORMMSG"
  1988.                     return $STS_ERR
  1989.                     ;;
  1990.             esac
  1991.         else
  1992.             #6.2-6.1_non_encryption_firmware
  1993.             check_61_enc_hw_features
  1994.             OVERALL_STS=$?
  1995.             if [ $OVERALL_STS != $STS_OK ]; then
  1996.                 return $OVERALL_STS
  1997.             fi
  1998.         fi
  1999.     fi
  2000.  
  2001.     #
  2002.     # Block downgrade if any 6.2 specific sw feature is enabled.
  2003.     #
  2004.     check_62_sw_features
  2005.     OVERALL_STS=$?
  2006.     if [ $OVERALL_STS != $STS_OK ]; then
  2007.         CHECK_STS=$OVERALL_STS
  2008.     fi
  2009.  
  2010.     #
  2011.     # Block downgrade if any 6.3 specific sw feature is enabled.
  2012.     #
  2013.     check_63_sw_features
  2014.     OVERALL_STS=$?
  2015.     if [ $OVERALL_STS != $STS_OK ]; then
  2016.         CHECK_STS=$OVERALL_STS
  2017.     fi
  2018.  
  2019.     if [ $CHECK_STS != $STS_OK ]; then
  2020.         return $CHECK_STS
  2021.     fi
  2022.  
  2023.     #
  2024.     # Block downgrade if any 6.2 specific hw feature is enabled.
  2025.     #
  2026.     check_62_hw_features
  2027.     OVERALL_STS=$?
  2028.     if [ $OVERALL_STS != $STS_OK ]; then
  2029.         CHECK_STS=$OVERALL_STS
  2030.     fi
  2031.  
  2032.     #
  2033.     # Block downgrade if any 6.3 specific hw feature is enabled.
  2034.     #
  2035.     check_63_hw_features
  2036.     OVERALL_STS=$?
  2037.     if [ $OVERALL_STS != $STS_OK ]; then
  2038.         CHECK_STS=$OVERALL_STS
  2039.     fi
  2040.  
  2041.     return $CHECK_STS
  2042.  
  2043. }
  2044.  
  2045. # This is the 6.3-6.0 and lower scenario
  2046. handle_pre_60()
  2047. {
  2048.     $ECHO handle_pre_60
  2049.     add_err_status "$UNSUPPORTED_DL_VERMSG"
  2050.     return ${STS_ERR}
  2051. }
  2052.  
  2053. #check if passwdcfg_history value is 0.
  2054. check_passwdCfg_history()
  2055. {
  2056.     HIST_VAL=$(/fabos/abin/passwdcfg --show | sed -n -e 's/passwdcfg.history: //gp')
  2057.     if [ $HIST_VAL -eq 0 ]; then
  2058.                return $STS_ERR
  2059.     fi
  2060.     
  2061.     return $STS_OK
  2062. }
  2063.  
  2064. # get the current firmware version
  2065. get_current_version()
  2066. {
  2067.     CUR_MAJOR=$(/sbin/getfabosver | sed -n -e 's/Major://gp')
  2068.     CUR_MINOR=$(/sbin/getfabosver | sed -n -e 's/Minor://gp')
  2069. }
  2070.  
  2071.  
  2072. #
  2073. # main()
  2074. #
  2075. $ECHO Requested version is ${TO_MAJOR}.${TO_MINOR}.${TO_PATCH} Type is $TYPE
  2076.  
  2077. if [ -z $TYPE ]; then
  2078.     TEST check_hcl_switchstate "$SWITCH_FAULTY_MSG"
  2079.     RET=$?
  2080.     if [ $RET != $STS_OK ]; then
  2081.         exit $RET_CODE
  2082.     fi
  2083.  
  2084.     #
  2085.     # clean up to free up disk space on /mnt before firmwaredownload
  2086.     #
  2087.     $ECHO removing tracedump.dmp
  2088.     rm -f /mnt/var/tracedump.dmp
  2089. fi
  2090.  
  2091. get_current_version
  2092.  
  2093. #
  2094. # Handle a specific firmware version
  2095. #
  2096. case "${TO_MAJOR}.${TO_MINOR}" in
  2097.     '6.3')
  2098.         handle_to_63
  2099.         RET=$?
  2100.     ;;
  2101.     '6.2')
  2102.         handle_to_62
  2103.         RET=$?
  2104.     ;;
  2105.     '6.1')
  2106.         handle_to_61
  2107.         RET=$?
  2108.     ;;
  2109.     *)
  2110.         handle_pre_60
  2111.         RET=$?
  2112.     ;;
  2113. esac
  2114.  
  2115.  
  2116. #
  2117. # Preinstall check fails
  2118. #
  2119. if [ $RET != $STS_OK ]; then
  2120.     exit $RET;
  2121. fi
  2122.  
  2123. #
  2124. # Firmwaredownload check passes, return
  2125. #
  2126. if [ -z $TYPE ]; then
  2127.     $ECHO return code is $RET
  2128.     exit $RET
  2129. fi
  2130.  
  2131. #
  2132. # For firmwarerestore, we will perform the firmwarerestore here.
  2133. # it will not return to the caller. That is to workaround a
  2134. # 2.4.19 kernel and 2.3.6 glibc mismatch issue. (79299). Read
  2135. # more comments in fwdl_undo() in the fwdl.c file.
  2136. #
  2137. baddev=`bootenv BadRootDev 2>/dev/null`
  2138. upgrade=`bootenv Upgrade 2>/dev/null`
  2139. softupgrade=`bootenv SoftUpgrade 2>/dev/null`
  2140.  
  2141. dev_p=`bootenv OSRootPartition 2>/dev/null | cut -d ';' -f 1`
  2142. dev_s=`bootenv OSRootPartition 2>/dev/null | cut -d ';' -f 2`
  2143. kern_p=`bootenv OSLoader 2>/dev/null | cut -d ';' -f 1`
  2144. kern_s=`bootenv OSLoader 2>/dev/null | cut -d ';' -f 2`
  2145.  
  2146. mount_p=`cat /proc/mounts | grep " / " | grep -v rootfs |sed 's? .*??g;s?^.*dev/??g'`
  2147. mount_s=`cat /proc/mounts |grep "/mnt" | sed 's? .*??g;s?^.*dev/??g'`
  2148.  
  2149. if [ -n "$baddev" ]; then
  2150.     add_err_status "$FWDL_RUNNING_MSG"
  2151.         exit 1;
  2152. fi
  2153.  
  2154. if [ -n "$softupgrade" ]; then
  2155.     add_err_status "$FWDL_RUNNING_MSG"
  2156.     exit 1;
  2157. fi
  2158.  
  2159. if [ "$upgrade" != /dev/$mount_p ]; then
  2160.     add_err_status "$FWRESTORE_DISALLOWED_MSG"
  2161.         exit 1;
  2162. fi
  2163.  
  2164. #
  2165. # prevent firmwarerestore from 6.3 to 6.1.2_cee because
  2166. # the we can not restore the PROM image in this case
  2167. #
  2168. case ${SWBD##SWBD} in
  2169.     '76')
  2170.         if [ ! -s /mnt/boot/bootrom.bin ]; then
  2171.             add_err_status "$FWRESTORE_VER_DISALLOWED_MSG"
  2172.             exit 1;
  2173.         fi
  2174.     esac 
  2175.  
  2176. # The following steps upgrades accounts with default AD member list
  2177. if [ $CUR_MAJOR -le 6 -a $CUR_MINOR -le 1 ]; then
  2178.     /usr/sbin/chroot /mnt /fabos/libexec/userdb_convert $CUR_MAJOR.$CUR_MINOR $TO_MAJOR.$TO_MINOR > /dev/null 2>&1
  2179. fi
  2180.  
  2181. if [ $CUR_MAJOR -eq 6 ] && [ $CUR_MINOR -ge 2 ]; then
  2182.     if [ $TO_MAJOR -le 6 -a $TO_MINOR -le 1 ]; then
  2183.         /fabos/libexec/userdb_convert $CUR_MAJOR.$CUR_MINOR $TO_MAJOR.$TO_MINOR > /dev/null 2>&1
  2184.     fi
  2185. fi
  2186.  
  2187. #Push Manufacturing key to SP
  2188. if [ -f '/fabos/libexec/spmPublicKeyUpdate' ] ; then
  2189.     /fabos/libexec/spmPublicKeyUpdate
  2190. fi
  2191.  
  2192. # Resotoring only the 8548 and 440epx prom images
  2193. echo "Restoring the PROM image ..."
  2194. if [ -s /mnt/boot/bootrom.bin ]; then
  2195.     /usr/sbin/chroot /mnt /sbin/prominst
  2196. fi
  2197.  
  2198.  
  2199. bootenv OSRootPartition "$dev_s;$dev_p"
  2200. bootenv OSLoader "$kern_s;$kern_p"
  2201. bootenv Upgrade "/dev/$dev_s"
  2202. bootenv SoftUpgrade "commit"
  2203.  
  2204. #
  2205. # Fix for defect 279915
  2206. #
  2207. if [ $CUR_MAJOR -eq 6 -a $CUR_MINOR -le 2 ]; then
  2208. echo "The system is rebooting now!! After reboot, firmwarecommit " \
  2209.      "will be started and the partitions will be restored to the " \
  2210.      "original firmware."
  2211. /fabos/cliexec/reboot -s -r FirmwareDownload -f
  2212. fi
  2213.  
  2214. exit 0
  2215.