#!/bin/bash

export PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin


echo $0 | grep groovix-session-setup
if [ $? -eq 0 ] ; then
	LOG=session-setup
	SDIR=/etc/groovix/session-setup.d
else

	# session cleanup gets triggered by lightdm even on just a failed login!  dont run groovix session cleanup in that case
	if [ -e /var/lib/groovix/session-info/session-setup-started ] ; then

		LOG=session-cleanup
		SDIR=/etc/groovix/session-cleanup.d

	else
		echo "dont need to run groovix cleanup"
		exit 0
	fi
fi



#log everything
mv /var/log/groovix/$LOG.log.6 /var/log/groovix/$LOG.log.7
mv /var/log/groovix/$LOG.log.5 /var/log/groovix/$LOG.log.6
mv /var/log/groovix/$LOG.log.4 /var/log/groovix/$LOG.log.5
mv /var/log/groovix/$LOG.log.3 /var/log/groovix/$LOG.log.4
mv /var/log/groovix/$LOG.log.2 /var/log/groovix/$LOG.log.3
mv /var/log/groovix/$LOG.log.1 /var/log/groovix/$LOG.log.2
mv /var/log/groovix/$LOG.log /var/log/groovix/$LOG.log.1
exec 3>&1 4>&2
trap 'exec 2>&4 1>&3' 0 1 2 3
exec 1>/var/log/groovix/$LOG.log 2>&1


#many Groovix scripts refer to GUNAME
GUNAME=$USER

echo GKDEBUG starting $0 at `date`

. /usr/share/groovix/global.conf

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

#do session things that need to be started as root before and after actual session:
# i.e. cmon/pacrez/screensaver/inactivity stop/start

#note: these scripts are explicitly called with bash, so no need
# to include #!/bin/bash in each one
#also they do not need to be executable, they are not meant to be called on their own
# note that any variables set in each sub script will not be visible to sibling scripts
	# if we want that then maybe rewrite groovix-source-bash-parts to just concat
	# then all together and execute as one big script

. /usr/bin/groovix-source-bash-parts $SDIR ; #old# 2>&1 >> /var/log/groovix/session-root.log


