#!/bin/sh
/usr/X11R6/bin/sessreg -a -w /var/log/wtmp -u /var/run/utmp -l $DISPLAY $USER

# if [ `ps -C xscreensaver -o cmd=` ]; then
	/usr/bin/killall -e /usr/X11R6/bin/xscreensaver
# fi

# Set the PROFILE_USER environment variable.
PROFILE_USER=$USER
if [ -f /tmp/profile/machine/IBMSetupLogin ]; then
   . /tmp/profile/machine/IBMSetupLogin
   if [ "$AutomaticLoginEnable" = "true" ]; then
      if [ -n "$AutomaticLoginProfileUser" ]; then
         PROFILE_USER=$AutomaticLoginProfileUser
      fi
   fi
fi
# Force PROFILE_USER to uppercase since Windows can't handle multiple cases.
# PROFILE_USER=`echo $PROFILE_USER | tr '[a-z]' '[A-Z]'`
export PROFILE_USER

. /etc/rc.d/rc.IBM_NS.env

# Source the profile functions.
. /IBM/bin/profile.functions
profile_init user

# Cache profiles to flash card -- if configured.
/IBM/bin/cache_profiles.sh user


# Source $LANG setup code common to all session scripts.
. /etc/gdm/Sessions/Common/SessionLang

# Source environment variable setup code common to all session scripts.
. /etc/gdm/Sessions/Common/SessionEnvironmentVariables


IBMSetupMouseSettings=`profile_file IBMSetupMouseSettings`
if [ -n "$IBMSetupMouseSettings" ]; then
   . $IBMSetupMouseSettings
   if [ "$LeftHandedMouse" = "1" ]; then
      /usr/X11R6/bin/xmodmap -e "pointer = 3 2 1"
   fi
   if [ "$CustomMouseSpeed" = "1" ]; then
      xset m $MouseAcceleration $MouseThreshold
   fi
fi

# Indicate to snmp who just logged in     
echo $USER > /tmp/snmp/user
# Send a login trap, passing in the new user

if [ -f /bin/nice ]; then
  /bin/nice -n +5 /IBM/bin/gentrap 6 1 '/etc/gdm/PreSession/Default' 200 $USER &
else
  /IBM/bin/gentrap 6 1 '/etc/gdm/PreSession/Default' 200 $USER &
fi



# Copy the /etc/motd file to /tmp/IBM/Messages, if needed.
if [ -n "$NETVISTA_MOTD_FILE" -a -f "$NETVISTA_MOTD_FILE" ]; then
   mkdir -p /tmp/IBM/Messages
   cp $NETVISTA_MOTD_FILE /tmp/IBM/Messages
fi


# ---------------------------------------------------------------------------
# Create the IBMSetup "Flags" file which toggles setup functions depending
# on the state of the file system.
# ---------------------------------------------------------------------------
rm -rf /tmp/IBMSetup/Flags
mkdir -p /tmp/IBMSetup
chmod 600 /tmp/IBMSetup

echo "save_boot_profiles=`/IBM/bin/can_save_boot_profiles.sh`" > /tmp/IBMSetup/Flags

chmod 600 /tmp/IBMSetup/Flags



/IBM/bin/ibmprintcapmerge
