#!/bin/sh
#
# The following script works for LTSP5 and was tested in Ubuntu "Feisty" Linux.
# Original rdesktop script by James A. McQuillan,
# modified for LTSP5 by Colin Osterhout of SERRC (www.serrc.org).
#
# This software is licensed under the Gnu General Public License.
# The full text of which can be found at http://www.LTSP.org/license.txt
#
# Call this through lts.conf like this:
#           RDP_OPTIONS  = "-a 16"
#           RDP_SERVER   = w2k3.terminal.server.ip
#           SCREEN_02    = rdesktop
#
# or like this:
#           SCREEN_02    = "rdesktop -a 16 w2k3.terminal.server.ip"

PATH=/bin:$PATH; export PATH
. /usr/share/ltsp/screen-x-common
 
unset prefix
case "${RDP_SOUND}" in 
    nopulse) 
        [ -x "/usr/bin/pasuspender" ] && prefix="/usr/bin/pasuspender --" 
        # Only modify RDP_OPTIONS if no options are passed with the command
        # This way, individual rdesktop screens can turn off sound
        # with a call to: SCREEN_XX="rdesktop -r sound:none"
        [ $# -lt 2 ] && RDP_OPTIONS="${RDP_OPTIONS} -r sound:local"
        ;;
    pulse-oss) 
        [ -x "/usr/bin/padsp" ] && prefix="/usr/bin/padsp" 
        # Only modify RDP_OPTIONS if no options are passed with the command
        # This way, individual rdesktop screens can turn off sound
        # with a call to: SCREEN_XX="rdesktop -r sound:none"
        [ $# -lt 2 ] && RDP_OPTIONS="${RDP_OPTIONS} -r sound:local:oss"
        ;;
esac

RDESKTOP_OPTIONS="-f -u '' ${RDP_OPTIONS} $* ${RDP_SERVER}"

if boolean_is_true "${RDP_DAEMON:-"True"}"; then
    export XINITRC_DAEMON="True"
fi

if [ -x /usr/share/ltsp/xinitrc ]; then
    xinitrc=/usr/share/ltsp/xinitrc
fi

xinit $xinitrc $prefix /usr/bin/rdesktop ${RDESKTOP_OPTIONS} -- ${DISPLAY} vt${TTY} ${X_ARGS} -br >/dev/null 2>&1
