#!/bin/sh
# Copyright 1995-2005 Richard M. Troth, all rights reserved. <plaintext>
#
#         Name: rcv (shell script)
#               "receive" a file sent via UFT
#         Date: 2024-04-19 (Fri) Gallatin
#

Z=`basename "$0"`

U=`id | awk -F\( '{print $2}' | awk -F\) '{print $1}'`

D=/var/spool/uft/$U
if [ ! -d $D ] ; then
exec ls -ld $D ; fi

#
# clean-up the spool ID
S="$1"
if [ -z "$S" ] ; then S=1 ; fi
S=`echo "0000$S" | awk '{print substr($0,length($0)-3,4)}'`

#
# extract the metadata and load it into this shell
grep -v '^#' $D/$S.cf | awk '{print "UFT_" $0}' | grep -v '=$' > /tmp/$$.set
RC=$? ; if [ $RC -ne 0 ] ; then rm -f /tmp/$$.set ; exit $RC ; fi
. /tmp/$$.set
rm /tmp/$$.set

#
# file needs a name
T="$2"
if [ -z "$T" ] ; then T="$UFT_NAME" ; fi
if [ -z "$T" ] ; then
    echo "$Z: UFT file $S needs a name"
    exit 1 ; fi

#
# report and receive
echo "$Z: receiving UFT file $S as '$T'"
cat $D/$S.df > $T
RC=$? ; if [ $RC -ne 0 ] ; then exit $RC ; fi

#
# if that worked then discard the spool file
yes | rm $D/$S.*

exit

# some example UFT file attributes:

UFT_REMOTE=                             # the sending user@host if available
UFT_SIZE='36K'                          # estimated size reported by sender
UFT_FROM='ltroth3'                      # sending user per the FILE command
UFT_USER='rmt'                          # intended recipient
UFT_TYPE='I'                            # text? binary? or something else?
UFT_NAME='uftcreqs.tar'                 # the name of the file, if available
UFT_DATE='2024-04-19 20:22:31'          # date stamp on the file being sent
UFT_RECFM='F'                           # record format, if applicable
UFT_LRECL='512'                         # record length, if applicable


