#! /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 &
sleep 3

# Wait for a resonable amount of time (0.0 for Xlib's safe 12s timeout) that
# the X Server starts up, then assume it failed and bail out

checkX -t 0.0
if [ $? -ne 0 ]; then
    exit 1
fi

# If the X Server actually started up, try to set the font path.

xset fp+ /usr/local/share/lyx/fonts
if ! xset -q | grep /usr/local/share/lyx/fonts >/dev/null; then
    xset fp+ /usr/local/share/lyx/fonts
fi

exit
