#!/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
	         echo "**************************************************" >&2 ; 
        	 echo "* Conference Startup Error:                      *" >&2 ; 
	         echo "*                                                *" >&2 ; 
        	 echo "* Unsupported or unknown machine architecture.   *" >&2 ; 
	         echo "**************************************************" >&2 ; 
        	 exit 1 
         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 "* Unsupported or unknown 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 Conference application is installed."
	echo ""
	echo "To correct this, you must set the COMM_HOME environment variable to the"
	echo "location where Conference is installed before starting the application."
	echo ""
	echo "Cooltalk startup cancelled."
	echo ""
	exit
fi

# 
# For Conference, OpenDVE is ALWAYS under the nsconference directory
#
OPENDVE_HOME="$COMM_HOME/OpenDVE"

#
# 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/$mtag/NScheckStatus" ]; then
   $OPENDVE_HOME/$mtag/NScheckStatus
else
   echo "Unable to locate $mtag binaries for NSconferenceEngine."
   echo "I looked in $OPENDVE_HOME/$mtag/NScheckStatus"
   exit
fi

#
# Launch the AVEngine 
# (if not already running)
#

AVRunning=`ps -eal | egrep NSAV`

if [ -z "$AVRunning" ]; then
  CurWorkDir=`pwd`
  cd $COMM_HOME
  NS_CODEC_PATH=$COMM_HOME/lib/codecs/$mtag/
  export NS_CODEC_PATH
  $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
