#!/bin/sh
# ************************************************************************************
# * Description: 	Validates a policy file based on an inventory file. 
# *			    Generates an inventory file with the resulting RAID configuration.
# *			    Generates a new policy file that can be use with PRAID
# * Name: 		valraid.sh
# * Dependencies:	valraid
# * Parameters:	
# *			$1 = Input   Inventory File 	(Generated by invraid.exe)
# *			$2 = Input   Policy File 	(Advance options available)
# *			$3 = Output  Inventory File 	(Includes new RAID configuration)
# *			$4 = Output  Policy File 	(Policy file supported by PRAID)
# *			%5 = Input   RAID INI PATH 	(Directory path to RAID ini files)
# *			%6 = Input   Log File 	        (Output file for logging)
# *
# * Return Code:
# * 			0     = Success 
# * 			>=1   = Error code define by VALRAID
# *
# ************************************************************************************

# ************************************************************************************
# *** Initialize Return Code
# ************************************************************************************
rc=0
err=1
# ************************************************************************************
# *** Check Parameters
# ************************************************************************************

if [ "$1" = "" ] ; then
	echo "ERROR: Missing Input Inventory File Parameter"
	exit $err
fi
if [ "$2" = "" ] ; then
	echo "ERROR: Missing Input Policy File Parameter"
	exit $err
fi
if [ "$3" = "" ] ; then
	echo "ERROR: Missing Output Inventory File Parameter"
	exit $err
fi
if [ "$4" = "" ] ; then
	echo "ERROR: Missing Input Inventory File"
	exit $err
fi
if [ "$5" = "" ] ; then
	echo "ERROR: Missing Input path to RAID ini files"
	exit $err
fi

# ************************************************************************************
# *** Run RAID Validation Utility
# ************************************************************************************
if [ "$6" = "" ] ; then
	valraid /ini:$1 /inp:$2 /outi:$3 /outp:$4 /raid:$5
	rc=$?
else
	valraid /ini:$1 /inp:$2 /outi:$3 /outp:$4 /raid:$5 > $6
	rc=$?
fi
#Check for error
if [ "$rc" -ne "0" ]; then
	echo "ERROR: valraid failed with rc=$rc"
	exit $rc
fi

exit $rc

