#!/bin/bash

# kill esound if it's running -- we can't coexist.
pkill esd

if [[ $1 == "-t" ]];
    then 
    { 
        echo "running mas and watchdog from within your tree: $2";
        PREFIX=$2
        LD_LIBRARY_PATH=${PREFIX}/build/lib
        export LD_LIBRARY_PATH  # somehow i need this
        MAS=${PREFIX}/mas/mas
        MAS_WD=${PREFIX}/clients/util/maswatchdog
    }
    else
    {
        PREFIX=/usr/local/mas
        LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${PREFIX}/lib
        MAS_PATH=${PREFIX}/lib/mas
        MAS=${PREFIX}/bin/mas
        MAS_WD=${PREFIX}/bin/maswatchdog
    }
fi;


LOG=${PREFIX}/mas-1.log

$MAS > $LOG 2>&1 &
sleep 1
exec $MAS_WD > /dev/null 2>&1
