#! /bin/bash

## global Variables
WORKDIR="./"
ARCHIVEDIR="./archives"
#RESULTPRINTER=/opt/robocup/bin/rclmresultprinter
#MATCH_NAME=$1
PID=$3

## echo message and exit 1.
## _die(message, ...)
function _die {
    echo "Error: $*" 
    kill -s INT $PID
    exit 1
}

## ----------------------------------------------------------
## get team names
TEAM_1_DIR=$1
TEAM_2_DIR=$2

TEAM_1_NAME=`basename $TEAM_1_DIR`
TEAM_2_NAME=`basename $TEAM_2_DIR`

## before_match(team1, team2)
echo ""
echo "Next Match ${TEAM_1_NAME} vs ${TEAM_2_NAME}"

# check the length of team directory string
[ -z "${TEAM_1_DIR}" ] && _die "TEAM_1_DIR is empty!"
[ -z "${TEAM_2_DIR}" ] && _die "TEAM_2_DIR is empty!"

# check start script
[ -x ${TEAM_1_DIR}/start ] || _die "start script does not exist in ${TEAM_1_DIR} !"
[ -x ${TEAM_2_DIR}/start ] || _die "start script does not exist in ${TEAM_2_DIR} !"

if [ $# -eq 4 ] ; then
  wait_time.rb $4
else
  echo -n "Press [Enter] to start next match..."
  read
fi

