#!/bin/bash
BASEDIR=/var/lib/suckmt                 # base directory for scripts
# Get the parameters 
. ${BASEDIR}/NewsParams


# if we are already running, abort 
if [ -f ${LOCKFILE} ]; then
	echo "Already running, can't run two at one time"
	exit
else
	touch ${LOCKFILE}
fi

echo "  NEWS Transfer START `date`" >> ${BASEDIR}/transfer.log

# is the local host up and running so we can post messages we download?
${TESTHOST} ${LOCAL_HOST} -s
LOCAL_RESULT=$?

if [ ${LOCAL_RESULT} -ne 0 ]; 
then
	echo "Local Host not responding"
	echo "Local Host not responding" >> ${BASEDIR}/transfer.log
fi

# is the remote host up and running so we can download messages?
${TESTHOST} ${REMOTE_HOST} -s
REMOTE_RESULT=$?

if [ ${REMOTE_RESULT} -ne 0 ]; 
then
	echo "Remote Host not responding"
	echo "Remote Host not responding" >> ${BASEDIR}/transfer.log
fi

if [ ${REMOTE_RESULT} -eq 0 -a ${LOCAL_RESULT} -eq 0 ]; then
	${BASEDIR}/ReceiveNews &
	${BASEDIR}/SendNews &
	wait
    
    # Start the post processing immediately
    ${BASEDIR}/PostProcessNews &
else
    rm -f ${LOCKFILE}
fi
echo "  NEWS Transfer STOP  `date`" >> ${BASEDIR}/transfer.log
