#!/bin/bash

#--------------------------------------------------------------------
#
# This script is intended to be invoked from /etc/rc.d/rc.local with:
#
#    /bin/nice -n -5 /usr/local/bin/start-tclkeymon &> /dev/null &
#
# This script will wait for a non-root login at the console, and will
# then start tclkeymon.  If tclkeymon exits, it will be automatically 
# restarted after 10 seconds.
#
#--------------------------------------------------------------------

if [ "$DISPLAY" == "" ]
then
   export DISPLAY=:0.0
fi
while true
do
  cons=`/bin/ls -l /dev/console | /usr/bin/awk '{print $3}'`
  if [ "$cons" == "root" ]
  then
     echo "`date` tclkeymon waiting for X login" > /var/log/tclkeymon.log
     /bin/sleep 10
  else
     /bin/nice -n -5 /usr/local/bin/tclkeymon &> /var/log/tclkeymon.log
     echo "`date` tclkeymon restarting" >> /var/log/tclkeymon.log
     /bin/sleep 10
  fi
done
