#! /bin/sh

# Setting paths to everything you're going to need
PATH_TO_CAT="/bin"
PATH_TO_PING="/sbin"
PATH_TO_NC="/usr/pkg/sbin"
PATH_TO_SLEEP="/bin"

# Set binary names
CAT="cat"
PING="ping"
NC="nc"
SLEEP="sleep"

# Options for binaries
# 10 seems to work well for SLEEP_TIME
PING_OPTIONS="-c 1 -w 0.1"
NETCAT_OPTIONS="-w 1"
SLEEP_TIME="10" 

# Hostname and port of Dreamcast
HOSTNAME="dreamcast"
PORT="4711"

# Path and name of file
PATH_TO_FILE="/mnt/exports/dc"
FILENAME="netbsd"

# Control variable for upload status
UPLOAD="1"


while :
do 
   # echo "UPLOAD is $UPLOAD"
   if ( $PATH_TO_PING/$PING $PING_OPTIONS $HOSTNAME > /dev/null ) ;
   then
      # echo "Pinged up, checking UPLOAD..."
      if [ "$UPLOAD" -eq "1" ] ;
      then
	 # echo "UPLOAD is 1, Sending kernel..."
         $PATH_TO_CAT/$CAT $PATH_TO_FILE/$FILENAME | $PATH_TO_NC/$NC $NETCAT_OPTIONS $HOSTNAME $PORT
	 UPLOAD="0"
      fi
   else
      # echo "Pinged down, setting UPLOAD to 1 and not sending kernel..."
      UPLOAD="1"
   fi 
   # echo "Sleeping for $SLEEP_TIME seconds..."
   $PATH_TO_SLEEP/$SLEEP $SLEEP_TIME
done 
