#!/bin/sh
# Make sure a given user do not log into the same computer twice.
# When this is done on an LTSP server, the KDE configuration is likely
# to be destroyed.
#

# debug=1
log() {
    if [ "$debug" ] ; then
        echo "$@"
    fi
}

limit_logins()
{
    num=1
    numps=0
    u=$LOGNAME
    # Do not try to limit the root user
    if [ "$u" != "root" ] ; then
	num=`who | cut -d" " -f1 | grep "^$LOGNAME\$" | wc -l`
    fi

    log "Found $num connections for user $LOGNAME"

    if [ "$num" -gt 1 ] ; then
	numps=`ps -eu "$LOGNAME" | grep -v -e sleep -e COMMAND|wc -l`
	num=`expr $numps + 1`

    fi
    if [ $num -gt 1 ] ; then
	xmessage -buttons Understood:0 -timeout 30 -center \
	    "You are not allowed to login at more than _one_ thinclient simultaneously."
	exit 1
    fi
}

# Only enable this if the flag file exists.  When the code is tested
# and found to work fine, we can enable it for everyone. [pere 2003-02-21]
# To enable this script you must create an empty file with the command
# touch /etc/debian-edu/limit-logins
# [klaus 2003-09-06]

if [ -f /etc/debian-edu/limit-logins ] ; then
    limit_logins
fi
