#!/bin/sh 
###############################################################################
# Copyright 1997-2000 by mental images GmbH & Co.KG, Fasanenstr. 81, D-10623
# Berlin, Germany. All rights reserved.
#
# installation tool interface
#
# $Id: rayinstall,v 1.12 2000/06/19 09:36:18 runa Exp $
#
###############################################################################

usage()
{
echo "usage:  rayinstall [ -sduh ]"
echo "	-h help"
echo "	-s silent installation"
echo "	-d default installation"
echo "	-u deinstall"
echo 
echo "full installation"
echo "includes installation of mental ray, the License Server"
echo "and license setup."
echo
echo "install mental ray"
echo "mental ray can be installed from only one host across the network."
echo "If you observe problems with the remote installation please install"
echo "mental ray on each machine locally."
echo 
echo "install License Server"
echo "installation of the License Server Software SPM"
echo "If you own floating licenses the installation has to be performed on the"
echo "license server machine only. Choose a fast and stable server in your network."
echo "For nodelocked licenses the license server has to be installed on any machine"
echo "where you want to run mental ray"
echo
echo "license management"
echo "creation of license request, installation of validation codes"
echo "and list already installed licenses."


exit 0
}

# parsing command line options
set -- `getopt sdhu $@`
[ $? != 0 ] && usage

while :
do 
	case $1 in 
        -s) miSilent=1; miOptions="$miOptions -s";;
        -d) miCustom=0; miOptions="$miOptions -d";;
	-u) miDeinst=1; miOptions="$miOptions -u";;
	-h) usage;;
        --) break;;
	esac
	shift
done

ROOT=`dirname $0`;export ROOT
TOP=${ROOT};export TOP
INSTFROM=${ROOT}/install;export INSTFROM
miExt=`${INSTFROM}/mi_checkos`
[ $miExt = none ] &&
	{
	echo "This platform ist not supported"
	exit
	}
SPMDIR=/var/spm;export SPMDIR
[ x$INSTDIR = 'x' ] && INSTDIR=/usr/local/mi;export INSTDIR
SPMFROM=${ROOT}/${miExt}/spm;export SPMFROM
RAYFROM=${ROOT}/${miExt}/bin;export RAYFROM
INCFROM=${ROOT}/common/include;export INCFROM
SHADFROM=${ROOT}/${miExt}/shaders;export SHADFROM
LOG=/tmp/rayinstall.log
PATH=/bin:.
OS=`uname`
[ $OS = 'OSF1' ] && PATH=$PATH:/sbin
[ $OS = 'SunOS' ] && PATH=$PATH:/usr/ucb
[ $OS = 'HP-UX' ] && PATH=$PATH:/usr/bin:/usr/sbin
[ $OS = 'IRIX' -o $OS = 'IRIX64' ] && PATH=$PATH:/usr/sbin:/usr/bsd
[ $OS = 'Linux' ] && PATH=$PATH:/bin:/usr/bin
HOST=`hostname`


# Initialization
miCustom=${miCustom:-1};export miCustom
miSpm=${miSpm:-0};export miSpm
miSilent=${miSilent:-0}; export miSilent
miRecover=${miRecover:-0};export miRecover
miDeinst=${miDeinst:-0};export miDeinst
miInst=1
miConfig=/tmp/mi-config
miLic=SPM
[ -f ${SPMFROM}/spmd.relay ] &&  
	miLic='SPM Relay Daemon'

# determine what to install
what_to_install()
{
echo
echo choose what you want to install[1]:
echo 1 full installation \(contains 2,3 and 4\)
echo 2 install mental ray
echo 3 install License Server $miLic
echo 4 licenses
echo 5 deinstallation
echo 6 get help
echo 7 quit
read tmp
miInst=${tmp:-1}

case $miInst in 
	1) ;; 
	2) ${ROOT}/install/mi_install_ray $miOptions ;;
	3) ${ROOT}/install/mi_install_spm $miOptions;;
	4) if [ -f ${ROOT}/install/mi_install_licenses ] ;then
 	   	${ROOT}/install/mi_install_licenses $miOptions
	   else
	   	echo '*** FLEXlm licenses are provided by Softimage ***'
	   fi;;
	5) ;;
	6) usage;;
	7) exit 0;;
	q) exit 0;;
esac
}

#############################################################################
# install main
#############################################################################

#comment it out to get a logfile
#if [ x$callmyself = x ] ;then
#	echo " **** Installation of mental ray `date` **** " >> $LOG
#	callmyself=1 ${ROOT}/rayinstall $miOptions | tee $LOG 
#	exit 0 
#fi

echo "************************************************************"
echo "               MENTAL RAY INSTALLATION                      "
echo "************************************************************"

echo
echo "NOTICE: Configuration settings will be saved in ${miConfig}."
echo

while :
do
	if [ $miDeinst = 1 -o $miInst = 5 ]; then
    		${ROOT}/install/mi_install_ray -u
    		[ $? != 0 ] && exit 1
 		${ROOT}/install/mi_install_spm -u 
 		[ $? != 0 ] && exit 1
		rm -rf $miConfig
		echo 
		echo "*** Deinstallation completed ***"
		exit 0
	fi
	[ $miCustom = 1 ] && what_to_install
	if [ $miInst = 1 ];then
		${ROOT}/install/mi_install_ray $miOptions
		[ $? != 0 ] && exit 1
		${ROOT}/install/mi_install_spm $miOptions 
		[ $? != 0 ] && exit 1
		if [ -f ${ROOT}/install/mi_install_licenses ]; then
			${ROOT}/install/mi_install_licenses -d $miOptions
		else
			echo '*** FLEXlm licenses are provided by Softimage ***'
		fi
		echo
		echo "*** Installation successfully completed ***"
		exit 0
	fi
done
