#!/bin/sh
#
# This module contains the deployment script to handle an Intel system in WinPE and Linux
#

# Deployment state defines:
Sflash=1
Sconfig=2
Sdisk=3
Sraid=4
Sos=5
Snet=6
Srestore=7
FINISHED=8
STATEVAR=DepState


echo "run customized deployment scripts here ..."
echo "execute a series of scripts of your own making ..."

#ret=queryProperty SMBIOS Version - type="0"
#if not BIOSver or ret:
#    addLogRecord customDeployment.sh ERROR 'BIOS version unavailable: $ret'
#    exit 1

persistVariable read $STATEVAR
depstate=$?
if [ $depstate -ge $FINISHED ]
then
    persistVariable update $STATEVAR=$Sflash
    depstate=$Sflash
fi

if [ $depstate -eq $Sflash ]
then
    $DeployPath/doc/flash.py
    status=$?
    if [ $status -eq 0 ]
    then
   	persistVariable update $STATEVAR=$Sconfig
    	depstate=$Sconfig
    else
        exit $status
    fi
fi

if [ $depstate -eq $Sconfig ]
then
    addLogRecord customDeployment.sh INFO 'system flashed, ready for BIOS/FW configuration'
    #call configuration script here
    persistVariable update $STATEVAR=$Sdisk
    depstate=$Sdisk
fi
    
if [ $depstate -eq $Sdisk ]
then
    addLogRecord customDeployment.sh INFO 'BIOS/FW configured, ready for disk configuration'
    #call configuration script here
    persistVariable update $STATEVAR=$Sswraid
    depstate=$Sswraid
fi
    
if [ $depstate -eq $Sswraid ]
then
    addLogRecord customDeployment.sh INFO 'disk configured, ready for SW RAID configuration'
    #call configuration script here
    #if BIOSver.split('.')[0] == 'S5000':
        persistVariable update $STATEVAR=$Shwraid
        depstate=$Shwraid
    #elif BIOSver.split('.')[0] == 'S3000':
    #    persistVariable update $STATEVAR=$Sos
    #    depstate=$Sos
    #else:
    #    addLogRecord customDeployment.sh ERROR 'Unsupported platform - BIOS version %s'%BIOSver)
    #    exit 1
fi
    
if [ $depstate -eq $Shwraid ]
then
    addLogRecord customDeployment.sh INFO 'SW RAID  configured, ready for HW RAID configuration'
    #call configuration script here
    persistVariable update $STATEVAR=$Sos
    depstate=$Sos
fi
    
if [ $depstate -eq $Sos ]
then
    addLogRecord customDeployment.sh INFO 'RAID configured, ready for OS installation'
    #call installation script here
    persistVariable update $STATEVAR=$Snet
    depstate=$Snet
fi
    
if [ $depstate -eq $Snet ]
then
    addLogRecord customDeployment.sh INFO 'OS installed, ready for NET configuration'
    #call configuration script here
    persistVariable update $STATEVAR=$Srestore
    depstate=$Srestore
fi
    
if [ $depstate -eq $Srestore ]
then
    addLogRecord customDeployment.sh INFO 'NET configured, ready to restore'
    #call erase script here
    persistVariable delete $STATEVAR
    depstate=$FINISHED
    evaluateDeployment
fi
    
exit
