#!/bin/sh

logdir=/var/tmp/carmen-logs

if [ ! -e $logdir ]; then
  mkdir $logdir
	chmod a+rwx $logdir
fi

carmen-kill.sh

with_camera=
if [ $# -gt 0 ]; then
  with_camera=yes
  echo "(re) starting Carmen with camera..."
else
  echo "(re) starting Carmen without camera..."
fi

message_log=$logdir/message_daemon.log
param_log=$logdir/param_daemon.log
orc_log=$logdir/orc_daemon.log
robot_central_log=$logdir/robot_central.log
quickcam_log=$logdir/quickcam_daemon.log

timestamp_pre="------- Carmen"
timestamp_post="(Re)started `date` -------"

echo "" > $message_log
echo "$timestamp_pre message_daemon $timestamp_post" >> $message_log

echo "" > $param_log
echo "$timestamp_pre param_daemon $timestamp_post" >> $param_log

echo "" > $orc_log
echo "$timestamp_pre orc_daemon $timestamp_post" >> $orc_log

echo "" > $robot_central_log
echo "$timestamp_pre robot_central $timestamp_post" >> $robot_central_log

if [ $with_camera ]; then
  echo "" > $quickcam_log
  echo "$timestamp_pre quickcam_daemon $timestamp_post" >> $quickcam_log
fi

message_daemon >> $message_log 2>&1 &
sleep 1
param_daemon >> $param_log 2>&1 &
sleep 1
orc_daemon >> $orc_log 2>&1 &
sleep 1
robot_central >> $robot_central_log 2>&1 &

if [ $with_camera ]; then
  sleep 1
  quickcam_daemon >> $quickcam_log 2>&1 &
fi	

chmod -f a+rwx $logdir
chmod -f a+rw $logdir/*
