#!/bin/sh
set -e

BINDIR=`dirname $0`
if [ -d $BINDIR/../java/jre ]; then
	JAVA="$BINDIR/../java/jre/bin/java"
	JAVAARGS="--add-exports java.desktop/com.apple.eawt=VncViewer"
else
	if [ "$JAVA_HOME" = "" ]; then
		JAVA=java
	else
		JAVA="$JAVA_HOME/bin/java"
	fi
fi
TVNC_JAVADIR=@CMAKE_INSTALL_FULL_JAVADIR@
if [ -d $BINDIR/../java ]; then
	TVNC_JAVADIR=$BINDIR/../java
fi

if [ "@BITS@" = "32" ]; then
	exec "$JAVA" $JAVAARGS -server -d@BITS@ -Djava.library.path=$TVNC_JAVADIR -jar $TVNC_JAVADIR/VncViewer.jar ${1+"$@"}
else
	exec "$JAVA" $JAVAARGS -server -Djava.library.path=$TVNC_JAVADIR -jar $TVNC_JAVADIR/VncViewer.jar ${1+"$@"}
fi
