#! /bin/bash

# File:        npetoysrun
# Author:      Michael Rueger
# Last edited: 2005-02-28 18:42:20 by jens on impara.de
# Description: Script to start Etoys 
#              from the Browser Plugin (npetoys.so)

VM_VERSION=3.9-12
APPDIR=/usr/share/Etoys.app

BIN=$APPDIR/Contents/Linux686
VM=$BIN/etoys
VMOPTIONS="-encoding UTF-8 -plugins $BIN -vm-display-x11 "
IMAGE="$APPDIR/Contents/Resources/etoys.image"
IMOPTIONS=""
DOCUMENT=""


# The (untrusted) user directory is used by etoys to store project files.
# Default is $HOME/Etoys

# The secure directory location is used to store per-user security information like the keys file.
# It needs to be outside the untrusted space.
# Default is $HOME/.etoys/Squeak.keys

[ -n "$ETOYS_SECUREDIR" ] && export SQUEAK_SECUREDIR="$ETOYS_SECUREDIR"
[ -n "$ETOYS_USERDIR" ] && export SQUEAK_USERDIR="$ETOYS_USERDIR"

[ -z "$SQUEAK_SECUREDIR" ] && export SQUEAK_SECUREDIR="$HOME/.etoys"
[ -z "$SQUEAK_USERDIR" ] && export SQUEAK_USERDIR="$HOME/Etoys"

[ ! -d "$SQUEAK_SECUREDIR" ] && mkdir -p "$SQUEAK_SECUREDIR" && chmod 700 "$SQUEAK_SECUREDIR"
[ ! -d "$SQUEAK_USERDIR" ] && mkdir -p "$SQUEAK_USERDIR"

# is there a clever way to determine if you are local?
if [ $DISPLAY = ":0.0" ]; then
    VMOPTIONS=$VMOPTIONS" -xshm "
fi

parameter_to_array(){
    i=0
    for p in "$@"; do
	i=$(( $i + 1 ))
	parameter[i]=$p
    done
}

parameter_to_array "$@"
parameter[6]=$IMAGE
echo $VM $VMOPTIONS "${parameter[@]}"
$VM $VMOPTIONS "${parameter[@]}"

