#!/bin/bash -login
# Copyright (c) 1999, 2000, 2001 Red Hat, Inc.
#                           2002 Project Vine
#                      modified by Jun Nishii <jun@vinelinux.org>
#                            Time-stamp: <02/03/25 10:44:22 vine>

#
# cleanup xdm resources
#
        /usr/X11R6/bin/xrdb -load /dev/null

#
# Clean up message logs
#
msgfile="$HOME/.xwm.msgs"
cp -f /dev/null $msgfile

#
# redirect errors to a file in user's home directory if we can
#
errfile="$HOME/.xsession-errors"
if cp /dev/null "$errfile" 2> /dev/null ; then
    chmod 600 "$errfile"
    exec > "$errfile" 2>&1
else
    errfile=`mktemp -q /tmp/xses-$USER.XXXXXX`
    if [ $? -eq 0 ]; then
        exec > "$errfile" 2>&1
    fi
fi

#
# check PATH
#
if ! printenv PATH | grep -q /usr/X11R6/bin
then
	PATH="${PATH}":/usr/X11R6/bin
fi

#
# run all system xinitrc shell scripts.
#
for i in /etc/X11/xinit/xinitrc.d/* ; do
    if [ -x "$i" ]; then
	echo "loading $i..." >> $msgfile
	. "$i"
    fi
done

#
# Set font path for Xpmac/XFree86-4.0-mga-r128-v2 server (ppc)
#
if [ -L /etc/X11/X ] ; then
    if [ `/bin/ls -l /etc/X11/X | grep -c Xpmac` -eq 1 ] || \
       [ `/bin/ls -l /etc/X11/X | grep -c mga-r128` -eq 1 ]; then
        if [ -f /usr/X11R6/lib/X11/fonts/TrueType/fonts.dir ] ; then
            xset +fp /usr/X11/lib/X11/fonts/TrueType
        fi
        xset +fp unix/:-1
        xset fp rehash
    fi
fi

#
# these files are left sitting around by TheNextLevel.
#
rm -f /tmp/fvwmrc* 2>/dev/null

# now, we see if xdm/gdm/kdm has asked for a specific environment
case $# in
1)
    echo $1 > $HOME/.wm_style
esac

#
# otherwise, take default action
#
if [ -x "$HOME/.xsession" ]; then
    exec "$HOME/.xsession"
elif [ -x "$HOME/.Xclients" ]; then
    exec "$HOME/.Xclients"
elif [ -x /etc/X11/xinit/Xclients ]; then
    exec "/etc/X11/xinit/Xclients"
else
    # should never get here; failsafe fallback
    exec "xsm"
fi
