#!/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`
STANDARD_MAN_PATH=/usr/share/man/man1

# 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 > /dev/null 2>&1

OS_RELEASE=`lsb_release -r -s`;

# Now link the man pages into /usr/shared/man/man1 directory so that the man
# pages can be opened from anywhere.
ln -s /opt/netapp/man/man1/* $STANDARD_MAN_PATH > /dev/null 2>&1

exit 0;
