#!/bin/sh
#			Copyright (c) 1993 by
#			Advanced Visual Systems Inc.
#			All Rights Reserved
#	
#	This software comprises unpublished confidential information of
#	Advanced Visual Systems Inc. and may not be used, copied or made
#	available to anyone, except in accordance with the license
#	under which it is furnished.
#	
#	This file is under Perforce control
#	$Id: //depot/express/fcs70/build/xp_start.sh#1 $
#	
#
# This shell script is executed by AVS/Express when it needs to start
# a process that has a "host_name" property set on it.
#
# This script should: 
#    * pass through the environment variables below to the process it starts
#    * honor the -host option which specifies the value of the
#      host_name property set on the process to be started
#    * honor the -path option which is used to override the directory
#      path on the remote machine
# 
# Since AVS/Express looks for this script in the project path, this script
# can be overridden by the user.
# 

ENV_STRING="OM_BOSS=\"$OM_BOSS\" OM_BOSS_2=\"$OM_BOSS_2\""
ENV_STRING="$ENV_STRING OM_ROOT_OBJ=$OM_ROOT_OBJ"
ENV_STRING="$ENV_STRING OM_PROC_OBJ=$OM_PROC_OBJ"
ENV_STRING="$ENV_STRING OM_INIT_STACK_LEVEL=$OM_INIT_STACK_LEVEL"

HOSTNAME="<unset>"
ARGS=""

while [ $# -gt 0 ] ; do
  case $1 in
    -host)      HOSTNAME=$2
                shift
		;;
    -path)	XP_PATH=$2
		shift
		;;
    *)          ARGS="$ARGS $1"
		;;
  esac
  shift
done

#
# cheesy hack to get last path entry
# we are only looking for the xp_exec script in the last path
# to avoid having to make multiple trips to the remote process.
# if a user needs to customize that script, they will have to
# customize this one as well.
#
for last_path in $XP_PATH ; do
  :
done

if [ "$HOSTNAME" = "<unset>" ] ; then
   $ARGS
else 
   if [ "$XP_RSH" = "" ] ; then
      if [ -x /usr/bin/remsh ] ; then
	 XP_RSH="/usr/bin/remsh"
      else
	 XP_RSH="rsh"
      fi
   fi

   if $XP_RSH $HOSTNAME \
          "env $ENV_STRING $last_path/bin/xp_exec $ARGS -path \"$XP_PATH\"" ; then
      :
   else 
      echo "xp_start: non-zero exit status from command:"
      echo "     $XP_RSH $HOSTNAME $ARGS -path \"$XP_PATH\""
   fi
fi
