#!/bin/sh

PID=$$
TMP_FILE=/tmp/netapp_san_inst_$PID
INS_DIR=/opt/netapp
INS_BIN_DIR=/opt/netapp/santools
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 there is already a sanlun installed 
if [ -d $INS_DIR ] ; then
	# There is an /opt/netapp/santools dir present move it aside
	echo "$INS_DIR exists, moving to $INS_DIR$DATE"
	/bin/mv $INS_DIR $INS_DIR$DATE
fi;

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

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

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

OS_RELEASE=`lsb_release -r -s`;

#Install the ontap prio callout only if it is not bundled with the kernel
if [ ! -f /sbin/mpath_prio_ontap ]; then
        if [ "$OS_RELEASE" = "5.1" ]; then
              #For RHEL 5.1 alone, install the mpath_prio_ontap.static
              chmod -f 755 /opt/netapp/santools/mpath_prio_ontap.static
              chown -f root:root /opt/netapp/santools/mpath_prio_ontap.static
              echo "Moving /opt/netapp/santools/mpath_prio_ontap to /sbin"
              mv /opt/netapp/santools/mpath_prio_ontap.static /sbin/
              ln -s /sbin/mpath_prio_ontap.static /sbin/mpath_prio_ontap
        else
              #For all others OSs, install the mpath_prio_ontap
              # move the Netapp prio patch to /sbin
              chmod -f 755 /opt/netapp/santools/mpath_prio_ontap
              chown -f root:root /opt/netapp/santools/mpath_prio_ontap
              echo "Moving /opt/netapp/santools/mpath_prio_ontap to /sbin"
              mv /opt/netapp/santools/mpath_prio_ontap /sbin/
        fi
fi

exit 0;
