#!/bin/ksh -p
#
# ident "@(#)utxsun.sh	1.11 05/03/28 SMI"
#
# Copyright 2000,2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
INFODIR=/var/opt/SUNWut
RESDIR=$INFODIR/dispinfo
SUNWUTBIN=/opt/SUNWut/bin
XSUN=/usr/X11R6/bin/Xnewt
# XSERVER can be 1 of Xsun  (on sparc with openwin)
#                     Xnewt (on linux with mit-based static server)
#                     Xorg  (on linux with xorg-based static server)
XSERVER=Xorg
AWK=/bin/awk
XMOREOPTS=

if [ ! -x $AWK ]
then
    AWK=/usr/bin/awk
    if [ ! -x $AWK ]
    then
	print "No awk found" 1>&2
	exit 2
    fi
fi

# This is temporary for Beta. We need to figure out what the
# fontpath is for a particular system. We'll grep through the
# XF86Config file. For FCS we'll do this at install time and
# keep the path in a file.
if [[ -f /etc/X11/XF86Config ]] ; then
	# match lines with FontPath that are not commented out,
	# accumulate the path, but remove double quotes before appending:
	FONTPATH=$($AWK '$1 == "FontPath" { fp = fp "," substr($2,2,length($2)-2) } \
                        END { print substr(fp,2) } \
                        ' /etc/X11/XF86Config)
	if [ x$FONTPATH != x ] ; then
		XMOREOPTS="-fp $FONTPATH"
	fi
fi

if [ ! -x $XSUN ]
then
    XSUN=/usr/openwin/bin/Xsun
    XSERVER=Xsun
    XMOREOPTS="-nobanner"
    if [ ! -x $XSUN ]
    then
	print "No X server found" 1>&2
	exit 2
    fi
fi

dpy=${1#:}
geom=$($AWK -F= '/GROUP_PRIVATE_DATA/ {print $3}' \
	$RESDIR/$dpy 2> /dev/null)

XOPTS=$($SUNWUTBIN/utxconfig -d $1 -X $XSERVER -L ${geom:-1x1} 2> /dev/null)

exec $XSUN "$@" $XMOREOPTS $XOPTS
