#!/bin/sh
#
# This script makes invoking the slate vm easier. The behaviour depends on what
# environment variables are set. By default the slate binary is looked up in
# $PATH (if $SLATE_BIN is unset). For using plugins a slate library directory is
# prepended to $LD_LIBRARY_PATH, if $SLATE_LIB is unset /usr/share/slate/lib is
# used. Furthermore $SLATE_IMAGE can be used to define a default image which is
# used if no arguments are given. If $SLATE_IMAGE is unset and no arguments are
# given the script will try to cd to $SLATE_HOME which defaults to
# /usr/share/slate.
#

: ${SLATE_BIN:="`which slate`"}
: ${SLATE_LIB:="/usr/lib/slate"}
# SLATE_IMAGE is an image to be used if none is given
: ${SLATE_HOME:="/usr/share/slate"}

# Prepending $SLATE_LIB to $LD_LIBRARY_PATH.
if test "x$LD_LIBRARY_PATH" = "x"; then
	export LD_LIBRARY_PATH="$SLATE_LIB"
else
	export LD_LIBRARY_PATH="$SLATE_LIB:$LD_LIBRARY_PATH"
fi

# No arguments?
if test "x$*" = "x"; then
	# Try $SLATE_IMAGE,
	if test "x$SLATE_IMAGE" != "x" -a -f "$SLATE_IMAGE"; then
		exec "$SLATE_BIN" "$SLATE_IMAGE"
	fi
	# or $SLATE_HOME
	if test "x$SLATE_HOME" != "x" -a -d "$SLATE_HOME"; then
		cd "$SLATE_HOME"
	fi
fi
# and finally exec the binary.
exec "$SLATE_BIN" "$@"
