#!/bin/bash -x
#
# on the first run check the mount mode of the mount table
# and exit if root is mounted in text mode
#
if ! test -f "$HOME/.kde_mountchecked"; then
	if test -n "`mount | grep ' / .*textmode'`" ; then
		CYGROOT=`cygpath -aw / | sed 's,\\\,\/,g'`
		echo "It seems that you have a text mounted root, which does not work with kde."
		echo "You should run the following command to fix this problem: "
		echo "cd $CYGROOT/bin "
		echo "umount -s /"
		echo "mount -s -b $CYGROOT /"
		exit 1
	fi
	touch $HOME/.kde_mountchecked
fi
#
# start ipc-daemon2 if not already started
# and save the pid for killing later
#
ipc-daemon2 &
IPC_PID=$!

#
# set client and server relating options depending on the display mode
#
case $1 in
	-multiwindow | -rootless | -fullscreen)
		client_opt=$1
		server_opt=$1
		;;
	*)
		client_opt=$1
		server_opt=
		;;
esac

#
# start xserver and kde
#
xinit /opt/kde3/bin/startkde $client_opt -- /usr/X11R6/bin/XWin :0 -noreset -ac -nowinkill $server_opt

# kill ipc-daemon2 if started above
# if ipc-daemon2 was started out of this script, IPC_PID contains the 
# pid of the above started ipc-daemon2 instance, which kill itself, so the
# following kill does have any affect like expected. 
#
kill -15 $IPC_PID >/dev/null 2>&1
