@echo off
set errlevel=0

call queryProperty IntelBIOSID BoardFamilyID S3000
if %errorlevel% EQU 0 (
    echo %0 script only works on a S3000 system
    call addLogRecord %0 INFO "%0 script only works on a S3000 system"
    set errlevel=1
    call :ERROR
    goto :DONE
)
call queryProperty BIOSRAID SWRAID Enabled
if %errorlevel% EQU 0 (
    call addLogRecord %0 INFO "setBIOS4RAID enable SATA, reboot required."
    call setBIOS4RAID enable SATA
    set errlevel=%errorlevel%
    call :ERROR
    goto :DONE
)
call queryProperty BIOSRAID Vendor LSI
if %errorlevel% EQU 0 (
    call addLogRecord %0 INFO "setBIOS4RAID enable SATA, reboot required."
    call setBIOS4RAID enable SATA
    set errlevel=%errorlevel%
    call :ERROR
    goto :DONE
)
call addLogRecord %0 INFO "Begin SWRAID Volume creation with HyperWin."
REM Clear previous RAID volumes and configuration information and creates RAID1
REM on ports #0 and #1 without asking for user input.
call addLogRecord %0 INFO "Create SWRAID: hyperwin /AM:00,10 /S"
hyperwin /AM:00,10 /S
set errlevel=%errorlevel%
if %errlevel% NEQ 0 (
    call :ERROR
    goto :DONE
)

rem #Initialize the New Volume
call addLogRecord %0 INFO "Initialize Volume: hyperwin /INIT /l0"
hyperwin /INIT /l0
set errlevel=%errorlevel%
if %errlevel% NEQ 0 (
    call :ERROR
    goto :DONE
)

rem #Set Disk Cache options for Port#0 and Port #1
call addLogRecord %0 INFO "Set Disk Cache options for Port#0: hyperwin /SETPD /C0 /wc-on /ra-on"
hyperwin /SETPD /C0 /wc-on /ra-on
set errlevel=%errorlevel%
if %errlevel% NEQ 0 (
    call :ERROR
    goto :DONE
)
call addLogRecord %0 INFO "Set Disk Cache options for Port#1: hyperwin /SETPD /C1 /wc-on /ra-on"
hyperwin /SETPD /C1 /wc-on /ra-on
set errlevel=%errorlevel%
if %errlevel% NEQ 0 (
    call :ERROR
    goto :DONE
)

goto OK

:ERROR
if %errlevel% EQU 0 goto :EOF
call addLogRecord %0 ERROR "errlevel=%errlevel%"
echo errlevel=%errlevel%
goto :DONE

:OK
set errlevel=0
call addLogRecord %0 INFO "SUCCESS"
goto :DONE

:DONE
exit /B %errlevel%
