#!/bin/bash

cd `dirname $0`/$1

LOG=logs/console.log.`date +%Y-%m-%d_%H:%M:%S`
touch $LOG
rm -f console.log
ln $LOG console.log

if [ $1 -eq 18 ]; then
  ./settime.sh &
elif [ $1 -eq 21 ]; then
  ./startlsr.sh &
fi

# Set up detach option based on whether this is a terminal
if [ -t 1 ]
then
	# We're talking to a terminal, fork
	SCREENMODE="-d"
else
	# We're not, so don't fork
	SCREENMODE="-D"
fi

if [ $1 -eq 18 ]; then
  exec /usr/bin/screen -h 1000 $SCREENMODE -m -S em$1 ./em -cpuid 5 -tport $2 -nport $3 -maps ring0.map ring3.map
else
  exec /usr/bin/screen -h 1000 $SCREENMODE -m -S em$1 ./em -tport $2 -nport $3 -maps ring0.map ring3.map
fi
