#!/bin/sh
#    prepareResources.sh
# unpack resource images for use by flash scripts
#
mydir=`pwd`
tmped=/tmp/ed.tmp

caps_rename() {
  biosfile=`grep BIOSNAME flashupdt.cfg  |awk '{ print $2}' |sed -e 's/"//g'`
  capfile=`ls |grep -i .cap$`
  # echo "capfile=$capfile biosfile=$biosfile"
  if [ ! -f $biosfile ]
  then
     mv $capfile $biosfile
  fi
}

skip_HSC() {
  echo 1 >$tmped
  echo /CFGNAME >>$tmped
  echo a >>$tmped
  echo "    SET \"NI_HSC\"" >>$tmped
  echo . >>$tmped
  echo w >>$tmped
  echo q >>$tmped
  ed flashupdt.cfg <$tmped
}

if [ $# -ge 1 ]
then
  chassis=$1
else
  chassis=`queryProperty FRU "Chassis OEM Field" -`
  # alternative:
  # chassis=`ipmiutil fru |grep "Chassis OEM Field" |cut -f2 -d':' |sed -e 's/ //g'`
fi

platform=`queryProperty IntelBIOSID BoardFamilyID -`
# alternative:
# platform=`dmidecode |grep "Version: S" |awk '{print $2}' |cut -f1 -d'.'`-
addLogRecord $0 INFO "for platform $platform, chassis $chassis"
updateDir=$DeployPath/update
if [ -e $updateDir ]
then
    rm -rf $updateDir
fi
mkdir $updateDir
if [ "$platform" = "S3000" ]
then
    cd $BootDevice/updates/$platform
    addLogRecord $0 INFO "unzip -o S3000AH_BIOS_Release_0046.zip into $updateDir"
    unzip -o S3000AH_BIOS_Release_0046.zip -d $updateDir
    cd $updateDir
    caps_rename
elif [ "$platform" = "S5000" ]
then
    cd $BootDevice/updates/$platform
    JSUP_PACKAGE=
    [ "$chassis" = "SR2500LX" ] && JSUP_PACKAGE="AL_06_25_2007.zip"
    [ "$chassis" = "TIGH2U" ]   && JSUP_PACKAGE="STA16_916412.zip"
    [ "$chassis" = "NSC2U" ]    && JSUP_PACKAGE="STA16_916412.zip"
    [ "$chassis" = "NSW1U" ]    && JSUP_PACKAGE="SHB26_912018.zip"
    [ "$chassis" = "TIGW1U" ]   && JSUP_PACKAGE="SHB26_912018.zip"
    if [ "$JSUP_PACKAGE" = "" ]
    then
        echo "ERROR chassis $chassis not recognized."
        addLogRecord $0  ERROR "ERROR chassis $chassis not recognized."
    else
        addLogRecord $0  INFO "unzip -o $JSUP_PACKAGE into $updateDir"
        unzip -o $JSUP_PACKAGE -d $updateDir
        cd $updateDir
        caps_rename
        skip_HSC
    fi
elif [ "$platform" = "S5500" ]
then
    cd $BootDevice/updates/$platform
    addLogRecord $0 INFO "unzip -o S5500.zips into $updateDir"
    unzip -o R0016.zip -d $updateDir
    unzip -o FUR2_05.zip -d $updateDir
    unzip -o BMC_0019.zip -d $updateDir
    cd $updateDir
    caps_rename
else
    echo "ERROR platform $platform not recognized."
    addLogRecord $0  ERROR  "ERROR platform $platform not recognized."
fi

cd $mydir

