#!/bin/sh
#
# Note that any setup should come before the sessreg command as
# that must be 'exec'ed for the pid to be correct (sessreg uses the parent
# pid)
#
# Note that output goes into the .xsession-errors file for easy debugging
#
# sessreg is installed in /usr/lib/X11/xdm on AIX
PATH=/usr/lib/X11/xdm:/usr/bin/X11:/usr/X11R6/bin:/opt/X11R6/bin:$PATH:/bin:/usr/bin

# AIX which is not suitable for Linux/Gnome/gdm  - use ksh whence builtin
XSETROOT=`whence xsetroot 2>/dev/null`
if [ x$XSETROOT != x ] ; then
	$XSETROOT -cursor_name left_ptr -solid "#363047"
fi

# use same strategy as /usr/lib/X11/xdm/GiveConsole
PORT=`echo $DISPLAY | /usr/bin/sed "s/\./_/g" | /usr/bin/sed "s/:/_/g" | /usr/bin/cut -c1-8`


# AIX which is not suitable for Linux/Gnome/gdm  - use ksh whence builtin
SESSREG=`whence sessreg 2>/dev/null`

if [ x$SESSREG = x ] ; then
# some output for easy debugging
echo "$0: could not find the sessreg utility, cannot update wtmp and utmp"
exit 0
fi


if [ -n "$PORT" ]; then
    # Create a fake device for the gdm login port.
    # This makes finger happy.
    if [ ! -d /dev/gdm ]; then
        /usr/bin/mkdir /dev/gdm
        /usr/bin/chmod 755 /dev/gdm
    fi
    if [ -f /dev/gdm/$PORT ]; then
        /usr/bin/rm /dev/gdm/$PORT
    fi
    /usr/bin/touch /dev/gdm/$PORT
    /usr/bin/chmod 644 /dev/gdm/$PORT

    # Extract the hostname (if present) from the DISPLAY name.
    HOST=`echo $DISPLAY | /usr/bin/cut -d":" -f1`

    # Use sessreg to add the /etc/utmp and /usr/adm/wtmp entries
    # for this login session.
    # use same strategy as /usr/lib/X11/xdm/TakeConsole
    if [ -n "$HOST" ]; then
        $SESSREG -a -l gdm/$PORT -h $HOST $USER
    else
        $SESSREG -a -l gdm/$PORT $USER
    fi
fi

