#!/bin/ksh 
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# ident  "@(#)sessionetc.src 1.17     04/09/09 SMI; TSOL 2.x"
#
#####################################################################
###  File:              sessionetc
###
###  Default Location:  /usr/dt/config/sessionetc
###
###  Purpose:		 To start additional programs under user's id at login
### 			 time after all user saved session applications have
###			 been started.
###
###       		 The /usr/dt/config location can be overwritten by 
###			 system software upgrades.  If you want to start 
###			 additional programs specific to a this workstation and
###			 not be effected by system upgrades, instead create a 
###			 similar executable file at /etc/dt/config/sessionetc.
###
###  Invoked by:        CDE SessionMgr (dtsession)
###
###  Revision:          @(#)sessionetc.src 1.17 04/09/09 
###
#####################################################################

if [ "$DTXSERVERLOCATION" != "remote" ]
then
  console=False
  case "$DISPLAY" in
  *:0|*:0.0)
    console=True
    ;;
  esac
  if [ "$console" = "True" ]
  then

    if [ -x /usr/dt/bin/sdtvolcheck ]
    then
	/usr/dt/bin/sdtvolcheck -d -z 5 cdrom,zip,jaz,dvdrom,rmdisk &
	echo $! | /bin/cat > /var/dt/tmp/$DTUSERSESSION/sdtvolcheck_pid
    fi
  fi
	# For Trusted Solaris change ownership to user
	chown -fR $LOGNAME $HOME/.dt/$LANG
	chown -fR $LOGNAME $HOME/.dt/wsmenu
fi

#
# The following lines are executed on behalf of
# 0100.SUNWut Sun Ray script
#

if [ "$XDIR" = "" ]
then
	XDIR=/usr/openwin/bin
fi

#
# The Sun Ray session is in the 
# _SUN_SUNRAY_SESSION property of 
# the root window
#
DEVICE_SESSION=`$XDIR/xprop -root _SUN_SUNRAY_SESSION 2> /dev/null \
	| /bin/sed -e 's/.*"\(.*\)".*/\1/'`
[ -n "$DEVICE_SESSION" ] && \
        LOCAL_HOST=`echo $DEVICE_SESSION | \
        /bin/grep $(/bin/uname -n)':' 2> /dev/null`

IDLEDIR=/var/opt/SUNWut/idle
DPYDIR=/var/opt/SUNWut/displays

DPY=${DISPLAY#*:}
DPY=${DPY%.*}


if [ "$LOCAL_HOST" != "" ]
then
	if [ -x /opt/SUNWut/lib/utaction ] 
	then
		# If $SUN_SUNRAY_UTXLOCK_PREF is set to NULL, don't do it
		if [[ $SUN_SUNRAY_TOKEN != auth.* && -n "${SUN_SUNRAY_UTXLOCK_PREF-foo}" ]]
		then
			/opt/SUNWut/lib/utaction -i -d '/usr/dt/bin/dtaction LockDisplay' \
				2>/dev/null >/dev/null &
		fi
	fi
	# Kill the session reaper
	if [ -f $IDLEDIR/$DPY.pid ]
	then
		/bin/rm -f $IDLEDIR/$DPY.info
		UTPID=$(/bin/cat $IDLEDIR/$DPY.pid)
		/bin/rm -f $IDLEDIR/$DPY.pid
		kill $UTPID
	fi
fi

unset DEVICE_SESSION LOCAL_HOST
