@echo off
rem ********************************************************************************
rem *
rem * RAIDCLN.BAT
rem *
rem * This file controls the disposal/clean of RAID adapters for the ServerGuide
rem * Scripting Toolkit.
rem *
rem * This batch file is called by the disposal process and by cfgraid
rem *
rem * NOTE: you MUST run hwdet.bat first to set the env vars below!
rem *
rem ********************************************************************************

:CLEAN

rem ********************************************************************************
rem * see if env vars are set. if not, then HWDET was not run. Fail.
rem ********************************************************************************

if "%NM_SR%"=="" goto error

rem ********************************************************************************
rem *    hwdet has already been run, to set these env vars:
rem *    NM_SR  Number of IBM ServeRAID 4H, 4Lx, 4Mx, 5i, 6i, 6i+, 6M
rem *    NM_TT  Number of IBM ServeRAID t-type
rem *    NM_EA  Number of IBM ServeRAID e-type SATA
rem *    NM_ES  Number of IBM ServeRAID e-type SCSI
rem *    NM_IS  Number of LSI-1020, LSI-1030
rem *    NM_ID  Number of IDE RAID
rem ********************************************************************************


rem ********************************************************************************
rem *    IBM ServeRAID 4H, 4Lx, 4Mx, 5i, 6i, 6i+, 6M
rem ********************************************************************************
:CLNSR
if %NM_SR%==0 goto CLNTT
if %NM_SR%==16 goto S16
if %NM_SR%==15 goto S15
if %NM_SR%==14 goto S14
if %NM_SR%==13 goto S13
if %NM_SR%==12 goto S12
if %NM_SR%==11 goto S11
if %NM_SR%==10 goto S10
if %NM_SR%==9  goto S9
if %NM_SR%==8  goto S8
if %NM_SR%==7  goto S7
if %NM_SR%==6  goto S6
if %NM_SR%==5  goto S5
if %NM_SR%==4  goto S4
if %NM_SR%==3  goto S3
if %NM_SR%==2  goto S2
if %NM_SR%==1  goto S1

:S16
IPSSEND SETCONFIG 16 DEFAULT NOPROMPT > nul
:S15
IPSSEND SETCONFIG 15 DEFAULT NOPROMPT > nul
:S14
IPSSEND SETCONFIG 14 DEFAULT NOPROMPT > nul
:S13
IPSSEND SETCONFIG 13 DEFAULT NOPROMPT > nul
:S12
IPSSEND SETCONFIG 12 DEFAULT NOPROMPT > nul
:S11
IPSSEND SETCONFIG 11 DEFAULT NOPROMPT > nul
:S10
IPSSEND SETCONFIG 10 DEFAULT NOPROMPT > nul
:S9
IPSSEND SETCONFIG 9  DEFAULT NOPROMPT > nul
:S8
IPSSEND SETCONFIG 8  DEFAULT NOPROMPT > nul
:S7
IPSSEND SETCONFIG 7  DEFAULT NOPROMPT > nul
:S6
IPSSEND SETCONFIG 6  DEFAULT NOPROMPT > nul
:S5
IPSSEND SETCONFIG 5  DEFAULT NOPROMPT > nul
:S4
IPSSEND SETCONFIG 4  DEFAULT NOPROMPT > nul
:S3
IPSSEND SETCONFIG 3  DEFAULT NOPROMPT > nul
:S2
IPSSEND SETCONFIG 2  DEFAULT NOPROMPT > nul
:S1
IPSSEND SETCONFIG 1  DEFAULT NOPROMPT > nul



rem ********************************************************************************
rem *    %NM_TT%  Number of IBM ServeRAID t-type
rem ********************************************************************************

:CLNTT
IF %NM_TT%==0 GOTO CLNEA
if %NM_TT%==16 goto T16
if %NM_TT%==15 goto T15
if %NM_TT%==14 goto T14
if %NM_TT%==13 goto T13
if %NM_TT%==12 goto T12
if %NM_TT%==11 goto T11
if %NM_TT%==10 goto T10
if %NM_TT%==9  goto T9
if %NM_TT%==8  goto T8
if %NM_TT%==7  goto T7
if %NM_TT%==6  goto T6
if %NM_TT%==5  goto T5
if %NM_TT%==4  goto T4
if %NM_TT%==3  goto T3
if %NM_TT%==2  goto T2
if %NM_TT%==1  goto T1

:T16
acu /DC0 /C15 /S
:T15
acu /DC0 /C14 /S
:T14
acu /DC0 /C13 /S
:T13
acu /DC0 /C12 /S
:T12
acu /DC0 /C11 /S
:T11
acu /DC0 /C10 /S
:T10
acu /DC0 /C9 /S
:T9
acu /DC0 /C8 /S
:T8
acu /DC0 /C7 /S
:T7
acu /DC0 /C6 /S
:T6
acu /DC0 /C5 /S
:T5
acu /DC0 /C4 /S
:T4
acu /DC0 /C3 /S
:T3
acu /DC0 /C2 /S
:T2
acu /DC0 /C1 /S
:T1
acu /DC0 /C0 /S


rem ********************************************************************************
rem *    IBM ServeRAID e-type SATA
rem ********************************************************************************
:CLNEA

if %NM_EA%==0 GOTO CLNES

acuichsv /d all  /S

rem ********************************************************************************
rem *    IBM ServeRAID e-type SCSI
rem ********************************************************************************
:CLNES

IF %NM_ES%==0 GOTO CLNIS

raidsel -D all -q
raidsel -Z all -q


rem ********************************************************************************
rem *    LSI-1020, LSI-1030
rem ********************************************************************************
:CLNIS

IF %NM_IS%==0 GOTO CLNID

COPY %TK_PATH%\utils\cfg1030.exe %RAMDSK% >nul
%RAMDSK%

IF %NM_IS%==1 GOTO IS1

:IS2
CFG1030 SETCONFIG 2 DEFAULT NOPROMPT > nul

:IS1
CFG1030 SETCONFIG 1 DEFAULT NOPROMPT > nul

rem * go back to the main Toolkit drive
%TKDRV%

rem ********************************************************************************
rem *    %NM_ID%  Number of IDE RAID
rem ********************************************************************************
:CLNID

IF %NM_ID%==0 GOTO END
hypercfg /Ea /S


goto END

:ERROR
echo The necessary environment variables are not set. You must run tghe
echo HWDETECT.BAT file before you run RAIDCLN.BAT. Run HWDETECT and then
echo retry the action.

rem * go back to the main Toolkit drive in case we are sitting on %RAMDSK%
%TKDRV%

savestat.exe /set2=251 > nul

:END

