All pastes #937263 Raw Edit

Mine

public text v1 · immutable
·published 2008-03-10 22:44 UTC
rendered paste body
#!/bin/bash -login
#
# $Id: Xsession,v 1.6 2006/01/07 19:27:04 ldv Exp $
# Copyright (C) 2002-2006  Dmitry V. Levin <ldv@altlinux.org>
#
# Traditional X session start script.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

PROG="${0##*/}"

if [ -z "$DISPLAY" ]; then
        echo "$PROG: \$DISPLAY undefined." >&2
        exit 1
fi

# Emulate which(1) internally.
absolute()
{
        local WHICH

        [ -n "$1" ] || return 1
        WHICH="$(type -p "$1")" || return 1
        [ "$WHICH" != "${WHICH##/}" ] || return 1
        [ -x "$WHICH" ] || return 1

        printf %s "$WHICH"
}

SourceIfNotEmpty()
{
        local f="$1"
        shift
        [ -s "$f" ] && . "$f" "$@"
}

RunIfExecutable()
{
        local f="$1"
        shift
        f="$(absolute "$f")" && [ -x "$f" ] && "$f" "$@"
}

ExecIfExecutable()
{
        local f="$1"
        shift
        f="$(absolute "$f")" && [ -x "$f" ] && exec "$f" "$@"
}

f="$HOME/.xsession-errors"
[ -z "${DISPLAY##:*}" ] && f="$f$DISPLAY" || f="$f-$DISPLAY"

# Redirect errors to a file.
for errfile in "$f" "$HOME/.xsession-errors"; do
        if install -m600 /dev/null "$errfile" 2>/dev/null; then
                exec &>"$errfile"
                break
        fi
done

unset f

echo "Running $PROG[$$] $*"

if [ $# -ge 1 ]; then
        # Clean up after xbanner.
        RunIfExecutable freetemp
else
        # ALT default background and cursor.
        xsetroot -solid "#666699"
        xsetroot -cursor_name left_ptr
fi

if [ -n "$LANGUAGE" ]; then
        try_lang="$LANGUAGE"
elif [ -n "$LANG" ]; then
        try_lang="$LANG"
else
        try_lang=
fi

Xrdb()
{
        if [ -s "$1" ]; then
                xrdb -merge "$1"
                return 0
        else
                return 1
        fi
}

MergeResources()
{
        local f
        for f in "$@"; do
                Xrdb "$f"
                local found=
                local n
                for n in `printf %s "$try_lang" |tr : ' '`; do
                        n1="${n%.*}"
                        n2="${n1%_*}"
                        Xrdb "$f.$n2" && found=1
                        Xrdb "$f.$n1" && found=1
                        Xrdb "$f.$n" && found=1
                        [ -z "$found" ] || break
                done
        done
}

# Merge in defaults and keymaps.
MergeResources /etc/X11/Xresources "$HOME/.Xresources" "$HOME/.Xdefaults"

/etc/X11/xinit/xrootwarn || exit

TryXBrowser()
{
        local n
        for n in "$@"; do
                if n=`absolute "$n"`; then
                        export BROWSER="$n"
                        break
                fi
        done
        return 0
}

TryTextBrowser()
{
        local n
        for n in "$@"; do
                if n=`absolute "$n"`; then
                        export BROWSER="xvt -e $n"
                        break
                fi
        done
        return 0
}

# We need to set default browser.
# Window manager may redefine this setting.
if [ -z "$BROWSER" ] || [ ! -x "$BROWSER" ]; then
        TryXBrowser xbrowser mozilla firefox konqueror
fi

if [ -z "$BROWSER" ] || [ ! -x "$BROWSER" ]; then
        TryTextBrowser browser links lynx
fi

if [ -z "$BROWSER" ] || [ ! -x "$BROWSER" ]; then
        export BROWSER=
fi

export HELP_BROWSER="$BROWSER"

# Source shell scripts from system /etc/X11/profile.d/
for f in /etc/X11/profile.d/*.sh; do
        # Don't run *.rpm* and *~ scripts
        [ "${f%.rpm*}" == "$f" -a "${f%\~}" == "$f" ] || continue

        SourceIfNotEmpty "$f" "$@"
done

# Source shell scripts from user ~/.xprofile
SourceIfNotEmpty "$HOME"/.xprofile "$@"

# Run system scripts from /etc/X11/xinit.d/
for f in /etc/X11/xinit.d/*; do
        # Don't run *.rpm* and *~ scripts
        [ "${f%.rpm*}" == "$f" -a "${f%\~}" == "$f" ] || continue

        if [ -x "$f" ]; then
                "$f" &
        fi
done

# Run user scripts from ~/.xsession.d/
for f in "$HOME"/.xsession.d/*; do
        # Don't run *.rpm* and *~ scripts
        [ "${f%.rpm*}" == "$f" -a "${f%\~}" == "$f" ] || continue

        if [ -x "$f" ]; then
                "$f" &
        fi
done

unset f

RunIfExecutable /etc/X11/xinit/fixkeyboard
RunIfExecutable /etc/X11/xinit/XIM

# See if desktop manager has asked for a specific environment.
if [ $# -ge 1 ]; then
        exec runwm "$@"
else
        # Try user defined action.
        ExecIfExecutable "$HOME/.xsession"
        ExecIfExecutable "$HOME/.Xclients"

        # Try WM Selector.
        ExecIfExecutable wm-select

        # Try WM Manager.
        ExecIfExecutable wmselect

        # Try default from runwm.
        exec runwm default
fi