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