#!/bin/sh
# 
# jets3t script


# Source functions library
if [ -f /usr/share/java-utils/java-functions ] ; then 
  . /usr/share/java-utils/java-functions
else
  echo "Can't find functions library, aborting"
  exit 1
fi

JETS3T_HOME=/usr/share/jets3t

# Configuration
SCRIPT_PATH=$0
PROGNAME=$(basename $SCRIPT_PATH)
JETS3T_CONF=/etc/jets3t
JETS3T_RESOURCES=$JETS3T_HOME/resources
MAXMEM=-Xmx256M

# Wrappers
[ $PROGNAME = jets3t-cockpit ] && CLASS=org.jets3t.apps.cockpit.Cockpit
[ $PROGNAME = jets3t-cockpitlite ] && CLASS=org.jets3t.apps.cockpitlite.CockpitLite
[ $PROGNAME = jets3t-synchronize ] && CLASS=org.jets3t.apps.synchronize.Synchronize
[ $PROGNAME = jets3t-uploader ] && CLASS=org.jets3t.apps.uploader.Uploader


# Load system-wide configuration
if [ -f /etc/jets3t.conf ]; then
  . /etc/jets3t.conf
fi

# Load user configuration
[ -f "$HOME/.jets3trc" ] && . "$HOME/.jets3trc"

# Bail out if there's nothing to run
if [ -z "$CLASS" ]
then
	echo "Can not determine main class for '$PROGNAME'" >&2
	exit 1
fi


BASE_JARS="$TOOLS_JAR"
BASE_JARS="$BASE_JARS jets3t"
BASE_JARS="$BASE_JARS jets3t-gui "
BASE_JARS="$BASE_JARS jets3t-deps"
BASE_JARS="$BASE_JARS jets3t-cockpit"
BASE_JARS="$BASE_JARS jets3t-cockpitlite"
BASE_JARS="$BASE_JARS jets3t-synchronize"
BASE_JARS="$BASE_JARS jets3t-uploader"
BASE_JARS="$BASE_JARS axis"
BASE_JARS="$BASE_JARS bcprov"
BASE_JARS="$BASE_JARS commons-codec"
BASE_JARS="$BASE_JARS commons-httpclient"
BASE_JARS="$BASE_JARS commons-logging"
BASE_JARS="$BASE_JARS java-xmlbuilder"
BASE_JARS="$BASE_JARS log4j"

# Set parameters
set_jvm
set_classpath $BASE_JARS
set_flags $BASE_FLAGS
set_options $BASE_OPTIONS $MAXMEM

# Let's start
run --main "$CLASS" "$@"
