#!/bin/sh
#
# this script should be in the root directory of the distribution

# name of various properties passed to install app
#
ARCHPROP="visad.install.arch"
HOMEPROP="visad.install.home"
PATHPROP="visad.install.path"

# figure out where this script lives
#
DISTTMP=`echo $0 | sed 's/\/[^\/]*$/\//'`
DISTDIR=`cd $DISTTMP && pwd`

# get OS/machine info
#
OS=`uname -s`
MACH=`uname -p`

# try to guess name of OS/machine distribution file/directory
#
ARCH=
case "$OS-$MACH" in
FreeBSD*-i*86) ARCH="freebsd-x86";;
Linux*-i*86) ARCH="linux-x86";;
SunOS-sparc) ARCH="solaris-sparc";;
esac

# if we guessed an OS/machine architecture...
#
if [ ! -z "$ARCH" ]; then
  JBIN="$DISTDIR/jdk-$ARCH/bin"

  # if JDK dir exists...
  #
  if [ -d "$JBIN" ]; then

    # ...add directory to PATH envvar
    #
    if [ -z "$PATH" ]; then
      PATH="$JBIN"
    else
      PATH="$JBIN:$PATH"
    fi
    export PATH
  fi
fi

# make sure visad.jar is in the CLASSPATH
#
CPARG=
if [ -f $DISTDIR/visad.jar ]; then
  CPARG="-cp $DISTDIR/visad.jar"
fi

# and away we go!
#
exec java $CPARG \
	"-D$ARCHPROP=$ARCH" \
	"-D$HOMEPROP=$DISTDIR" \
	"-D$PATHPROP=$PATH" \
		visad.install.Main
