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