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