This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues/pull-requests.
bash-shell-base/setup/etc/profile

71 lines
2.2 KiB
Plaintext
Raw Permalink Normal View History

2021-03-09 13:13:23 -08:00
#!/bin/bash
2021-03-09 13:13:23 -08:00
# do not add code here.
# organize additional profile script code in files /etc/profile.d
2021-03-09 13:13:23 -08:00
([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true
[[ $- == *i* ]] && export SHELL_INTERACTIVE=true
shopt -q login_shell && export SHELL_LOGIN=true
[ $EUID -eq 0 ] && export USER_ROOT=true
#uncomment these for debugging.
# echo ---- sourcing system /etc/profile ---
# [[ $USER_ROOT ]] && echo 'Root User' || echo 'Non Root User'
# [[ $SHELL_INTERACTIVE ]] && echo 'Interactive' || echo 'Not interactive'
# [[ $SHELL_LOGIN ]] && echo 'Login shell' || echo 'Not login shell'
# [[ $SSH_SESSION ]] && echo ssh remote user || echo local user
# echo ---------------------
# main /etc/profile loaded for all logins
# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
# Set the initial path
export PATH=/bin:/usr/bin:/usr/local/bin
# set directory for base shell repo
export BASH_SHELL_BASE=THISWILLCHANGEDBYDEPLOYSCRIPT
# now bootstrap by souring the shell repo envinroment
source $BASH_SHELL_BASE/shell.env
# uncomment to NOT load the BASH SHELL Repos for interactive login shell
2021-03-09 13:13:23 -08:00
# NO_BASH_SHELL=true
if [[ $SHELL_INTERACTIVE ]]; then
if [[ ! $NO_BASH_SHELL ]]; then
# echo interactive shell loading $BASH_SHELL_LOAD
source "$BASH_SHELL_LOAD"
else
2021-03-09 13:13:23 -08:00
# just set a simple prompt instead
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
2021-03-09 13:13:23 -08:00
# this is non-interactive login (e.g. at user machine login)
if [[ $EUID -ne 0 ]] && [[ ! $SSH_SESSION ]]; then
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
llog "$(env | grep BASH)"
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
fi