#!/bin/sh
#
#==============================================================
#  Name: start_mcc_scp.sh
#  Abs:  A script to start up a MCC scp
#
#  Usage: start_mcc_scp.sh  [nodename] -Name of X server         
#
#         P1 = [username]  -will prompt if none given
#         P2 = [DECTERM]   
#
#  Facility: SLAC/PEPII/NLCTA/LCLS
#
#  Auth: Ken Brobeck
#  Rev:  dd-mmm-yyyy, First Lastname (USERNAME)
#
#        12-Dec-2006  Ken (Brobeck)
#
#--------------------------------------------------------------
#  Mod:
#        dd-mmm-yyyy, First Lastname (USERNAME)
#==============================================================
#
# when a user logs into a machine via SUNSRV00 or SUNSRV01 to 
# run EDM the DISPLAY variable is set to "sunsrv00:x.x"
#
# use remotehost to pass as a P1 parameter to MCC
#
from_sunray_host=`echo $DISPLAY | grep sunsrv>/dev/null;echo $?`
on_sunray_host=`echo $HOST | grep sunsrv>/dev/null;echo $?`

if [ $on_sunray_host = "0" ]
  then
     remotehost="$HOST$DISPLAY"
  else
     if [ $from_sunray_host = "0" ]
       then
	 remotehost=$DISPLAY
       else
         if [ "$REMOTEHOST" = "" ] 
  	   then
	     remotehost=$HOST
  	   else
	     remotehost=`echo $REMOTEHOST | awk -F. '{ print $1 }'`
       fi
    fi
fi
#echo "$remotehost  -remotehost"

if [ "$2" = "DECTERM" ]
  then
    decterm="DECTERM"
  else
    decterm=""
fi

HOST_LIST="lcls-mcc01 lcls-mcc02 lcls-mcc03"
HST_STS=`echo $HOST_LIST | grep $HOST>/dev/null; echo $?`

if [ "$HST_STS" = "0" ]
  then
    User="mccscp"
  else
    # Get Username
    #
    if [ "$1" = "" ]
      then
        echo -n "Enter Username to use (VMS account)[$USER]->  "
        read user
        if [ "$user" = "" ]  
	  then
	    User=$USER
          else
	    User=$user
        fi
      else
        User=$1
    fi
fi
#
#
#echo "ssh -Xl $User mcc-lavc "@slccom:start_scp_edm.com $remotehost $decterm"

ssh -Xl $User mcc "@slccom:start_scp_edm.com $remotehost $decterm"
