#!/bin/sh

#######################################################
#
#   Configure KDM to register sessions in the same way
#   that GDM and XDM do
#
#######################################################


# session modifications
if [  ! "`grep SESSREG /etc/kde/kdm/Xstartup`" ]
then
       /usr/bin/perl -i.ltsp -p -e '
          if ($_ =~ /^exit 0/ ) {
            print "exec sessreg -a -l \$DISPLAY \$USER\n";
          }
    ' /etc/kde/kdm/Xstartup
fi

# logout modifications
if [ ! "`grep SESSREG /etc/kde/kdm/Xreset`" ]
then
        /usr/bin/perl -i.ltsp -p -e '
            if ($_ =~ /^$/ ) {
              print "\n# Remove session\n" unless $done;
              print "SESSREG=/usr/X11R6/bin/sessreg\n" unless $done;
              print "if [ -x \$SESSREG ] ; then\n" unless $done;
              print "       \$SESSREG -d -w /var/log/wtmp -u /var/run/utmp -x \"\$X_SERVERS\" -h \"\$REMOTE_HOST\" -l \$DISPLAY \$USER\n" unless $done;
              print "fi\n" unless $done;
              $done = "yes";
            }
        ' /etc/kde/kdm/Xreset
fi
