#!/bin/bash
#
##################################################################################
# This file: 	IpeV4SLTScript
# Date:		2010-02-27 
# Author:	Till.Bergmann@kit.edu
# Purpose:	Customn Script to configure the PrPMC (e.g. for simulation mode)
#		or to execute commands on the PrPMC
##################################################################################

echo This is IpeV4SLTScript - number of arguments is $# 

if [ "$1" = "arg1" ]
then
	echo "- I recognized the argument '$1'! - "
elif  [ "$1" = "SimulationConfigScriptON" ]
then
	echo "- I recognized the argument '$1'! - "
	if test -a ~/ORCA; then
		cd ~/ORCA
		echo "PMC_COMPILE_IN_SIMULATION_MODE=1"> simulationmode.mk
		#touch HW_Readout.cc
		#touch ORSLTv4Readout.cc
		#touch ORFLTv4Readout.cc
		make -B
		if [ x"$2" = x"" ] ; then
			echo Start OrcaReadout with standard port 44667 ...
			~/ORCA/OrcaReadout 44667 &
		else
			echo Start OrcaReadout with port $2 ...
			~/ORCA/OrcaReadout $2 &
		fi
	else 
		echo Directory ORCA does not exist: upload readout code, send ON again and recompile!
	fi
elif  [ "$1" = "SimulationConfigScriptOFF" ]
then
	echo "- I recognized the argument '$1'! - "
	if test -a ~/ORCA/ ; then
		cd ~/ORCA
		echo "PMC_COMPILE_IN_SIMULATION_MODE=0"> simulationmode.mk
		#touch HW_Readout.cc
		#touch ORSLTv4Readout.cc
		#touch ORFLTv4Readout.cc
		#rm simulationmode.mk
		make -B
		# maybe I should leave it to the user to restart the readout code? -tb-
		if [ x"$2" = x"" ] ; then
			echo Start OrcaReadout with standard port 44667 ...
			~/ORCA/OrcaReadout 44667 &
		else
			echo Start OrcaReadout with port $2 ...
			~/ORCA/OrcaReadout $2 &
		fi
	else echo "OK (nothing needed to be done)"
	# shall I remove the file simulationmode.mk?
	fi
elif  [ "$1" = "shellcommand" ]
then
	echo "- I recognized the argument '$1'! - "
	echo "Executing shell command ..." "$2 $3 $4 $5 $6 $7 $8 $9"
	$2 $3 $4 $5 $6 $7 $8
else
	echo "Unknown argument"
fi



# some tests:
if [ "$1" = "tilltest" ]
    then
    cd ~/tmp
    touch tillsScriptWasHere.txt
    echo arguments are: XXX $0 $1 $2 XXX
    for X in $*
    do
        echo $X
    done
    echo Writing tillsScriptWasHere.txt
    echo hallo >>tillsScriptWasHere.txt

    rm ../IpeV4SLTScript
fi
