#!/bin/ksh -p
#
# ident "@(#)gdm-add-dpy.sh	1.3 04/06/24
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
#
# Script to add an X server to the Xservers file and set it up via the
# Xconfig file to service 
#
# The database of available display numbers is taken as 
# Xservers. If a display is mentioned as
#
#	sysname:num OR :num
#
# at the beginning of a line or the beginning of a comment, it is considered
# unavailable for use.
#
# E.g. a line '# :3 RESERVED' will prevent display 3 from being assigned
#

#
# Note that for Gdm Xconfig is not required 
# Therefore we will create an Xconfig file, whose sole
# purpose in life is to contain the env necessary for the session, and
# we'll read it when necessary to establish the environment.  
# Similarly Xservers is not required, the private online interface
# to gdm is all that is needed. We use Xservers as the database
# of X displays in use by SunRay
#

unset LD_LIBRARY_PATH

BASE=/etc/opt/SUNWut/basedir
SUNWUT=$BASE
SUNWUTLIB=$SUNWUT/lib

INET_SERVICES=/etc/services 

#
# Set default values
#
INFODIR=/var/opt/SUNWut
ETCDIR=/etc/opt/SUNWut
TMPDIR=/tmp/SUNWut

# Note - we start MINDISP at 11 using gdm for linux. It gets around bug
# 5057552, which is actually caused by lax privileges defined by
# /etc/security/console.perms
MINDISP=11		# minimum display number XXX
MAXDISP=1000	# maximum display number XXX -> must match OWconfig
#
# Add a session
#

dir=$1		# location of config files and lock
token=$2	# token name
type=$3		# session type
mvdisplay=$4	# mv display command line

xserv=$dir/Xservers	# SRSS's Xservers file
xconf=$dir/Xconfig	# SRSS's Xconfig file
xconfiglock=$dir/config.lock    # X-Windows config lock file

xcdesc="DisplayManager.*_%d.exportList: SUN_SUNRAY_TOKEN=$token CORONA_TOKEN=$token"
if [ "$type" = normal ]
then
	xsdesc=":%d SunRay local /usr/X11R6/bin/Xnewt :%d"
else
	xsdesc="# :%d RESERVED"
fi

#
# Allow everyone to read Xsessions and Xconfig file
#
umask 0022

dpy=$($SUNWUTLIB/utdtutil -l $xconfiglock -s "$xsdesc" -c "$xcdesc" \
	-i "$INET_SERVICES" -F $MINDISP -L $MAXDISP \
	-R "$mvdisplay" $xserv $xconf)
print $dpy
