#!/bin/ksh -p
#
# ident "@(#)dtlogin-add-dpy.sh	1.3 04/02/04"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
#
# Script to add an X server to the xdm 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
#


unset LD_LIBRARY_PATH

DMNAME=dtlogin

# support SUNWuto relocation by using basedir symlink
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

MINDISP=2		# 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	# DMNAME's Xservers file
xconf=$dir/Xconfig	# DMNAME's Xconfig file
xconfiglock=$dir/config.lock    # X-Windows config lock file

xcdesc="Dtlogin.*_%d.environment: SUN_SUNRAY_TOKEN=$token CORONA_TOKEN=$token"
if [ "$type" = normal ]
then
	xsdesc=":%d SunRay local@none $SUNWUTLIB/utxsun :%d -nobanner"
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
