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

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

# Only run if user doesn't prevent it:

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

if [ $DEBUG = 1 ]; then
    if [ ! -d /tmp/sysprofile ]; then
        mkdir /tmp/sysprofile
        chmod 333 /tmp/sysprofile
        touch /tmp/sysprofile/$USER
        chmod 600 /tmp/sysprofile/$USER
    fi
fi

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

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

# Then run any existing user defined scripts:

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