#!/bin/sh

# Copyright (C)2007 Sun Microsystems, Inc.
# Copyright (C)2021 Karl Kleinpaste
# Copyright (C)2022 D. R. Commander
#
# This library is free software and may be redistributed and/or modified under
# the terms of the wxWindows Library License, Version 3.1 or (at your option)
# any later version.  The full license is in the LICENSE.txt file included
# with this distribution.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# wxWindows Library License for more details.

if [ "$1" = "-check" ]; then exit 0; fi

VGLRUN=

usage()
{
	echo "USAGE: $0 [-v] -s <server-side port on SSH tunnel>"
	exit 1
}

if [ "$1" = "" ]; then usage $0; fi

if [ "$1" = "-v" ]; then

	VGLRUN=vglrun
	shift

fi

if [ "$1" = "-s" ]; then

	if [ "$2" = ""  ]; then usage $0; fi
	VGL_CLIENT=localhost
	export VGL_CLIENT
	VGL_PORT=$2
	export VGL_PORT
	__VGL_SSHTUNNEL=1
	export __VGL_SSHTUNNEL

else

	usage $0

fi

exec $VGLRUN $SHELL -l
