#!/bin/sh -x
##########################################################################
#
# routine: cdbpau.sh 
#
# purpose: Script to pause to allow remote CDBS deliveries.
#
#          It also appends the remote transfer trailer files to the
#          main trailer file (since at least the site#1 transfer should
#          be complete by now).
#
# modification history:
#
#   date    opr     who     reason
# -------- -----  --------  --------------------------------------
# 04/11/03 48141  MSwam     first version
# 05/06/04 48141  MSwam     add trailer pickup from remote transfer dirs
# 
##########################################################################
date
#
all_is_well=0

# pause to allow remote deliveries time to work
sleep $WAIT_SECONDS

#
# resolve stretch for UNIX
cdbdir=`osfile_stretch_file $CDB_IN_DIR`
if [ ! -d $cdbdir ]
then
   echo "ERROR: $cdbdir directory does not exist"
   exit $go_absent
fi
cd $cdbdir
if [ $? != 0 ]
then
   echo "ERROR: Failed to set directory to $cdbdir"
   exit $go_absent
fi
localdir=`pwd`
echo "sitting in $localdir"

# set main trailer file name
trl=$localdir/${OSF_DATASET}.trl

# append remote transfer trailers to main trailer
if [ -f ${OUTGOING1_DIR}/${OSF_DATASET}.trl ]
then
  cat ${OUTGOING1_DIR}/${OSF_DATASET}.trl >> ${trl}
fi
if [ -f ${OUTGOING2_DIR}/${OSF_DATASET}.trl ]
then
  cat ${OUTGOING2_DIR}/${OSF_DATASET}.trl >> ${trl}
fi

#
# complete, exit success
exit $all_is_well
