#! /bin/sh
export DISPLAY=127.0.0.1:0.0
export PATH=/usr/X11R6/bin:"$PATH"
export XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
export XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
export XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
export XNLSPATH=/usr/X11R6/lib/X11/locale

# Cleanup from last run.
rm -rf /tmp/.X11-unix

# Startup the X Server with the integrated Windows-based window manager.
# WARNING: Do not use 'xwinclip' in conjunction with the ``-clipboard''
# command-line parameter for XWin.  Doing so would start two clipboard
# managers, which is never supposed to happen.

XWin -multiwindow -clipboard -silent-dup-error 2>/dev/null &

# Wait for a resonable amount of time that the X Server starts up,
# then assume it failed and bail out

n=0
until ps -efW | grep -i XWin >/dev/null
do
    sleep 1
    n=`expr $n + 1`
    if [ $n -gt 10 ]; then
	break
    fi
done

# If the X Server actually started up, try to set the font path.
# We use caution because if the X Server is not running, xset will
# block until time out, which can be a long time.

if [ $n -le 10 ]; then
    until xset -q | grep /usr/local/share/lyx/fonts >/dev/null
    do
	xset fp+ /usr/local/share/lyx/fonts
    done
fi

exit
