mharris 451f77c
#!/bin/bash
mharris 451f77c
# Copyright (C) 1999 - 2004 Red Hat, Inc. All rights reserved. This
mharris 451f77c
# copyrighted material is made available to anyone wishing to use, modify,
mharris 451f77c
# copy, or redistribute it subject to the terms and conditions of the
mharris 451f77c
# GNU General Public License version 2.
mharris 451f77c
#
mharris 451f77c
# You should have received a copy of the GNU General Public License
mharris 451f77c
# along with this program; if not, write to the Free Software
mharris 451f77c
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
mharris 451f77c
mharris 451f77c
# redirect errors to a file in user's home directory if we can
mharris 451f77c
if [ -z "$GDMSESSION" ]; then
mharris 451f77c
    # GDM redirect output itself in a smarter fashion
mharris 451f77c
    errfile="$HOME/.xsession-errors"
a3b6ec3
    if ( umask 077 && cp /dev/null "$errfile" 2> /dev/null ); then
mharris 451f77c
        chmod 600 "$errfile"
57bed23
        [ -x /sbin/restorecon ] && /sbin/restorecon $errfile
mharris 451f77c
        exec > "$errfile" 2>&1
mharris 451f77c
    else
mharris 451f77c
        errfile=$(mktemp -q /tmp/xses-$USER.XXXXXX)
mharris 451f77c
        if [ $? -eq 0 ]; then
mharris 451f77c
            exec > "$errfile" 2>&1
mharris 451f77c
        fi
mharris 451f77c
    fi
mharris 451f77c
fi
mharris 451f77c
mharris 451f77c
SWITCHDESKPATH=/usr/share/switchdesk
mharris 451f77c
mharris 451f77c
# Mandatorily source xinitrc-common, which is common code shared between the
mharris 451f77c
# Xsession and xinitrc scripts which has been factored out to avoid duplication
mharris 451f77c
. /etc/X11/xinit/xinitrc-common
mharris 451f77c
mharris 451f77c
# This Xsession.d implementation, is intended to obsolte and replace the
mharris 451f77c
# various mechanisms present in the 'case' statement which follows, and to
mharris 451f77c
# eventually be able to easily remove all hard coded window manager specific
mharris 451f77c
# content from this script.  See bug #142260 for additional explanation and
mharris 451f77c
# details.  All window manager rpm packages and desktop environment
mharris 451f77c
# packages should be modified to provide the Xsession.d/Xsession.$wm scripts
mharris 451f77c
# to start themselves up.  In the future, the legacy switchdesk mechanisms
mharris 451f77c
# and hard coded window managers and desktop environments will be removed from
mharris 451f77c
# this script. 
mharris 451f77c
XCLIENTS_D=/etc/X11/xinit/Xclients.d
ae42efc
if [ "$#" -eq 1 ] && [ -x "$XCLIENTS_D/Xclients.$1.sh" ]; then
Adam Tkac c92ca00
    exec -l $SHELL -c "$CK_XINIT_SESSION $SSH_AGENT $XCLIENTS_D/Xclients.$1.sh"
mharris 451f77c
else
mharris 451f77c
# now, we see if xdm/gdm/kdm has asked for a specific environment
mharris 451f77c
case $# in
mharris 451f77c
1)
mharris 451f77c
    if [ -x "$SWITCHDESKPATH/Xclients.$1" ]; then
f676551
       exec -l $SHELL -c "$SWITCHDESKPATH/Xclients.$1";
mharris 451f77c
    fi;
mharris 451f77c
mharris 451f77c
    case "$1" in
00772e3
	failsafe)
00772e3
	    exec -l $SHELL -c "xterm -geometry 80x24-0-0"
00772e3
	    ;;
55e46c3
	gnome|gnome-session)
6f9fbe0
	    # lack of SSH_AGENT is intentional, see #441123.  though
6f9fbe0
	    # the whole thing should really happen in xinitrc.d anyway.
6f9fbe0
	    exec -l $SHELL -c gnome-session
6f9fbe0
	    exec /bin/sh -c "exec -l $SHELL -c \"gnome-session\"" 
00772e3
	    ;;
00772e3
	kde|kde1|kde2)
Adam Tkac c92ca00
	    exec $CK_XINIT_SESSION $SSH_AGENT /bin/sh -c "exec -l $SHELL -c \"startkde\""
00772e3
	    ;;
00772e3
	twm)
mharris 451f77c
        # fall back to twm
Adam Tkac c92ca00
	    exec $CK_XINIT_SESSION $SSH_AGENT /bin/sh -c "exec -l $SHELL -c \"twm\""
00772e3
	    ;;
00772e3
	*)
mharris 451f77c
       # GDM provies either a command line as the first argument or
mharris 451f77c
       # provides 'failsafe', 'default' or 'custom'.  KDM will do the
mharris 451f77c
       # same at some point
00772e3
	    if [ "$1" != "default" -a "$1" != "custom" ]; then
Adam Tkac c92ca00
		exec $CK_XINIT_SESSION $SSH_AGENT /bin/sh -c "exec -l $SHELL -c \"$1\""
00772e3
	    fi
00772e3
	    ;;
mharris 451f77c
    esac
mharris 451f77c
esac
mharris 451f77c
fi
mharris 451f77c
mharris 451f77c
# otherwise, take default action
mharris 451f77c
if [ -x "$HOME/.xsession" ]; then
Adam Tkac c92ca00
    exec -l $SHELL -c "$CK_XINIT_SESSION $SSH_AGENT $HOME/.xsession"
mharris 451f77c
elif [ -x "$HOME/.Xclients" ]; then
Adam Tkac c92ca00
    exec -l $SHELL -c "$CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients"
mharris 451f77c
elif [ -x /etc/X11/xinit/Xclients ]; then
Adam Tkac c92ca00
    exec -l $SHELL -c "$CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients"
mharris 451f77c
else
mharris 451f77c
    # should never get here; failsafe fallback
mharris 451f77c
    exec -l $SHELL -c "xsm"
mharris 451f77c
fi
mharris 451f77c