#!/bin/sh
#
#====================================================================*
# File Name   : conference
# Purpose     : This is the startup script to run the correct 
#		binary for the appropriate architecture.
# Developed by: Netscape Communications Corp.
#               (c) Copyright 1996, 1997
# 
# Revision     Change                                          Date
# --------     ------                                          ----
#   2.0        Netscape Conference Version                     11/96
#====================================================================*

case `uname` in
   SunOS )
         vers=`uname -r`
         if [ `echo "$vers" | cut -f1 -d.` -ge 5 ]; then
               mtag=sol24
         else
            mtag=sunos
         fi 
         ;;

   HP-UX )
	if [ `uname -r | cut -f2 -d.` -ge 10 ]; then
      	   mtag=hpux10;
    	else
      	   mtag=hpux;
    	fi 
        ;;

   AIX ) mtag=aix ;;

   OSF1 ) mtag=axp ;;

   IRIX ) mtag=irix ;;

   * ) 
         echo "**************************************************" >&2 ; 
         echo "* Conference Startup Error:                      *" >&2 ; 
         echo "*                                                *" >&2 ; 
         echo "* Unable to determine machine architecture.      *" >&2 ; 
         echo "**************************************************" >&2 ; 
         exit 1 ;;
esac

case "`echo 'x\c'`" in
   'x\c')  necho="echo -n"      nnl="" ;;         # BSD
   x)      necho="echo"         nnl="\c" ;;       # SYSV
   *)      necho="echo -n"      nnl="" ;;         # BSD
esac

#
# File locking for the profile library is now turned off...if file
# corruption becomes a problem, you can comment these 2 lines out and
# file locking will be used.
#
_InSoft_Profile_Locks=off
export _InSoft_Profile_Locks

#
# Figure out where we are running from - skip if COMM_HOME is set
#
if [ -z "$COMM_HOME" ]; then
   SaveDir="`pwd`"
   cd "`/bin/dirname \"$0\"`" > /dev/null 2>&1
   if [ $? -eq 0 ]; then
      if [ -d "`pwd`/plugins" ]; then
         COMM_HOME="`pwd`"
         export COMM_HOME
      else
         cd "$SaveDir"
         cd "`/bin/dirname \"$0\"`/.." > /dev/null 2>&1
         if [ $? -eq 0 ]; then
            if [ -d "`pwd`/plugins" ]; then
               COMM_HOME="`pwd`"
               export COMM_HOME
            fi
         fi
      fi
   fi
   cd "$SaveDir"
   unset SaveDir
fi

#
# If COMM_HOME not set by this point, they must set it manually
#
if [ -z "$COMM_HOME" ]
then
	echo "Could not determine where the Cooltalk application is installed."
	echo ""
	echo "To correct this, you must set the COOLTALK_HOME environment variable to the"
	echo "location where Cooltalk is installed before starting the application."
	echo ""

	basesh=`/bin/basename $SHELL`
	cmd=""
	kshcmd='export COOLTALK_HOME=/usr/cooltalk'
	bashcmd=$kshcmd
	cshcmd='setenv COOLTALK_HOME /usr/cooltalk'
	shcmd='COOLTALK_HOME=/usr/cooltalk ; export COOLTALK_HOME'
	if [ "$basesh" = "ksh" -o "$basesh" = "bash" ]; then
		cmd=$kshcmd
	elif [ "$basesh" = "csh" -o "$basesh" = "tcsh" ]; then
		cmd=$cshcmd
	elif [ "$basesh" = "sh" ]; then
		cmd=$shcmd
	fi
	if [ ! -z "$cmd" ]; then
		echo "For example, to set COOLTALK_HOME to /usr/cooltalk when using $basesh, type:"
		echo ""
		echo "$cmd"
	else
		echo "I don't recognize your shell.  Here are commands for common shells:"
		echo ""
		echo "csh : $cshcmd"
		echo "tcsh: $cshcmd"
		echo "ksh : $kshcmd"
		echo "bash: $bashcmd"
		echo "sh  : $shcmd"
	fi

	echo ""
	echo "Cooltalk startup cancelled."
	echo ""
	exit
fi

# 
# For CoolTalk, OpenDVE is ALWAYS under the CoolTalk directory
#
if [ -d "$COMM_HOME/opendve" ]; then
   OPENDVE_HOME="$COMM_HOME/opendve"
elif [ -d "$COMM_HOME/OpenDVE" ]; then
   OPENDVE_HOME="$COMM_HOME/OpenDVE"
else
   OPENDVE_HOME="$COMM_HOME/opendve"
fi

#
# Setting XAPPLRESDIR should just work, but it doesn't
# We'll use this instead.
# WARNING: This is temporary and limits our customability [is that a word?].
#
XENVIRONMENT=$COMM_HOME/lib/app-defaults/NSConference
export XENVIRONMENT

INSOFT_FIFO_PATH=/tmp/netscape/conference/sockets
export INSOFT_FIFO_PATH

#
# Set the CommuniqueSave directory
#
InSoft_Personal_Profile_Directory="~/.netscape/conference/"
export InSoft_Personal_Profile_Directory

#
# Check to see that the OpenDVE provider(s) are running
#
if [ -f "$OPENDVE_HOME/bin/$mtag/NScheckStatus" ]; then
   $OPENDVE_HOME/bin/$mtag/NScheckStatus
elif [ -f "$OPENDVE_HOME/$mtag/NScheckStatus" ]; then
   $OPENDVE_HOME/$mtag/NScheckStatus
else
   echo "Unable to locate $mtag binaries for NSconferenceEngine."
   exit
fi

AVRunning=`ps -eal | egrep NSAV`
NS_CODEC_PATH=$COMM_HOME/lib/codecs/$mtag/
export NS_CODEC_PATH

if [ -z "$AVRunning" ]; then
  CurWorkDir=`pwd`
  cd $COMM_HOME
  $COMM_HOME/plugins/NSAVEngine/$mtag/NSAVEngine&
  cd $CurWorkDir
fi


CMGR_PLUGIN=$COMM_HOME/plugins/NSConference/$mtag/NSConference

if [ -f "$CMGR_PLUGIN" ]; then
   exec  $CMGR_PLUGIN "$@"
else
   echo "Unable to locate NSConference for $mtag."
   exit
fi
