#!/bin/bash

# Perform various BIOS function
# Possible exit code: 0 everything worked
#		      1 BIOS flash failed / netboot disabled
#		      2 Model does not support operation
#		      3 BIOS is already up to date
# LATEST_CR2_BIOS="39"
# LATEST_CR3_BIOS="32"
# LATEST_CR4_BIOS="111"
#set -x
vpd=`/opt/hsc/bin/getHMCVPD`
#bioslvl=`/opt/hsc/bin/getHMCVPD -b`
# Check for VPD first. Do not change this logic.
# This way if this script is run on unsupported model
# it will return a 2.
# Only do this function on Machines that are supported
# Storage does not use this function
# Function changed. We no longer update the bios at install. walt 12/10/07

if [ "$1" == "update" ]; then
           exit 2
fi

if [ "$1" == "modify" ]; then
   # make network the first
   case "$vpd" in
    *CR2 | *CR3 | *CR4 | 8676* | 8837* | 7978* )
       /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice1 "Network"
       /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice2 "Diskette Drive 0"
       /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice3 "CD ROM"
       /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice4 "Hard Disk 0"
       /opt/hsc/sbin/asu set CMOS_ENET_PXE_ENABLE "Planar Ethernet 1 and 2"
       ;;
    7310C05 )
       /opt/hsc/sbin/asu set cmosStartupPrimary1 "Network-Planar0"
       /opt/hsc/sbin/asu set cmosStartupPrimary3 "CD/DVD-ROM"
       /opt/hsc/sbin/asu set cmosStartupPrimary4 "Hard Disk"
       ;;
    *C06 )
       /opt/hsc/sbin/asu set cmosIPLOrder0 "PCI LAN1"
       /opt/hsc/sbin/asu set cmosIPLOrder1 "USB FDD0"
       /opt/hsc/sbin/asu set cmosIPLOrder2 "IDE CDROM"
       /opt/hsc/sbin/asu set cmosIPLOrder3 "IDE HDD0"
       /opt/hsc/sbin/asu set cmosIPLOrder4 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder5 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder6 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder7 "None"
       ;;
    *C07 )
       /opt/hsc/sbin/asu set cmosIPLOrder0 "PCI LAN Planar"
       /opt/hsc/sbin/asu set cmosIPLOrder1 "CDROM1"
       /opt/hsc/sbin/asu set cmosIPLOrder2 "HDD(S0)"
       /opt/hsc/sbin/asu set cmosIPLOrder3 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder4 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder5 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder6 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder7 "None"
       ;;

  *)
       exit 2
       ;;
   esac
fi
if [ "$1" == "reset" ]; then
   # set back to default settings
   case "$vpd" in
    *CR2 | *CR3 | *CR4 | 8676* | 8837* | 7978* )
      /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice1 "Diskette Drive 0"
      /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice2 "CD ROM"
      /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice3 "Hard Disk 0"
      /opt/hsc/sbin/asu set CMOS_PrimaryBootDevice4 "Network"
      ;;
    7310C05 )
       /opt/hsc/sbin/asu set cmosStartupPrimary2 "CD/DVD-ROM"
       /opt/hsc/sbin/asu set cmosStartupPrimary3 "Hard Disk"
       /opt/hsc/sbin/asu set cmosStartupPrimary4 "Network-Planar0"
       ;;
    *C06 )
       /opt/hsc/sbin/asu set cmosIPLOrder0 "USB FDD0"
       /opt/hsc/sbin/asu set cmosIPLOrder1 "IDE CDROM"
       /opt/hsc/sbin/asu set cmosIPLOrder2 "IDE HDD0"
       /opt/hsc/sbin/asu set cmosIPLOrder3 "PCI LAN1"
       /opt/hsc/sbin/asu set cmosIPLOrder4 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder5 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder6 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder7 "None"
       ;;
    *C07 )
       /opt/hsc/sbin/asu set cmosIPLOrder0 "CDROM1"
       /opt/hsc/sbin/asu set cmosIPLOrder1 "HDD(S0)"
       /opt/hsc/sbin/asu set cmosIPLOrder2 "PCI LAN Planar"
       /opt/hsc/sbin/asu set cmosIPLOrder3 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder4 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder5 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder6 "None"
       /opt/hsc/sbin/asu set cmosIPLOrder7 "None"
       ;;
  *)
       exit 2
       ;;
   esac
fi
if [ "$1" == "viewnetboot" ]; then
   case "$vpd" in
    *CR2 | *CR3 | *CR4 | 8676* | 8837* | 7978* )
      /opt/hsc/sbin/asu show CMOS_PrimaryBootDevice1 | grep -q "Network"
      exit $?
      ;;
    7310C05 )
      /opt/hsc/sbin/asu show cmosStartupPrimary1 | grep -q "Network"
      exit $?
      ;;
    *C07 | *C06 )
       /opt/hsc/sbin/asu show cmosIPLOrder0 | grep -q  "PCI LAN"
      exit $?
      ;;
    *)
       exit 2
       ;;
    esac
fi
exit 0
