#!/bin/sh

# Config files can define several variables used throughout this script.
# JAVACMD - The java command to launch osmosis.
# JAVACMD_OPTIONS - The options to append to the java command, typically used to modify jvm settings such as max memory.

if [ -f /etc/osmosis ] ; then
  . /etc/osmosis
fi

if [ -f "$HOME/.osmosis" ] ; then
  . "$HOME/.osmosis"
fi

if [ -z "$JAVACMD" ] ; then
  # No JAVACMD provided in osmosis config files, therefore default to java
  JAVACMD=java
fi

## resolve links - $0 may be a link to application
PRG="$0"

# if started without absolute path, but from PATH environment
if [ ! -s "$PRG" ] ; then
    PRG=`which $PRG`
fi

# 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

# make it fully qualified
saveddir=`pwd`
MYAPP_HOME=`dirname "$PRG"`/..
MYAPP_HOME=`cd "$MYAPP_HOME" && pwd`
cd "$saveddir"

# Build up the classpath of required jar files.
MYAPP_CLASSPATH=$MYAPP_HOME/osmosis.jar:$OSMOSIS_CLASSPATH
for FILE in `ls $MYAPP_HOME/lib/default/`; do
  MYAPP_CLASSPATH=$MYAPP_CLASSPATH:$MYAPP_HOME/lib/default/$FILE
done

MAINCLASS=org.openstreetmap.osmosis.extract.mysql.v0_6.OsmosisExtractMysql
EXEC="$JAVACMD $JAVACMD_OPTIONS -cp $MYAPP_CLASSPATH $MAINCLASS $@"

exec $EXEC
