@echo off
rem ************************************************************************************
rem * Description: 	Validates a policy file based on an inventory file. 
rem *			    Generates an inventory file with the resulting RAID configuration.
rem *			    Generates a new policy file that can be use with PRAID
rem * Name: 		VALDRAID.BAT
rem * Dependencies:	VALRAID.EXE, SETERRLV.EXE, SAVERC.BAT, TKOUT.BAT
rem * Parameters:	
rem *			%1 = Input   Inventory File 	(Generated by invraid.exe)
rem *			%2 = Input   Policy File 	(Advance options available)
rem *			%3 = Output  Inventory File 	(Includes new RAID configuration)
rem *			%4 = Output  Policy File 	(Policy file supported by PRAID)
rem *			%5 = Input   RAID INI PATH 	(Directory path to RAID ini files)
rem *			%6 = Input   Log File 	        (Optional. Output file for logging)
rem *
rem * Return Code:
rem * 			0     = Success 
rem * 			>=1   = Error code define by VALRAID.exe
rem *
rem ************************************************************************************

rem ************************************************************************************
rem *** Initialize Return Code
rem ************************************************************************************
set RC=0

rem ************************************************************************************
rem *** Check Parameters
rem ************************************************************************************
if %1 == "" goto PERROR
if %2 == "" goto PERROR
if %3 == "" goto PERROR
if %4 == "" goto PERROR
if %5 == "" goto PERROR

rem ************************************************************************************
rem *** Run RAID Validation Utility
rem ************************************************************************************
SET VALOG=%6
rem Remove the quotes from parameter
SET VALOG=###%VALOG%###
SET VALOG=%VALOG:"###=%
SET VALOG=%VALOG:###"=%
SET VALOG=%VALOG:###=%

if "%VALOG%" == "" goto SCREEN
VALRAID /ini:%1 /inp:%2 /outi:%3 /outp:%4 /raid:%5 > "%VALOG%"
if errorlevel 1 goto RAIDFAIL
goto RAIDGOOD

:SCREEN
VALRAID /ini:%1 /inp:%2 /outi:%3 /outp:%4 /raid:%5
if errorlevel 1 goto RAIDFAIL
goto RAIDGOOD

:RAIDFAIL
call saverc.bat
set MSG="RAID Validation failed."
call TKOUT.BAT
goto ERROR

:RAIDGOOD
set MSG="RAID Validation succeeded."
call TKOUT.BAT
goto END

:PERROR
set MSG="Missing script parameter."
call TKOUT.BAT
SET RC=1
goto ERROR

:ERROR
set MSG="Encountered an error and stopped processing in valdraid.bat"
call TKOUT.BAT
goto END

:END
SET MSG=
SETERRLV %RC%