#!/bin/bash
#*****************************************************************************
# Copyright 2004-2007 LSI Logic Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation,  version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#*****************************************************************************
#  
#  Script:		hbaCheck
#  Instance:		1
#  %version:		3 %
#  Description:		
#  %created_by:		sdachepa %
#  %date_created:	Mon Feb 04 18:17:17 2008 %

if [ "$#" -gt "0" ]
then
    MPP_RAMDISK_KERNEL_VERSION="$1"
else
    MPP_RAMDISK_KERNEL_VERSION=""
fi

if [ -f /opt/mpp/mppMkInitrdHelper ]
then
	. /opt/mpp/mppMkInitrdHelper;
else
	. utility/mppMkInitrd
fi

# Begin of the script
# we may need to modify the following function to do automatic connection detection
# This function asks the user the question passed to it.
hbaConfigWarning()
{
# This empty echo sign is just for the binary rpm installation of MPP in which this
# function becomes an empty function and hence gives an error during installation.
    echo "" > /dev/null
#NIGEB OINEGNE CIGAM ENIL#
    echo $1
    echo -n "Do you want to continue (yes or no) ? "
    read answer
    if [ $answer != y ] && [ $answer != yes ] &&  [ $answer != Y ] && [ $answer != YES ] 
    then

	if [ -f /tmp/checkResultFile.mpp ]
	then
		rm /tmp/checkResultFile.mpp
	fi
	if [ -f /tmp/ModuleListFile.mpp ]

	then
		rm /tmp/ModuleListFile.mpp
	fi

	exit 1;
    fi 
#DNE OINEGNE CIGAM ENIL#
}

#Execution starts here

checkHBAConfig;
result=`cat /tmp/checkResultFile.mpp`;

if [ $result = 2 ] 
then
    echo "Please make sure that only supported models of HBA are connected to Storage Array."
    if [ -f /tmp/checkResultFile.mpp ]
    then
        rm /tmp/checkResultFile.mpp
    fi
    if [ -f /tmp/ModuleListFile.mpp ]
    then
        rm /tmp/ModuleListFile.mpp
    fi
    exit 1;
fi


if [ -z "${MPP_RAMDISK_KERNEL_VERSION}" ]
then
    ModuleNameCheck
else
    ModuleNameCheck ${MPP_RAMDISK_KERNEL_VERSION}
fi

if [ $result = 3 ] 
then
    hbaConfigWarning "iSCSI software initiator found. Do you want MPP to manage an iSCSI storage array?"
fi

#Now we know that we have the right HBA driver
#continue to modify configuration files
echo "Please wait while we modify the system configuration files.";