2022-03-01 22:44:26 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# do not add code here for non-interative login shell
|
|
|
|
# rather put additional non-interactive profile script code in files in /etc/profile.d
|
|
|
|
|
|
|
|
# this files is sourced for all login shells and also interactive non-login shells via /etc/bash.bashrc
|
|
|
|
# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
|
|
|
|
|
|
|
|
# interactive non-login and login shells will call the BASH_SHELL_LOAD script below
|
|
|
|
# non-interative login shells only source /etc/profile.d
|
|
|
|
# in profile.d is 03-startup.sh which will call
|
|
|
|
# any of the scripts in a repo's startup subdirectory
|
|
|
|
# non-interactive non-login shells are not handled here only via /etc/bash.bashrc
|
|
|
|
# interactive login
|
2020-11-13 10:25:04 -08:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# uncomment for debugging non-interactive login shell, i.e. $ . /etc/profile
|
|
|
|
#unset SHELL_INTERACTIVE
|
2021-03-09 13:13:23 -08:00
|
|
|
|
|
|
|
#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 ---------------------
|
2020-11-13 10:25:04 -08:00
|
|
|
|
|
|
|
# Set the initial path
|
|
|
|
export PATH=/bin:/usr/bin:/usr/local/bin
|
|
|
|
# set directory for base shell repo
|
2020-11-23 12:21:20 -08:00
|
|
|
export BASH_SHELL_BASE=THISWILLCHANGEDBYDEPLOYSCRIPT
|
2020-11-13 10:25:04 -08:00
|
|
|
# now bootstrap by souring the shell repo envinroment
|
2021-01-30 11:58:19 -08:00
|
|
|
source $BASH_SHELL_BASE/shell.env
|
2022-03-01 22:44:26 -08:00
|
|
|
# set $BASH_SAFE_MODE=true in shell.env to disable UCI interactive shell from loading
|
|
|
|
# TODO see if $NO_BASH_SHELL_SSH=true in user or host directory (at the remote machine)
|
|
|
|
# if so don't source the load command below and make just a simple prompt.
|
2021-03-09 13:13:23 -08:00
|
|
|
if [[ $SHELL_INTERACTIVE ]]; then
|
2022-03-01 22:44:26 -08:00
|
|
|
if [[ ! $BASH_SAFE_MODE ]]; then
|
2020-11-23 15:14:18 -08:00
|
|
|
# echo interactive shell loading $BASH_SHELL_LOAD
|
2020-11-13 10:25:04 -08:00
|
|
|
source "$BASH_SHELL_LOAD"
|
|
|
|
else
|
2022-03-01 22:44:26 -08:00
|
|
|
# safe mode
|
2021-03-09 13:13:23 -08:00
|
|
|
# just set a simple prompt instead
|
2020-11-13 10:25:04 -08:00
|
|
|
NORMAL="\[\e[0m\]"
|
|
|
|
RED="\[\e[1;31m\]"
|
|
|
|
GREEN="\[\e[1;32m\]"
|
2022-03-01 22:44:26 -08:00
|
|
|
YELLOW='\e[1;33m'
|
2020-11-13 10:25:04 -08:00
|
|
|
if [[ $EUID == 0 ]] ; then
|
2022-03-01 22:44:26 -08:00
|
|
|
PS1="${YELLOW}SAFE:$RED\u [ $NORMAL\w$RED ]# $NORMAL"
|
2020-11-13 10:25:04 -08:00
|
|
|
else
|
2022-03-01 22:44:26 -08:00
|
|
|
PS1="${YELLOW}SAFE:$GREEN \u [ $NORMAL\w$GREEN ]\$ $NORMAL"
|
2020-11-13 10:25:04 -08:00
|
|
|
fi
|
2022-03-01 22:44:26 -08:00
|
|
|
unset RED GREEN NORMAL YELLOW
|
2020-11-13 10:25:04 -08:00
|
|
|
fi
|
|
|
|
else
|
2021-03-09 13:13:23 -08:00
|
|
|
# this is non-interactive login (e.g. at user machine login)
|
2020-11-23 15:14:18 -08:00
|
|
|
if [[ $EUID -ne 0 ]] && [[ ! $SSH_SESSION ]]; then
|
2023-12-20 17:21:48 -08:00
|
|
|
export LOGIN_LOG=$HOME/.logs/login.log
|
|
|
|
mkdir -p $HOME/.logs
|
2020-11-18 15:32:09 -08:00
|
|
|
touch $LOGIN_LOG
|
|
|
|
llog () {
|
2023-01-21 08:18:40 -08:00
|
|
|
echo "$@" >> $LOGIN_LOG 2>&1
|
2020-11-18 15:32:09 -08:00
|
|
|
}
|
2023-01-21 08:18:40 -08:00
|
|
|
export -f llog
|
2020-11-18 15:32:09 -08:00
|
|
|
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
|
2020-11-13 10:25:04 -08:00
|
|
|
fi
|