# /etc/profile:
# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/profile,v 1.17 2003/03/02 22:32:08 azarah Exp $

if [ -e "/etc/profile.env" ]
then
	. /etc/profile.env
fi

# 077 would be more secure, but 022 is generally quite realistic
umask 022

if [ "`/usr/bin/whoami`" = 'root' ]
then
	if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
	then
		export PS1='\[\033[01;31m\]\h \[\033[01;34m\]\W \$ \[\033[00m\]'
	fi
	export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
	if [ "$SHELL" = '/bin/bash' ] || [ "$SHELL" = '/bin/sh' ]
	then
		export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
	fi
	export PATH="/bin:/usr/bin:${PATH}"
fi
unset ROOTPATH

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]
then
	export INPUTRC="/etc/inputrc"
fi

# Extract the value of EDITOR
get_editor() {
	[ ! -f "$1" ] && return
	
	local editor="`gawk '
		/^[[:space:]]*EDITOR[[:space:]]*=/ {

			sub(/^[[:space:]]*EDITOR[[:space:]]*=/, "")
			EDITOR = $0
		}
		
		END { print EDITOR }
	' $1`"

	bash -c "eval echo $editor"
}

if [ -f /etc/rc.conf -a -n "`get_editor /etc/rc.conf`" ]
then
	export EDITOR="`get_editor /etc/rc.conf`"

elif [ -f /etc/conf.d/basic -a -n "`get_editor /etc/conf.d/basic`" ]
then
	export EDITOR="`get_editor /etc/conf.d/basic`"

else
	export EDITOR="/bin/nano"
fi

# We do not need this floating around
unset get_editor

