#!/bin/sh

cmd()
{
    echo "$@"
    eval '"$@"'
    [ $? -ne 0 ] && echo "CMD - error detected in '$@'" >&2 && exit 2
}

checkanswer()
{
    echo
    echo "Do you wish to continue?  (yes/no) "
    echo    
    read answer
    answer=${answer:-null}
    while [ $answer != "yes" -a $answer != "no" -a $answer != "y" -a $answer != "n" ]
    do
	echo Please answer 'yes' or 'no'.
	read answer
        answer=${answer:-null}
    done
    
    if [ $answer != "yes" -a $answer != "y" ]
    then
	echo
	echo "SANergy install was not performed."
	echo
	exit 0
    fi
}

bootnotice() 
{
    #echo "Current conditions require this uninstall script to "
    #echo "reboot the machine after completion."
    #checkanswer
    #needboot=1
    echo "Installing from a accelerated window in not allowed"
    echo "Unset the environment variable then try to install"
    exit 0
}


osnotice()
{
    echo
    echo "****************** SANergy installer *******************"
    echo
    echo "The installer detected os type "`uname`". Is this correct?"
    checkanswer
}

doregstrthing()
{
    file=$1
    x=4;
    while [ $x -gt 0 ]
    do
	if [ -f $file ]
	then
	    cp $file $2
 	    break
	fi
	x=`expr $x - 1`
	file="../"$file
    done
}

checkroot()
{
  if [ "$@" != "root" ]
  then
    echo
    echo "User "$user" you must login as root to run this script."
    echo
    exit 1
  fi
}


setupaixaio() {
    chdev -l aio0 -P $*
    if [ $? = 0 ]
    then
	echo "Changes will become effective at next system restart"
    fi
}

checkaixaio() {
    grep "Available" $@ >> /dev/null 
    if [ $? -ne 0 ]
    then
	echo "Changing aio0 from Defined to Available"
	setupaixaio -a autoconfig='available'
	echo
        echo "After the restart run the SANergy installer again."
        echo "The system will restart now to complete the AIO setup. "
        checkanswer
	reboot
    fi
}

sharedmemanswer()
{
    echo "SANergy needs to have the systems shared memory set to 4MB or higher."
    echo "Do you wish to set the shared memory now?  (yes/no) "
    echo    
    read answer
    answer=${answer:-null}
    while [ $answer != "yes" -a $answer != "no" -a $answer != "y" -a $answer != "n" ]
    do
	echo Please answer 'yes' or 'no'.
	read answer
        answer=${answer:-null}
    done
    
    if [ $answer != "yes" -a $answer != "y" ]
    then
	echo "WARNING: the shared memory will not be set"
	echo "SANergy will recieve a shared memory error at to conclusion of the installation."
    else # set shared memory and do reboot
	echo "set shmsys:shminfo_shmmax=0x400000" >> /etc/system
	echo "The shared memory has been set. The system will need to be rebooted for the changes "
	echo "to take affect.  At the conclusion of the reboot rerun the install script." 
	echo
	echo "Are you sure you want the reboot to occur now?"
	echo
	read answer
        answer=${answer:-null}
	while [ $answer != "yes" -a $answer != "no" -a $answer != "y" -a $answer != "n" ]
	do
	   echo Please answer 'yes' or 'no'.
	   read answer
           answer=${answer:-null}
	done
    
	if [ $answer != "yes" -a $answer != "y" ]
	then
	   echo "The shared memory has been set in the /etc/system file."
	   echo "The changes will not take affect until the system is rebooted."
	   echo "SANergy will recieve a shared memory error at to conclusion of the installation."
	else # set shared memory and do reboot
	   reboot
	fi
    fi
}

askNls(){
    echo
    echo "Do you want to install National Language Support for SANergy?"
    echo "Prior to answering yes, be sure that you have the Language Pack CD available?  (yes/no) "
    echo    
    read answer
    answer=${answer:-null}
    while [ $answer != "yes" -a $answer != "no" -a $answer != "y" -a $answer != "n" ]
    do
	echo Please answer 'yes' or 'no'.
	read answer
        answer=${answer:-null}
    done
    
    if [ $answer != "no" -a $answer != "n" ]
    then
	echo
	echo "Installation for SANergy CD 1 is complete."
	echo "Please insert the SANergy Language Pack CD 2 in your CD-ROM drive,then"
	echo "change to the CD directory and type ./install"
	echo
	exit 0
    fi
}

copyright(){
    echo
    echo "          Tivoli SANergy (TM)"
    echo "This software is protected by U.S. patent 5,950,203"
    echo
    echo "        5698-SFS"
    echo "  (C) Copyright IBM Corporation 1995, 2002."
    echo "	  All rights reserved."
    echo
    echo "Please refer to the license.txt file in the appropriate language directory "
    echo "under $1/nls/ for complete details."
}

# ****** start here

ostype=`uname`
needboot=0
done=0
overinstall=0
where=`pwd`
regstr="registration.txt"


if [ ! -f $where/install ] 
then    
    echo
    echo "The install script was not found in "$where"."
    echo "You must be in the directory where the install script is, to run it."
    echo
    exit 1
fi 

#osnotice
############################# IRIX ############################# 
if [ "$ostype" = "IRIX" ] || [ "$ostype" = "IRIX64" ]
then
  user=`whoami`
  checkroot $user
  homedir="/usr/SANergy"

  testenv=`env | grep _RLD_LIST`
  if [ -n "$testenv" ]
  then
	bootnotice
  fi

  if [ -f /usr/SANergy/uninstall ]
  then
    #echo
    #echo "SANergy is currently installed."
    #echo "Please run /usr/SANergy/uninstall and then run the installer again. "
    #echo
    #echo "Installation cancelled"
    #exit 1
    awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    overinstall=1
    cp /usr/SANergy/SANergyconfig.txt /tmp
    if [ -f /usr/SANergy/devices.txt ]
    then
	cp /usr/SANergy/devices.txt /tmp
    fi
    #cp /usr/SANergy/SANergykey.txt /tmp
    /usr/SANergy/uninstall
    if [ -d /usr/SANergy ]
    then 
       exit 1
    fi
  fi

  if [ -d sgi ]
  then

#    testenv=`env | grep _RLD_LIST`
#    if [ -n "$testenv" ]
#    then
#	unset _RLD_LIST
#	unset _RLDN32_LIST
#	unset _RLD64_LIST
#    fi

#    if [ `uname -r` = "6.2" ]
#    then
#	echo "6.2 install"
#	mkdir /tmp/saninstall
#	cp sgi/sanergy_irix62* /tmp/saninstall/.
#	cd /tmp/saninstall
#	tar xvf sanergy_irix62*
#	./install
#	cd /
#	rm -r /tmp/saninstall
#    else
#	cmd inst -A -f sgi/sanergy
#    fi 

    cmd inst -A -f sgi/sanergy

    done=1
    if [ $overinstall -eq 1 ]
    then	
	awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
	newversion=`cat /tmp/newfile`
	rm /tmp/newfile
	if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
	then
	    cp /tmp/SANergyconfig.txt /usr/SANergy/.
	    #cp /tmp/SANergykey.txt /usr/SANergy/.
	    if [ -f /tmp/devices.txt ]
	    then
		cp /tmp/devices.txt /usr/SANergy
	    fi
	fi
	rm /tmp/SANergyconfig.txt
	#rm /tmp/SANergykey.txt
    fi
 
    if [ ! -d $homedir/nls ]
    then
      mkdir $homedir/nls	
    fi
    
    cd $homedir/nls
    tar xf ../nls.tar
    tar xf codeset.tar
    rm -f codeset.tar
    rm -f ../nls.tar
    
    cd $where
    doregstrthing $regstr $homedir
    cd /

    if [ ! -d $homedir/lib ]
    then
      mkdir $homedir/lib
    fi
    mv -f $homedir/sancvt.so $homedir/lib/.
    mv -f $homedir/sancvt32.so $homedir/lib/.
    mv -f $homedir/sancvt64.so $homedir/lib/.

    askNls
   
    copyright $homedir
    cd /usr/SANergy  #change to our directory to create nohup.out
    nohup /etc/rc2.d/S97sanergy start >> /dev/null
    nohup /usr/SANergy/config & >> /dev/null
  else 
    echo "Could not find a sgi directory off of "$where"."
  fi

############################# AIX ############################# 
elif [ "$ostype" = "AIX" ]
then

  user=`whoami`
  checkroot $user
  homedir="/usr/SANergy"
  aixver=`lslpp -L bos.rte | grep bos.rte | awk '{ print $2;}'`
  majorver=`echo $aixver | awk -F. '{ print $1;}'`
  testenv=`env | grep LIBPATH | grep /usr/SANergy`
  if [ -n "$testenv" ]
  then
	bootnotice
  fi

  if [ -f /usr/SANergy/uninstall ]
  then
    #echo
    #echo "SANergy is currently installed."
    #echo "Please run /usr/SANergy/uninstall and then run the installer again. "
    #echo
    #echo "Installation cancelled"
    #exit 1
    overinstall=1
    awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    cp /usr/SANergy/SANergyconfig.txt /tmp
    if [ -f /usr/SANergy/devices.txt ]
    then
	cp /usr/SANergy/devices.txt /tmp
    fi
    #cp /usr/SANergy/SANergykey.txt /tmp
    /usr/SANergy/uninstall
    if [ -d /usr/SANergy ]
    then 
       exit 1
    fi
    
  fi

  langsave=$LANG
  LANG=C
  tempfile=/tmp/tempclw 
  cmd echo "Checking systems AIO device... "
  cmd lsdev -C -c aio > $tempfile
  checkaixaio $tempfile
  unlink $tempfile
  cmd echo "Check complete."
  LANG=$langsave

  if [ -d aix ]
  then
   # testenv=`env | grep LIBPATH`
   # if [ -n "$testenv" ]
   # then
   #	unset LIBPATH
   # fi
    mkdir /tmp/saninstall
    cp aix/sanergy_aix$majorver* /tmp/saninstall/.
    cd /tmp/saninstall
    cmd installp -acgNQqwX -d /tmp/saninstall sanergy.rte
    cd /
    rm -r /tmp/saninstall
    done=1
    if [ $overinstall -eq 1 ]
    then	
	awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
	newversion=`cat /tmp/newfile`
	rm /tmp/newfile
	if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
	then
	    cp /tmp/SANergyconfig.txt /usr/SANergy/.
	    #cp /tmp/SANergykey.txt /usr/SANergy/.
	    if [ -f /tmp/devices.txt ]
	    then
		cp /tmp/devices.txt /usr/SANergy
	    fi
	fi
	rm /tmp/SANergyconfig.txt
	#rm /tmp/SANergykey.txt
    fi

    cd $homedir/nls 
    tar xf ../nls.tar
    tar xf codeset.tar
    rm -f codeset.tar
    cd ..
    rm -f nls.tar
    
    cd $where
    doregstrthing $regstr $homedir
    cd /

    if [ ! -d $homedir/lib ]
    then
      mkdir $homedir/lib
    fi
    
    if [ $majorver -gt 4 ]
    then
	chgrp staff /usr/SANergy/libc*.a
    fi

    askNls
   
    cd /usr/SANergy    #change to our directory to create nohup.out
    nohup /etc/rc.sanergy start >> /dev/null
    nohup /usr/SANergy/config & >> /dev/null
    echo "Starting /usr/SANergy/config ..."
  else 
    echo "Could not find a aix directory off of "$where"."
  fi

############################# SUN ############################# 
elif [ "$ostype" = "SunOS" ]
then

  user=`/usr/ucb/whoami`
  checkroot $user
  homedir="/opt/SANergy"
  OS_REV=`uname -r`

  testenv=`env | grep LD_PRELOAD`
  if [ -n "$testenv" ]
  then
    bootnotice
  fi

  #check the system shared memory
  shline=`grep -v "^*" /etc/system | grep "shminfo_shmmax"`
  if [ $? -eq 0 ] # check return status of grep command
  then
     #shared memory exists use awk to get the size
     size=`echo $shline | awk '{ FS = "="
	size = $2
	print size
     }'`
     echo $size | grep x #determine if size is in hex or not
     if [ $? -eq 0 ]
     then 
        size=`echo $size | awk '{ FS = "x"
	   size = $2
	   print size
	}'`
        if [ $size -ne ffffffffffff -a $size -lt 400000 ] 
        then
           echo "The shared memory is currently set to 0x$size but needs to be at least 0x400000."
           echo "edit the /etc/system file to read: set shmsys:shminfo_shmmax=0x400000"
	   echo "The system will need to be rebooted for the changes to take affect."
        fi  
     else
        if [ $size -lt 4194304 ]
        then
           echo "The shared memory is currently set to $size but needs to be at least 4MB."
           echo "edit the /etc/system file and set your system shared memory to 4MB."
	   echo "The system will need to be rebooted for the changes to take affect."
        fi
     fi    
  else # shminfo_shmmax is not set so lets do it now
    sharedmemanswer
  fi 

  if [ -f /opt/SANergy/uninstall ]
  then
    #echo
    #echo "SANergy is currently installed."
    #echo "Please run /opt/SANergy/uninstall and then run the installer again. "
    #echo
    #echo "Installation cancelled"
    #exit 1
    overinstall=1
    awk -F. '{ print $1 }' /opt/SANergy/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    cp /opt/SANergy/SANergyconfig.txt /tmp
    if [ -f /opt/SANergy/devices.txt ]
    then
	cp /opt/SANergy/devices.txt /tmp
    fi
    #cp /opt/SANergy/SANergykey.txt /tmp
    /opt/SANergy/uninstall
    if [ -d /opt/SANergy ]
    then 
       exit 1
    fi
     
  fi

  if [ -d solaris ]
  then
    #testenv=`env | grep LD_PRELOAD`
    #if [ -n "$testenv" ]
    #then
    #    unset LD_PRELOAD
    #fi
    if [ "$OS_REV" = "5.6" ]
    then
      cmd pkgadd -d solaris/sanergy_sol$OS_REV*
    elif [ "$OS_REV" = "5.8" ]
    then
      cmd pkgadd -d solaris/sanergy_sol$OS_REV*
    elif [ "$OS_REV" = "5.9" ]
    then
      cmd pkgadd -d solaris/sanergy_sol$OS_REV*
    else
      cmd pkgadd -d solaris/sanergy_sol5.7*     
    fi
    done=1
    if [ $overinstall -eq 1 ]
    then	
	awk -F. '{ print $1 }' /opt/SANergy/version.txt > /tmp/newfile
	newversion=`cat /tmp/newfile` 
	rm /tmp/newfile
	if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
	then
	    cp /tmp/SANergyconfig.txt /opt/SANergy/.
	    if [ -f /tmp/devices.txt ]
	    then
		cp /tmp/devices.txt /opt/SANergy
	    fi
	    #cp /tmp/SANergykey.txt /opt/SANergy/.
	fi
	rm /tmp/SANergyconfig.txt
	#rm /tmp/SANergykey.txt
    fi

    cd $homedir
    cd nls 
    
    tar xf ../nls.tar
    chmod 644 C/*
    chown -f root C/*
    chgrp -f sys C/*
    tar xf codeset.tar
    chmod 644 codeset/*
    chown -f root codeset/*
    chgrp -f sys codeset/*
    rm -f codeset.tar
    cd ..
    rm -f nls.tar

    cd $where
    doregstrthing $regstr $homedir
    cd /
  
    ### added link to LSCqfs library ###
    if [ -f /opt/SUNWsamfs/lib/libsamsanergy.so ]
    then
	ln -s /opt/SUNWsamfs/lib/libsamsanergy.so /opt/SANergy/lib/libsamsanergy.so
    elif [ -f /opt/LSCsamfs/lib/libsamsanergy.so ]
    then
	ln -s /opt/LSCsamfs/lib/libsamsanergy.so /opt/SANergy/lib/libsamsanergy.so
	#ln -s /opt/LSCsamfs/lib/sancvt.o  /opt/SANergy/lib/sancvt.o
	#ln -s /opt/LSCsamfs/lib/sparcv9/sancvt.o  /opt/SANergy/lib/sparcv9/sancvt.o
    fi

    askNls

    copyright $homedir
    cd /opt/SANergy  #change to our directory to create nohup.out
    nohup /etc/rc2.d/S97sanergysun start >> /dev/null
    nohup /opt/SANergy/config & >> /dev/null
    echo "Starting /opt/SANergy/config ..."
  else 
    echo "Could not find a solaris directory off of "$where"."
  fi

############################# TRU64 ############################# 
elif [ $ostype = "OSF1" ] 
then

  osrev=`uname -r`
  majorrev=`echo $osrev | sed 's/\..*//g'`  # something like V4 or V5

  user=`whoami`
  checkroot $user
  homedir="/usr/SANergy"

  testenv=`env | grep _RLD_LIST`
  if [ -n "$testenv" ]
  then
      bootnotice
  fi

  if [ -f /usr/SANergy/uninstall ]
  then
    #echo
    #echo "SANergy is currently installed."
    #echo "Please run /usr/SANergy/uninstall and then run the installer again. "
    #echo
    #echo "Installation cancelled"
    #exit 1
    overinstall=1
    awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    cp /usr/SANergy/SANergyconfig.txt /tmp
    if [ -f /usr/SANergy/devices.txt ]
    then
	cp /usr/SANergy/devices.txt /tmp
    fi
    #cp /usr/SANergy/SANergykey.txt /tmp
    /usr/SANergy/uninstall
    if [ -d /usr/SANergy ]
    then 
       exit 1
    fi
  fi

  if [ -d tru64 ]
  then
   # testenv=`env | grep _RLD_LIST`
   # if [ -n "$testenv" ]
   # then
   #	unset _RLD_LIST
   # fi
    mkdir /tmp/saninstall
    cp tru64/sanergy_tru64$majorrev* /tmp/saninstall/.
    cd /tmp/saninstall
    tar xf sanergy*.tar
    setld -l . SFSSFS*
    cd /
    rm -r /tmp/saninstall
    done=1
    if [ $overinstall -eq 1 ]
    then	
	awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
	newversion=`cat /tmp/newfile`
	rm /tmp/newfile
	if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
	then
	    cp /tmp/SANergyconfig.txt /usr/SANergy/.
	    if [ -f /tmp/devices.txt ]
	    then
		cp /tmp/devices.txt /usr/SANergy
	    fi
	    #cp /tmp/SANergykey.txt /usr/SANergy/.
	fi
	rm /tmp/SANergyconfig.txt
	#rm /tmp/SANergykey.txt
    fi

    if [ ! -d $homedir/nls ]
    then
      mkdir $homedir/nls	
    fi
      
    cd $homedir/nls
    tar xf ../nls.tar
    tar xf codeset.tar
    rm -f codeset.tar
    rm -f ../nls.tar
    
    cd $where
    doregstrthing $regstr $homedir
    cd /

    #if [ ! -d $homedir/lib ]
    #then
    #  mkdir $homedir/lib
    #fi
    #mv -f $homedir/sancvt.so $homedir/lib/sancvt.so

    askNls

    copyright $homedir
    cd /usr/SANergy  #change to our directory to create nohup.out
    nohup /sbin/init.d/sanergy start >> /dev/null
    nohup /usr/SANergy/config & >> /dev/null
    echo "Starting /usr/SANergy/config ..."

  else 
    echo "Could not find a tru64 directory off of "$where"."
  fi

############################# DGUX  ############################# 
elif [ "$ostype" = "dgux" ]
then

  user=`whoami`
  checkroot $user
  homedir="/usr/opt/SANergy"
  
  testenv=`env | grep LD_PRELOAD`
  if [ -n "$testenv" ]
  then
      bootnotice
  fi

  if [ -f $homedir/uninstall ]
  then
    #echo
    #echo "SANergy is currently installed."
    #echo "Please run /usr/SANergy/uninstall and then run the installer again. "
    #echo
    #echo "Installation cancelled"
    #exit 1
    overinstall=1
    awk -F. '{ print $1 }' $homedir/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    cp $homedir/SANergyconfig.txt /tmp
    if [ -f $homedir/devices.txt ]
    then
	cp $homedir/devices.txt /tmp
    fi
    #cp $homedir/SANergykey.txt /tmp
    $homedir/uninstall
    if [ -d $homedir ]
    then 
       exit 1
    fi
  fi

  if [ -d dgux ]
  then
    #testenv=`env | grep LD_PRELOAD`
    #if [ -n "$testenv" ]
    #then
    #    unset LD_PRELOAD
    #fi
    echo "DGUX install"
    if [ ! -d $homedir ]
    then
      mkdir $homedir
    fi

    mkdir /tmp/saninstall
    cp dgux/sanergy_dgux* /tmp/saninstall/.
    cd /tmp/saninstall
    tar xf sanergy_dgux*
    ./install
    cd /
    rm -r /tmp/saninstall
    done=1
    if [ $overinstall -eq 1 ]
    then	
	awk -F. '{ print $1 }' /usr/opt/SANergy/version.txt > /tmp/newfile
	newversion=`cat /tmp/newfile`
	rm /tmp/newfile
	if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
	then
	    cp /tmp/SANergyconfig.txt $homedir/.
	    if [ -f /tmp/devices.txt ]
	    then
		cp /tmp/devices.txt $homedir/.
	    fi
	    #cp /tmp/SANergykey.txt $homedir/.
	fi
	rm /tmp/SANergyconfig.txt
	#rm /tmp/SANergykey.txt
    fi
    
    if [ ! -d $homedir/nls ]
    then
      mkdir $homedir/nls	
    fi
  
    cd $homedir/nls 
    tar xf ../nls.tar
    tar xf codeset.tar
    rm -f codeset.tar
    cd ..
    rm -f nls.tar
     
    cd $where
    doregstrthing $regstr $homedir
    cd /

    if [ ! -d $homedir/lib ]
    then
      mkdir $homedir/lib
    fi
    mv -f $homedir/sancvt.so $homedir/lib/.
    
    askNls

    copyright $homedir
    cd /usr/SANergy  #change to our directory to create nohup.out
    nohup /etc/rc3.d/S355.sanergy start >> /dev/null
    #/usr/SANergy/config & >> /dev/null
    #echo "Starting /usr/SANergy/config ..."

  else 
    echo "Could not find a dgux directory off of "$where"."
  fi

############################# Linux  ############################# 
elif [ "$ostype" = "Linux" ]
then

  user=`whoami`
  checkroot $user
  homedir="/usr/SANergy"
  kernelRev=`uname -r`
  linuxDir="linux"
  installmdc=1  

  # need to check for smp 
  SMP=0
  if [ `uname -v | awk '{ print $2;}'` = "SMP" ] 
  then
     SMP=1
  fi

  testenv=`env | grep LD_PRELOAD`
  if [ -n "$testenv" ]
  then
    bootnotice
  fi

  # need to determine if the linux kernel is supported before we do anything
  # print error message and exit if we do not support the kernel 
  cd $linuxDir  # switch to the linux directory

  for DIR in san_lin*.tar
  do 
    temp=`echo $DIR | sed 's/^san_lin//' | sed 's/_3.*.*$//'`
    kernelList="$kernelList $temp"
  done

  echo $kernelList | egrep -wq $kernelRev
  if [ $? -ne 0 ]
  then 
    echo "The SANergy MDC will not be installed.  This kernel is not supported."
    echo "Only the client will be installed."
    checkanswer
    installmdc=0
  fi

  cd ../       # switch back out of the linux directory

  if [ -f /usr/SANergy/uninstall ]
  then
    overinstall=1
    awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    cp /usr/SANergy/SANergyconfig.txt /tmp
    if [ -f /usr/SANergy/devices.txt ]
    then
	cp /usr/SANergy/devices.txt /tmp
    fi
    #cp /usr/SANergy/SANergykey.txt /tmp
    /usr/SANergy/uninstall
    if [ -d /usr/SANergy ]
    then 
      exit 1
    fi
  fi

  if [ -d $linuxDir ]
  then

    echo "Linux install"

    if [ ! -d /usr/SANergy ] 
    then
	mkdir -p /usr/SANergy
    fi
    if [ ! -d /usr/SANergy/lib ] 
    then
	mkdir -p /usr/SANergy/lib
    fi

    echo "installing files"

    if [ -d /etc/init.d ]
    then
      INIT_DIR=/etc/init.d
    else
      INIT_DIR=/etc/rc.d/init.d
    fi

    if [ $installmdc -eq 1 ]
    then
      cp $linuxDir/"san_lin"$kernelRev"_"*.tar /usr/SANergy
      cd /usr/SANergy
      tar xf "san_lin"$kernelRev"_"*.tar
    
      mv -f libSANergy.so /lib
      mv -f libext2mdc.so /usr/SANergy/lib
      mv -f sancvt.so /usr/SANergy/lib/.
      LINUXVER=`uname -r` 
      mkdir -p /lib/modules/$LINUXVER/misc
      if [ $SMP -eq 1 ] 
      then
        echo "moving sanergysmp.o to /lib/modules/$LINUXVER/misc/"
        mv -f sanergysmp.o /lib/modules/$LINUXVER/misc/sanergy.o
      else
        mv -f sanergy.o /lib/modules/$LINUXVER/misc/sanergy.o
      fi

      mv -f sanergylinux $INIT_DIR
      ln -sf $INIT_DIR/sanergylinux /etc/rc.d/rc5.d/S87sanergy
      rm -f "san_lin"$kernelRev"_"*.tar
    else
      cp $linuxDir/"san_lin"*.tar /usr/SANergy
      cd /usr/SANergy
      tar xf "san_lin"*.tar
    
      mv -f libSANergy.so /lib
      mv -f libext2mdc.so /usr/SANergy/lib
      mv -f sancvt.so /usr/SANergy/lib/.

      mv -f sanergylinuxnomdc $INIT_DIR
      ln -sf $INIT_DIR/sanergylinuxnomdc /etc/rc.d/rc5.d/S87sanergy
      rm -f "san_lin"*.tar
    fi

    done=1
    if [ $overinstall -eq 1 ]
    then	
      awk -F. '{ print $1 }' /usr/SANergy/version.txt > /tmp/newfile
      newversion=`cat /tmp/newfile`
      rm /tmp/newfile
      if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
      then
	cp /tmp/SANergyconfig.txt /usr/SANergy/.
	if [ -f /tmp/devices.txt ]
	then
          cp /tmp/devices.txt /usr/SANergy
	fi
	#cp /tmp/SANergykey.txt /usr/SANergy/.
      fi
      rm /tmp/SANergyconfig.txt
      #rm /tmp/SANergykey.txt
    fi


    cd $homedir
    mkdir nls
    cd nls 
    tar xf ../nls.tar
    tar xf codeset.tar
    rm -f codeset.tar
    cd ..
    rm -f nls.tar


    cd $where
    doregstrthing $regstr $homedir
    cd /

    askNls    

    copyright $homedir
    cd /usr/SANergy  #change to our directory to create nohup.out
    nohup /etc/rc.d/rc5.d/S87sanergy start >> /dev/null
    nohup /usr/SANergy/config & >> /dev/null
    echo "Starting /usr/SANergy/config ..."

  else 
    echo "Could not find a linux directory off of "$where" that matches kernel "$kernelRev"."
  fi


############################# HP-UX  ############################# 
elif [ "$ostype" = "HP-UX" ]
then

  user=`whoami`
  checkroot $user
  homedir="/opt/SANergy"
  
  testenv=`env | grep LD_PRELOAD`
  if [ -n "$testenv" ]
  then
      bootnotice
  fi

  if [ -f /opt/SANergy/uninstall ]
  then
    #echo
    #echo "SANergy is currently installed."
    #echo "Please run /opt/SANergy/uninstall and then run the installer again. "
    #echo
    #echo "Installation cancelled"
    #exit 1
    overinstall=1
    awk -F. '{ print $1 }' $homedir/version.txt > /tmp/newfile
    oldversion=`cat /tmp/newfile`
    rm /tmp/newfile
    cp $homedir/SANergyconfig.txt /tmp
    if [ -f $homedir/devices.txt ]
    then
	cp $homedir/devices.txt /tmp
    fi
    #cp $homedir/SANergykey.txt /tmp
    $homedir/uninstall
    if [ -d $homedir ]
    then 
       exit 1
    fi
  fi

  if [ -d hpux ]
  then
    #testenv=`env | grep LD_PRELOAD`
    #if [ -n "$testenv" ]
    #then
    #    unset LD_PRELOAD
    #fi
    echo "HPUX install"

    if [ ! -d $homedir ] 
    then
	mkdir -p $homedir
    fi
    if [ ! -d $homedir/lib ] 
    then
	mkdir -p $homedir/lib
    fi

    cp hpux/sanergy_hpux* $homedir/.
    cd $homedir
    tar xf sanergy_hpux*

    mv -f sanergyconfhpux /etc/rc.config.d/sanergyconf
    mv -f *.so /usr/lib/.
    mv -f sanergyhpux /sbin/init.d
    ln -s /sbin/init.d/sanergyhpux /sbin/rc2.d/S880sanergy

    done=1

    if [ $overinstall -eq 1 ]
    then	
	awk -F. '{ print $1 }' $homedir/version.txt > /tmp/newfile
	newversion=`cat /tmp/newfile`
	rm /tmp/newfile
	if [ $newversion -ge 2 -o $newversion -eq $oldversion ]
	then
	    cp /tmp/SANergyconfig.txt $homedir/.
	    if [ -f /tmp/devices.txt ]
	    then
		cp /tmp/devices.txt $homedir/.
	    fi
	    #cp /tmp/SANergykey.txt $homedir/.
	fi
	rm /tmp/SANergyconfig.txt
	#rm /tmp/SANergykey.txt
    fi
    
    if [ ! -d $homedir/nls ]
    then
      mkdir $homedir/nls	
    fi
  
    cd $homedir/nls 
    tar xf ../nls.tar
    tar xf codeset.tar
    rm -f codeset.tar
    cd ..
    rm -f nls.tar
     
    cd $where
    doregstrthing $regstr $homedir
    cd /

    if [ ! -d $homedir/lib ]
    then
      mkdir $homedir/lib
    fi
    if [ -f $homedir/sancvt.so ]
    then
      mv -f $homedir/sancvt.so $homedir/lib/.
    fi
    
    askNls

    copyright $homedir
    cd /opt/SANergy  #change to our directory to create nohup.out
    nohup /sbin/rc2.d/S880sanergy start >> /dev/null
    nohup /opt/SANergy/config & >> /dev/null
    echo "Starting /opt/SANergy/config ..."

  else 
    echo "Could not find a hpux directory off of "$where"."
  fi

else
    echo $ostype" unsupported"
    exit 1
fi

if [ $done = 1 ]
then
    echo 
    echo "Refer to the users guide for further installation instructions. "
    echo
    echo "SANergy file installation complete."
    echo
    if [ $needboot = 1 ] 
    then
      echo "The system will now restart"
      checkanswer
    fi 
fi
