#!/bin/sh
# Script for starting Jext on Unix.
#
# This version allows for an install in a central area like /usr/local/jext.
# Set the JEXT_HOME to /usr/local/jext and add this to your PATH in
# /etc/profile. Setting JAVA_HOME to the base of your Java JDK or JRE is
# also a good idea as it helps Java find fonts and stuff.

# To allow an execution from a central place, please uncomment the lines
# marked by the <PLUGINS> tag

# Original Author: Norbert Seidel
# Modified by: Duncan Dickinson [06/12/2000]
# Modified by: Yannis Delmas    [18/12/2000]
# Modified by: Jonas De Vuyst   [20/12/2000]

if [ "$1" = --help ] ; then
	echo "This script loads the Jext editor."
	echo "Usage: jext.sh [files]"
	echo "Environment variables:"
	echo "HOME:		home directory of user"
	echo "JEXT_HOME:	Jext's base directory"
	echo "JAVA_HOME:	Java implementation base directory"
	echo "JAVA_CMD :      Java interpreter path"
	echo "JAVA_OPTS:	options for the Java interpreter"
    exit 0
fi

JEXT_HOME=/usr/local/share/java/jext
export JEXT_HOME
JAVA_CMD=/usr/local/bin/javavm

# Guess for JEXT_HOME if not set already
if [ -z "$JEXT_HOME" ] ; then
    # strip "/bin/sometext" from script path
    echo -n "You have not set the JEXT_HOME environment variable. "
    JEXT_HOME="`echo "$0" | sed "s/\\/bin\\/[^\\/]*\$//"`"
    echo "Assuming: $JEXT_HOME"
fi

##
# START make sure all our directories are there
##
if [ ! -d "$HOME/.jext" ]; then
    # Create the Jext config directory
    echo "Creating your configuration directory [~/.jext]"
    mkdir -p $HOME/.jext/xinsert
fi

# <PLUGINS>
# uncomment for central execution
# if [ ! -h "$HOME/.jext/plugins" ]; then
#     # Add links to plugins
#     ln -s $JEXT_HOME/bin/plugins $HOME/.jext
# fi

#if [ ! -h "$HOME/templates" ]; then
#    # Add links to templates
#    ln -s $JEXT_HOME/bin/templates $HOME/
#fi

##
# Directories are done
##
     
#if [ "$JAVA_HOME" = "" ] ; then
#    echo "You have not set the JAVA_HOME environment variable."
#    echo "I'll still load Jext but you may encounter font warnings"
#    echo "and other nasties."
#fi

# Allows for those with varying JDKs and standard calls to java
if [ -z "$JAVA_CMD" ] ; then
   if [ -z "$JAVA_HOME" ] ; then
      JAVA_CMD=java
   else
      JAVA_CMD="$JAVA_HOME/bin/java"
   fi
   JAVA_OPTS="" #"-Xms16m -Xmx32m"
fi

exec "$JAVA_CMD" $JAVA_OPTS -Dpython.home=$JEXT_HOME/lib -classpath "$JEXT_HOME/lib/jython.jar":"$JEXT_HOME/lib/dawn.jar":"$JEXT_HOME/lib/jext.jar" org.jext.Jext "$@"
