# This script first checks for the existence of "$HOME/.nosyslogout"
# and simply quits if it exists.  If it doesn't exist it further checks 
# for the directory "/etc/syslogout.d" which contains all configuraton 
# scripts to execute.  If the latter doesn't exist it just quits without
# any unnecessary complaints.

# Set SYSDEBUG=1 for debugging:
#SYSDEBUG=1
SYSDEBUG=0

# Only run if user doesn't prevent it:

if [ ! -f $HOME/.nosyslogout ]; then

if [ "$SYSDEBUG" = 1 ]; then 
    if [ ! -d /var/tmp/syslogout ]; then
        mkdir -m 1777 /var/tmp/syslogout
        touch /var/tmp/syslogout/$USER
        chmod 600 /var/tmp/syslogout/$USER
    fi
fi

# First run common system wide scripts if no 
# user defined version exists:

    if [ -d /etc/syslogout.d ]; then
	for i in `cd /etc/syslogout.d && echo *.bash` 
    	do
    	    if [ ! -f $HOME/.syslogout.d/$i ]; then
		. /etc/syslogout.d/$i
	    fi
        done
    fi

# Then run any existing user defined scripts:

    if [ -d $HOME/.syslogout.d ]; then
	for i in `cd $HOME/.syslogout.d && echo *.bash` 
    	do
	    . $HOME/.syslogout.d/$i
        done
    fi
fi

