#!/bin/sh

if [ -z "$CDARCHIVE_HOME" -o ! -d "$CDARCHIVE_HOME" ] ; then
  # try to find CDARCHIVE

  ## resolve links - $0 may be a link to ant's home
  PRG="$0"
  progname=`basename "$0"`

  # need this for relative symlinks
  while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
    else
    PRG=`dirname "$PRG"`"/$link"
    fi
  done

  CDARCHIVE_HOME=`dirname "$PRG"`

  # make it fully qualified
  CDARCHIVE_HOME=`cd "$CDARCHIVE_HOME" && pwd`
fi

JAVA=`which java 2> /dev/null`
if [ -z "$JAVA" ] ; then
	JAVA=java
fi

if [ ! -x "$JAVA" ] ; then
	  echo "Error: java is not under your path"
		exit 1
fi

JAVA_OPT="-server -Xmx256M"
SWT_LIB=$CDARCHIVE_HOME/swt/linux
SWT_JAVA_LIB=$CDARCHIVE_HOME/swt/java
JAVA_LIB="$SWT_JAVA_LIB/swt.jar:$SWT_JAVA_LIB/swt-mozilla.jar:$SWT_JAVA_LIB/swt-pi.jar:$CDARCHIVE_HOME/MCA.jar"

$JAVA $JAVA_OPT -Djava.library.path=$SWT_LIB -cp $JAVA_LIB org.mingyi.cdarchive.CDArchive $*
