#!/bin/sh
#
# /usr/bin/rdjbrowse
#
# Launches the RoboDJ music browser and playlist manager

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=robodj
DESC="Robodj game server"
PIDFILE="/var/run/$NAME.pid"
CLASS=robodj.importer.Importer
LOGFILE=/var/log/$NAME/stdout.log
ROBODJ_HOME=/usr/share/$NAME

# The following varibales can we overwritten in /etc/default/robodj

# The first existing directory is used for JAVA_HOME
JDK_DIRS="/usr/local/jdk1.4 /usr/lib/j2se/1.3"

# overwrite settings from default file
if [ -f /etc/default/robodj ]; then
    . /etc/default/robodj
fi

# Look for the right JVM to
for jdir in $JDK_DIRS; do
    if [ -d "$jdir" -a -z "${JAVA_HOME}" ]; then
        JAVA_HOME=$jdir
    fi
done
JAVA="$JAVA_HOME/bin/java"

test -f $DAEMON || exit 0

# Start with the standard Java classes
CLASSPATH="$JAVA_HOME/jre/lib/rt.jar"

# Add all JAR files in /usr/share/robodj/lib to the CLASSPATH
for jar in $ROBODJ_HOME/lib/*.jar; do
    if [ -e $jar ]; then
        CLASSPATH=$jar:$CLASSPATH
    fi
done
export CLASSPATH

$JAVA $CLASS
