#!/bin/sh
# $XConsortium: Xsession /main/10 1995/12/18 18:21:28 gildea $
# $Id: Xsession,v 1.6 1998/09/29 16:49:02 bieker Exp $

# modified for COL 2.2 by Matthias Hoelzer-Kluepfel

wm=$1

if [ -r "$HOME/.profile" ]; then
	. "$HOME/.profile"
else
	[ -r /etc/config.d/shells/bashrc ] && . /etc/config.d/shells/bashrc
	[ -r /etc/config.d/shells/profile ] && . /etc/config.d/shells/profile
fi

# redirect errors to a file in user's home directory if we can
for errfile in "$HOME/.xsession-errors" "${TMPDIR-/tmp}/xses-$USER" "/tmp/xses-$USER"
do
	if ( cp /dev/null "$errfile" 2> /dev/null )
	then
		chmod 600 "$errfile"
		exec > "$errfile" 2>&1
		break
	fi
done

if [ -n "$wm" ]; then
	case $wm in
	kde)	[ -z "$KDEDIR" ] && {
			KDEDIR=/opt/kde; export KDEDIR
		PATH=$KDEDIR/bin:$PATH
		}
		exec /etc/X11/xinit/kdeinitrc
		;;

	failsafe)
		exec xterm -geometry 80x24-0-0
		;;
	esac
fi

# start windowmanager
which "$wm" && exec "$wm"

# windowmanager not found, tell user
message="Sorry, $wm not found."
if [ -x /opt/kde/bin/kdialog ]; then
  exec /opt/kde/bin/kdialog --msgbox "$message"
else
  exec xmessage -center "$message"
fi
