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