#!/bin/bash

prefix=/usr
libdir=/usr/lib
exec_asm="banshee.exe"
MONO_EXE="/usr/lib/banshee/$exec_asm"

export DYLD_LIBRARY_PATH=/usr/lib:/usr/lib/banshee${DYLD_LIBRARY_PATH+:$DYLD_LIBRARY_PATH}
export LD_LIBRARY_PATH=/usr/lib:/usr/lib/banshee${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
export GST_PLUGIN_PATH=/usr/lib/banshee/gstreamer-0.10${GST_PLUGIN_PATH+:$GST_PLUGIN_PATH}

[ -n "$BANSHEE_DEBUG" ] && BANSHEE_DEBUG="--debug"
[ -n "$BANSHEE_TRACE" ] && BANSHEE_TRACE="--trace=$BANSHEE_TRACE"
[ -n "$BANSHEE_PROFILE" ] && BANSHEE_PROFILE="--profile=$BANSHEE_PROFILE"

for arg in $*; do
    case "x--debug" in ("x$arg")
        BANSHEE_DEBUG=$arg
    esac

    case "x--trace=" in ("x${arg:0:8}")
        BANSHEE_TRACE=$arg
    esac

    case "x--profile=" in ("x${arg:0:10}")
        BANSHEE_PROFILE=$arg
    esac
done

if [ -n "$BANSHEE_DEBUG" ]; then
    echo "** Running Banshee in Debug Mode **"
fi

if [ -n "$BANSHEE_DEBUG" -o -n "$BANSHEE_TRACE" -o -n "$BANSHEE_PROFILE" ]; then
    MONO_OPTIONS="$BANSHEE_DEBUG $BANSHEE_TRACE $BANSHEE_PROFILE"
    echo "** Running Mono with $MONO_OPTIONS **"
fi

# Plugins can install scripts to be sourced into this script. 
# Sourcing is useful if a plugin needs to ensure certain environment 
# variables are initialized.

if [ -d $libdir/banshee/shell-init ]; then
	for init in `find $libdir/banshee/shell-init/*`; do
		if [ ! -x $init ]; then
			continue
		fi

		source $init;	
	done
fi

# Finally - environment is set up, time to run our beloved
exec -a banshee mono $MONO_OPTIONS $MONO_EXE $BANSHEE_DEBUG "$@"

