#! /bin/sh
# Front end to allow the HST GSC CDs to be accessed from machines other
# than the one on which the CDrom drives reside.  An rsh is spawned that
# propagates the stdin and stdout back to this script (and thence to the
# caller, an IRAF foreign task).  The FITS files off the CDs are staged
# onto the CD host machine's /tmp disk and then copied to the cwd.

# This script is designed to be a drop in replacement for the x_cdroms.e
# executable.  To install it, make a symbolic link from this file into
# the correct stsdas bin directory, removing the original executable if
# necessary.  The original executable should be left in the osprocs$unix
# directory on the CDrom host machine, i.e., don't do a `mkpkg install'
# after compiling and linking.

# Rob Seaman, NOAO CCS, 9/10/90

cd_host='orion'
stsdas='/local/stsdas'

cd_exe=/local/iraf/local/bin/xx_cdroms.e	# changed 8/2/91, CB

if [ `hostname` = $cd_host ]; then
    exec $cd_exe

else
    d=`rsh $cd_host 'echo /tmp/gasp.dir.$$'`
    trap "echo ' cleaning up...' >&2; rsh $cd_host 'rm -rf $d'; exit" 1 2 3 15

    cat <&0 | rsh $cd_host "mkdir $d; cd $d; exec $cd_exe"

    rcp $cd_host:$d/* .	# copy the FITS files back to the cwd
    rsh $cd_host rm -rf $d	# clean up
fi
