#!/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/D3610/D3710 12Gb SAS Disk Enclosure ROM Flash Component for Linux (x64)"
echo $copyright
echo ""
echo " This package updates the I/O module firmware on HP D3600, D3700, D3610 and D3710 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 | --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 [ "`uname -m`" ==  "x86_64" ] ; then
  cp -f x86_64/* .
fi
if [ $sflag -eq 0 ] ; then
echo "HP D3600/D3700/D3610/D3710 12Gb SAS Disk Enclosure ROM Flash Component for Linux (x64)"
echo $copyright
echo ""
echo "Version : 3.64"
echo ""
echo "Important Notes:"
cat <<-%IMP_NOTES%
 IMPORTANT: Firmware updates must be performed during a system maintenance window, with all I/O to the system halted.In single domain configuration, if user hosts an OS in D3000(or any storage box) and flash the SEPs, it will hung/crash everytime as SmartComponent will reset the SEPs after flash/codeload  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
