#!/bin/bash
export LD_LIBRARY_PATH=.
copyright="(C) Copyright 2015 Hewlett Packard Enterprise Development LP"
maxargs=${#@}
args[maxargs]=
aflag=0
sflag=0
index=0
argindex=0
HELP()
{
echo "HP D3600/D3700 12Gb SAS Disk Enclosure ROM Flash Component for Linux (x86)"
echo $copyright
echo ""
echo " This package updates the I/O module firmware on HP D3600 and D3700 Disk Enclosures attached to supported HP Storage Controllers and Host Bus Adapters"
echo ""
echo "OPTIONS for in band enclosure flash"
echo "   -d, --discover <file>    Dumps discovery information in XML format to <file>"
echo "   -e, --reflash            Flash even if the device is already up to date"
echo "   -f, --force              Always flash applicable devices (same as -e -g)"
echo "   -g, --downgrade          Flash if the device has a later firmware"
echo "   -s, --silent             Do not display any text"
echo ""
echo "Activity logs are kept in /var/cpq/Component.log file"
echo ""
exit 0
}
until [ $index -ge $maxargs ]
do
case "$1" in
--help | -h ) HELP;;
-s | --silent ) sflag=1;args[$argindex]="$1"; let "argindex += 1"
let "index += 1"; shift;;
--user | -l )   export OA_USERNAME="$2"
let "index += 2"; shift 2;;
--passwd | -p )   export OA_PASSWORD="$2"
let "index += 2";shift 2;;
--target | -n ) export OA_ADDRESS="$2"
let "index += 2";shift 2;;
*)              args[$argindex]="$1"; let "argindex += 1"
let "index += 1";shift;;
esac
done
if [ -n "$OA_USERNAME" -o -n "$OA_PASSWORD" -o -n "$OA_ADDRESS" ]
then
aflag=1
fi
if [ $sflag -eq 0 ] ; then
echo "HP D3600/D3700 12Gb SAS Disk Enclosure ROM Flash Component for Linux (x86)"
echo $copyright
echo ""
echo "Version : 1.72"
echo ""
echo "Important Notes:"
cat <<-%IMP_NOTES%
 IMPORTANT: Due to potential issues in D3000 JBODs when certain third-party HDDs are installed, customers that are currently running FW version 2.02 on D3000 should replace it with FW v1.72 for all D3x00 Storage Enclosures.  FW v1.72 is also recommended for all D3x00 Storage Enclosures currently running earlier versions of FW on the JBOD.  Please refer to the customer advisory for more details.  IMPORTANT: Firmware updates must be performed during a system maintenance window, with all I/O to the system halted.  WARNING! Do not power cycle or restart during the firmware update as this can result in loss of capabilities for this unit. It typically takes several minutes for the firmware to load.  NOTE:All firmware flash progress messages are logged to /var/cpq/D3000.log and flash summary is logged to /var/cpq/Component.log.
%IMP_NOTES%
echo ""
echo "Warning - Please go through the above important notes section before continuing!"
echo "Do you want to continue(yes/no):"
read confirm
if expr "$confirm" : "[Yy]$" >/dev/null || expr "$confirm" : "[Yy][Ee][Ss]$" >/dev/null  ; then
if [ $aflag != 1 ] ; then
./ccissflash  "${args[@]}"
_RESULT=$?
fi
else
_RESULT=5
fi
exit $_RESULT
fi
if [ $sflag -eq 1 ] ; then
if [ $aflag != 1 ] ; then
./ccissflash  "${args[@]}"
_RESULT=$?
exit $_RESULT
fi
fi
