#!/bin/ksh -up
#
# read_xfer
#
# This script starts the second half of net_xfer.  It is run on the target 
# network.
#
# In order to write to where the files need to go, this script must be
# set be run as root.  Can avoid creating a a setuid script and 
# set up a "dedicated account" where this script is the login program (in lieu 
# of a typical login shell, or run as root via cron.
#
# Check if a tape is loaded.  If not, assume no files to transfer and
# bail

export PATH='/usr/bin:/usr/ucb:/usr/sbin'

XFER_DIR=/auto/admin/net_xfer
mt -f /dev/rmt/0 status

case $? in

	1) echo "no tape loaded"
		exit 0
		;;
	0) echo "Processing file transfers...."
		;;
esac 

umask 000

DATE=`date '+%m%d%y'`
LOGFILE=$XFER_DIR/xfer_log.$DATE

#
# Clear out working directory
#
rm -rf /$XFER_DIR/*


#
# Create the file so that we can just append to it if it does not exist.
#
if [ ! -f $LOGFILE ]; then
	touch $LOGFILE
fi

# Allow tape time to mount

sleep 5

# Untar the files.

tar -xvpf /dev/rmt/0 >> $LOGFILE 2>&1

/usr/ucb/mail -s "File transfer log" root < $LOGFILE

#=============
# VERIFICATION
#=============


#
# After untar'ing the tape, do an ls of /auto/admin/net_xfer
# and check for xfer_verify.*.  These are the verification scripts.
# They are just long listing commands of the files that were requested.
# The file extension by convention is the user that requested the 
# transfer.  In this manner we will know who to mail the results of the
# scripts to
#

if [ ! -d $XFER_DIR ]; then
	echo "Error!!! No where to stage verification scripts."
	echo "Make certain that $XFER_DIR directory exists"
fi
#
# Get username
#
#for SCRIPT in `/usr/bin/ls -1 $XFER_DIR/xfer_verify.*` 
#	do
	
        USER=`/usr/bin/ls -1 $XFER_DIR/xfer_verify.* | cut -f2 -d"." `

#
# Invoke TS verification script
#
/local/admin/file_verify  $USER


mt -f /dev/rmt/0 offline


