#!/bin/sh
#-----------------------------------------------------------------------------
# rshexec: Initiate commands invoked via rsh
#-----------------------------------------------------------------------------
#
#   Copyright (C) 1993,1994,1995
#   Associated Universities, Inc. Washington DC, USA.
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#   Correspondence concerning AIPS++ should be addressed as follows:
#          Internet email: casa-feedback@nrao.edu.
#          Postal address: AIPS++ Project Office
#                          National Radio Astronomy Observatory
#                          520 Edgemont Road
#                          Charlottesville, VA 22903-2475 USA
#
#-----------------------------------------------------------------------------
# Usage: rshexec [-i] [-e <aips_ext>] <command [arguments]>
#-----------------------------------------------------------------------------
# rshexec defines the AIPS++ environment for a process invoked by 'rsh' and
# then exec's the command with any specified arguments.
#
# Options:
#   -i     Report the command before exec'ing it.
#   -e <aips_ext>
#          Specifies an alternative AIPS++ architecture extension.
#
# Original: 1993/07/14 by Mark Calabretta, ATNF
# $Id$
#=============================================================================
# The AIPS++ root directory is hardcoded here.
  AIPSROOT=__AIPSROOT
  export AIPSROOT

#------------------ Do not change anything below this line -------------------
# Parse options for rshexec.
  INFORM=""
  while [ "$#" -gt 0 ]
  do
     case $1 in
     -i)
        INFORM=1
        ;;
     -e*)
        case $1 in
        -e)
           shift
           aips_ext="$1"
           ;;
        *)
           aips_ext=`echo $1 | sed -e 's/^-e//'`
           ;;
        esac
        ;;
     *)
        break
        ;;
     esac

     shift
  done

# Be informative?
  if [ "$INFORM" != "" ]
  then
     echo $*
     echo ""
  fi


# Get the AIPS++ environment.
  . $AIPSROOT/.profile

# Invoke the command.
  eval exec $*
