#!/bin/sh

if [ "$#" -lt 2 ]; then
    echo "Usage: $0 [mseed-volume] [output-xml]"
    exit 0
fi

DBFLAG="-d mysql://sysop:sysop@localhost/seiscomp3"
STORAGE=$DBFLAG
FLAGS="--console=1 $STORAGE"

# Start EventParameters logging
echo "Starting sceplog..."
sceplog $FLAGS --auto-shutdown=1 --shutdown-master-module=scevent > $2 & 
# Start autoloc
echo "Starting autoloc..."
scautoloc $FLAGS --playback --start-stop-msg=1 --auto-shutdown=1 --shutdown-master-module=scautopick &
echo "Starting magtool..."
scmag $FLAGS --start-stop-msg=1 --auto-shutdown=1 --shutdown-master-module=scautoloc &
echo "Starting eventtool..."
scevent $FLAGS --start-stop-msg=1 --auto-shutdown=1 --shutdown-master-module=scmag &
# Start autopick as daemon
echo "Running autopick..."
scautopick -I $1 $FLAGS --start-stop-msg=1
echo "Finished"
