#!/bin/sh

# Create the fake application dir.
APPDIR=`(cd ~; pwd)`/.azureus/app
if ! test -d $APPDIR; then
  mkdir -p $APPDIR;
fi

# Reconstruct the plugins dir.
rm -rf $APPDIR/plugins
mkdir -p $APPDIR/plugins
pushd $APPDIR/plugins > /dev/null 2>&1
for pdir in /usr/share/azureus/plugins/*; do
  ln -s $pdir .;
done;
popd > /dev/null 2>&1

# Source functions library
. /usr/share/java-utils/java-functions

# Source system prefs
if [ -f /etc/azureus.conf ] ; then
    . /etc/azureus.conf
fi

# Source user prefs
if [ -f $HOME/.azureusrc ] ; then
    . $HOME/.azureusrc
fi
FIREFOXVER=$(firefox -version| cut -d "," -f1|cut -d " " -f3)
export MOZILLA_FIVE_HOME=/usr/lib64/firefox-$FIREFOXVER
echo $MOZILLA_FIVE_HOME
export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
      
# Configuration
MAIN_CLASS="org.gudy.azureus2.ui.swt.Main"
BASE_FLAGS="-Djava.library.path=/usr/lib64 -Dgnu.gcj.runtime.VMClassLoader.library_control=never -Dazureus.install.path=$APPDIR"
BASE_JARS="Azureus2 bcprov jakarta-commons-cli log4j swt-gtk bcprov"

# Set parameters
set_jvm
set_classpath $BASE_JARS
set_flags $BASE_FLAGS

echo "You can ignore errors below about jakarta-commons-cli and log4j if you are"
echo "not using the Azureus console interface."

# Let's start
run "$@"
