#!/bin/sh

PID=$$
TMP_FILE=/tmp/ntap_san_inst_$PID
HBA_LIB=/usr/lib/libqlsdm.so
INS_DIR=/opt/sanlun
INS_BIN_DIR=/opt/sanlun/bin
DATE=`date +%Y%m%d_%H%M`

# Ensure the user is running as root
USER=`/usr/bin/whoami`

if [ "$USER" != "root" ]
then
        echo
        echo This install program must be run as root.
        echo
        exit 1
fi

# See if the Qlogic driver is installed.  Just inform them if it isn't
# installed.  Maybe it would be better to halt the install?
/sbin/lsmod > $TMP_FILE
/bin/grep -iqs qla2300 $TMP_FILE 
ret=$?
if [ $ret -ne 0 ] ; then
	echo "WARNING:  Qlogic qla2300 driver is not installed"
fi;

rm $TMP_FILE 

# See if the HBA API library is installed.  Should I halt this install
# if the HBA API library isn't present?
if [ ! -f $HBA_LIB ] ; then
	echo "WARNING:  Qlogic HBA API library $HBA_LIB is not installed"
	echo "$HBA_LIB is required by sanlun.  Please install the library"
	
fi;

# See if there is already a sanlun installed 
if [ -d $INS_DIR ] ; then
	# There is an /opt/sanlun dir present move it aside
	echo "$INS_DIR exists, moving to $INS_DIR$DATE"
	/bin/mv $INS_DIR $INS_DIR$DATE
fi;

# create /opt/sanlun/bin and install the stuff
/bin/mkdir -p $INS_BIN_DIR

# put all the stuff there
here=`pwd`
cd /; tar -xvf $here/sanlun_bin.tar

# make a link in /usr/sbin to sanlun
ln -s /opt/sanlun/bin/sanlun /usr/sbin/sanlun

exit 0;
