#!/bin/sh
ADDLOG=addLogRecord
# ADDLOG=echo

DEMOSTATE=`persistVariable read Demo`

if [ "$DEMOSTATE" = "" ] ; then
    echo STATE: $DEMOSTATE
    $ADDLOG $0 INFO "Provisioning state: Start $DEMOSTATE"
    $ADDLOG $0 INFO "Update BIOS and FW, then reboot."
    pushd /opt/deploy/doc
        sh ./do.sh
        persistVariable update Demo=1
        $ADDLOG $0 INFO "Update complete, now reboot."
    popd
    reboot
elif [ "$DEMOSTATE" = "01" ] ; then
    echo "STATE: $DEMOSTATE"
    $ADDLOG $0 INFO "Provisioning state: Prepare RAID: $DEMOSTATE"
    echo "Build the RAID volume and Reboot."
    $ADDLOG $0 INFO "Build the RAID volume and Reboot."
    pushd /opt/deploy/doc/cmdtool2
        sh ./cmdtool2_createvolume.sh
        if [ $? = 9 ]
        then
            #BIOS was set for RAID - reboot to take effect
            reboot
        fi
        persistVariable update Demo=2
        $ADDLOG $0 INFO "RAID complete, now reboot."
    popd
    reboot
elif [ "$DEMOSTATE" = "02" ] ; then
    echo STATE: $DEMOSTATE
    $ADDLOG $0 INFO "Provisioning state: Set boot order: $DEMOSTATE"
    pushd /opt/deploy/doc/customshell
        persistVariable update Demo=4
        boutil /f HDtop.bcf
        $ADDLOG $0 INFO "Look, Ma! No hands!!!  :)"
        persistVariable delete Demo
    popd
else
    echo UNKNOWN Demo state: $DEMOSTATE
    exit 1
fi
exit 0
