#!/bin/sh
#
# Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
#

theModule=kiosk:vdm

#################### USER CONFIGURABLE OPTIONS ################################
theJavaExec=/usr/java/bin/java

# For SSL connections:
# Set the location of the Java key store. If you are using a self signed
# certificate it must be imported into the keystore using keytool.
javaKeyStore=$KIOSK_SESSION_DIR/keystore
javaKeyStorePass=

USER_SCRIPT=$KIOSK_SESSION_DIR/vdm-user.sh

####################### BEGIN SESSION SCRIPT###################################

theClient=$KIOSK_SESSION_DIR/vdmclient.jar
theUser=`$USER_SCRIPT`

KIOSK_SESSION_DIR=$KIOSK_SESSION_DIR/../uttsc
theUTTSCScript=$KIOSK_SESSION_DIR/uttsc

export KIOSK_SESSION_DIR

LOGIN_LANGUAGE=${LANG:=en}

if [ -n "$theUser" ]; then
    if [ "$theUser" != "$SUN_SUNRAY_TOKEN" ]; then
        userNameArg="$theUser"
    fi
fi

xset fp+ /usr/openwin/lib/X11/fonts/TTbitmaps

errLog=/tmp/vdm.$$
trap "rm -f $errLog; exit" INT TERM EXIT

# Connect to the VDM Connection server, request a VM, and open an RDP connection to it
result=`$theJavaExec -client -Duser.language=$LOGIN_LANGUAGE -Djavax.net.ssl.trustStore=$javaKeyStore -Djavax.net.ssl.trustStorePassword=$javaKeyStorePass -jar $theClient -uttsc $theUTTSCScript -m "$userNameArg" "$@" > $errLog 2>&1`
retCode=$?
cat $errLog | logger -i -p user.error -t $theModule

if [ $retCode -gt 0 ]; then
    logger -i -p user.error -t $theModule \
       "Error: Could not locate Virtual Machine for '$theUser': exit code: $retCode $result"
fi
exit $retCode
