#!/bin/sh

# This line will be automatically uncommented when you "make install"
installed=1

if [ -z $installed ] ; then
    echo "*** Running uninstalled IndexHelper.exe ***"
    THIS_PATH="../Util:../BeagleClient:."
    THIS_EXE="./IndexHelper.exe"

    export BEAGLE_TOOL_PATH="../tools"

    export MONO_PATH="../Util:../BeagleClient${MONO_PATH+:$MONO_PATH}"
    export LD_LIBRARY_PATH="../glue/.libs${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}"
    export BEAGLE_FILTER_PATH="../Filters${BEAGLE_FILTER_PATH+:$BEAGLE_FILTER_PATH}"
else
    THIS_PATH="/usr/lib64/beagle"
    THIS_EXE="/usr/lib64/beagle/IndexHelper.exe"
fi

if [ -n "$_GET_ON_THE_HEAP_BUDDY_BANDWAGON" ]; then
   n=1
   while [ -e $BEAGLE_HEAP_BUDDY_DIR/outfile.helper.$n ]; do
	 n=$(($n+1))
   done	
   MONO_EXTRA_ARGS="--profile=heap-buddy:$BEAGLE_HEAP_BUDDY_DIR/outfile.helper.$n $MONO_EXTRA_ARGS"
elif [ -n "$_HEY_LETS_DO_A_HEAP_SHOT" ]; then
   n=1
   while [ -e $BEAGLE_HEAP_SHOT_DIR/outfile.helper.$n ]; do
	 n=$(($n+1))
   done	
   MONO_EXTRA_ARGS="--profile=heap-shot:$BEAGLE_HEAP_SHOT_DIR/outfile.helper.$n $MONO_EXTRA_ARGS"

fi

if [ -n "$BEAGLE_MONO_DEBUG_FLAG_IS_SET" ]; then
   MONO_EXTRA_ARGS="--debug $MONO_EXTRA_ARGS"
fi

export MONO_PATH="$THIS_PATH${MONO_PATH+:$MONO_PATH}"

CMDLINE="$BEAGLE_MONO_RUNTIME $MONO_EXTRA_ARGS $THIS_EXE $@"

PROCESS_NAME="beagled-helper"
exec -a $PROCESS_NAME $CMDLINE

