#!/bin/sh

echo 
echo "----- KabyLake and SkyLake BIOS updater - Linux 32bit Version -----"
echo 

chmod +x H2OFFT.sh

# Sanitiy check and init parameters
if [ $# -lt 1 ]; then
	echo "Usage: $0 BIOSfile [DUMPfile] [Options]"
	echo "Where:"
	echo "BIOSfile is the MANDATORY BIOS binary image"
	echo "DUMPfile is the optional dumped BIOS file"
	echo "Options are additional command line options"
	echo 
	echo "See documentation for more information"
	exit $E_MISSING_POS_PARAM
fi  
Arg1=$1
if [ $# -lt 2 ]; then
	Arg2=$1
else
	Arg2=$2
	shift
fi  
shift

# Saving LAN setting
echo "Dumping old BIOS image..."
./H2OFFT.sh OldBios.bin -g -n -DAM

# Programming new image
echo 
echo "Programming new BIOS image..."
echo 
./H2OFFT.sh $Arg1 -ALL -N $@

# Deleting NVS
echo 
echo "Resetting NVS..."
echo 
./H2OFFT.sh $Arg2 -SPN -N -Q

# Restoring LAN setting
echo "Restoring MAC address and LED setting..."
echo 
./H2OFFT.sh OldBios.bin -GBE -N -Q
rm OldBios.bin

# Done
echo "Done: you can now safely turn the power off."
