#!/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.11 2000/03/23 15:37:35 runa Exp $
#
###############################################################################

usage()
{
echo "usage:  rayinstall [ -sduh ]"
echo "	-h help"
echo "	-s silent installation"
echo "	-d default installation"
echo "	-u deinstall"
#echo "	-r recover configuration from file (not implemented yet)"
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


# determine what to install
what_to_install()
{
echo
echo choose what you want to install[1]:
echo 1 full installation 
echo 2 install mental ray
echo 3 install license server  
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
