reworked/improved setup files

master
Kebler Network System Administrator 2021-03-09 13:13:23 -08:00
parent 256186376d
commit 5d2ccc7c4f
5 changed files with 69 additions and 36 deletions

View File

@ -1,17 +1,26 @@
#!/bin/bash
# non-interactive shell
([ -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 wide bash.bashrc ---
# [ $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'
# ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && echo ssh remote user || echo local user
# [[ $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 ---------------------
if ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]); then
export SSH_SESSION=true
if ( [[ $SHELL_INTERACTIVE ]] );then
source /etc/profile
else
# Set the initial path
export PATH=/bin:/usr/bin:/usr/local/bin
# set this for access to any shell sources
export BASH_SHELL_BASE=/opt/bash/shell/base
# loading module functions
source $BASH_SHELL_BASE/module.lib
fi
# global debug on or off via debug_on debug_off aliases
# can add this export to any file
#export BASH_DEBUG=true
source $BASH_SHELL_LOAD

View File

@ -1,14 +1,21 @@
#!/bin/bash
# put no script code directly here.
# organize all script code in files /etc/profile.d
# do not add code here.
# organize additional profile 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 -----------
([ -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
@ -20,13 +27,13 @@ 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
# NO_LOGIN_BASHRC=true
if [[ $- == *i* ]]; then # interactive?
[[ ! $SSH_SESSION ]] && echo interactive login shell
if [[ ! $NO_LOGIN_BASHRC ]]; then
# 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
# just set a simple prompt instead
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
@ -38,6 +45,7 @@ if [[ $- == *i* ]]; then # interactive?
unset RED GREEN NORMAL
fi
else
# 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

View File

@ -3,4 +3,4 @@
# echo ".bash_profile sourced at user $USER login"
# only source .bashrc if interactive login shell
[[ $- == *i* ]] && [[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
[[ $SHELL_INTERACTIVE ]] && [[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"

View File

@ -1,7 +1,23 @@
#!/bin/bash
# echo "$USER .bashrc"
# processing user's shell repo if base was loaded
[[ $BASH_SHELL_BASE_LOADED = true ]] && \
export BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} && \
#uncomment these for debugging.
# echo ---- sourcing system .bashrc for user $USER ---
# [[ $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
# env | grep BASH
# echo ---------------------
if ( [[ $SHELL_INTERACTIVE ]] );then
if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then
# echo loading user shell sources
export BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"}
[[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\
echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template
fi
# uncomment to add non-interactive setup/sourcing
# else
# echo non-login and non-interactive
fi
# anything below will be sourced by all shell types (except non-interactive/login)

View File

@ -1,2 +1,2 @@
echo .profile, user $USER
echo "this only is sourced if .bash_profile doesn't exist"
echo "warning: this only is sourced if .bash_profile doesn't exist"