#! /bin/bash

mv /var/log/groovix/inactivity-warn.log.6 /var/log/groovix/inactivity-warn.log.7
mv /var/log/groovix/inactivity-warn.log.5 /var/log/groovix/inactivity-warn.log.6
mv /var/log/groovix/inactivity-warn.log.4 /var/log/groovix/inactivity-warn.log.5
mv /var/log/groovix/inactivity-warn.log.3 /var/log/groovix/inactivity-warn.log.4
mv /var/log/groovix/inactivity-warn.log.2 /var/log/groovix/inactivity-warn.log.3
mv /var/log/groovix/inactivity-warn.log.1 /var/log/groovix/inactivity-warn.log.2
mv /var/log/groovix/inactivity-warn.log /var/log/groovix/inactivity-warn.log.1

#log everything
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/var/log/groovix/inactivity-warn.log 2>&1

. /usr/share/groovix/global.conf

# per user settings
echo checking /etc/groovix/peruser/$USER/groovix.conf
if [ -e /etc/groovix/peruser/$USER/groovix.conf ] ; then
        . /etc/groovix/peruser/$USER/groovix.conf
fi


date

#if we're not dirty, no need to logout ! 
#any activity will start xautolock counting again for later
groovix-no-x-activity-since-login
if [ $? -eq 0 ] ; then
	#no activity yet
	echo no x activity detected since login
else
	echo x activity detected since login

	#zenity --warning --title 'WARNING: Session Timeout' --text "WARNING: This session has been inactive and will be closed in $GX_LOGOUT_NOTIFY_TIME seconds. \n\nYou must move the mouse or type something to extend your session." &
	#start an imminent logoff, 
	# but if they move the mouse or keyboard at all they will NOT be kicked off and we'll kill that zenity box
	groovix-delayed-session-exit $GX_LOGOUT_NOTIFY_TIME

fi
