shell-base/setup/etc/profile
David Kebler 0ac5906eee refactor the way the module library is loaded
added startup script callable from profile.d
renamed setup.sh to load.sh
added rsync copy function cprs
added shell.env that is called by /etc/profile to set up access to this  and related repos
2020-11-13 10:25:04 -08:00

62 lines
1.6 KiB
Bash

#!/bin/bash
# put no script code directly here.
# organize all script code in files /etc/profile.d
# uncomment for debugging
# echo ---- system profile /etc/profile sourced at login ----
# [ $EUID -eq 0 ] && echo 'Root User' || echo 'Non Root User'
# [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
# shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
# echo -----------
# main /etc/profile loaded for all logins
# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
export LOGIN_LOG=$HOME/logs/login.log
mkdir -p $HOME/logs
touch $LOGIN_LOG
llog () {
echo "$@" 2>&1 | tee -a $LOGIN_LOG
}
export -f llog
# Set the initial path
export PATH=/bin:/usr/bin:/usr/local/bin
# set directory for base shell repo
export BASH_SHELL_BASE=/opt/bash/shell/base # where
# now bootstrap by souring the shell repo envinroment
. $BASH_SHELL_BASE/shell.env
llog "$(env | grep BASH)"
if [[ $- == *i* ]]; then # interactive?
echo interactive login shell
if [[ ! $NO_LOGIN_BASHRC ]]; then
echo loading $BASH_SHELL_LOAD
source "$BASH_SHELL_LOAD"
else
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
unset RED GREEN NORMAL
fi
else
echo "$(date)" > $LOGIN_LOG
llog "non-interactive login shell for $USER"
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
llog "sourcing $i"
source $i
fi
done
unset i
fi
fi