From 5d2ccc7c4f25926ca09ba381193bb8f4a68cb030 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Tue, 9 Mar 2021 13:13:23 -0800 Subject: [PATCH] reworked/improved setup files --- setup/etc/bash.bashrc | 39 ++++++++++++++++++++++++--------------- setup/etc/profile | 34 +++++++++++++++++++++------------- setup/user/.bash_profile | 2 +- setup/user/.bashrc | 28 ++++++++++++++++++++++------ setup/user/.profile | 2 +- 5 files changed, 69 insertions(+), 36 deletions(-) diff --git a/setup/etc/bash.bashrc b/setup/etc/bash.bashrc index afeb750..bcf7522 100644 --- a/setup/etc/bash.bashrc +++ b/setup/etc/bash.bashrc @@ -1,17 +1,26 @@ #!/bin/bash -# 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 -# echo --------------------- +# non-interactive shell -if ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]); then - export SSH_SESSION=true - source /etc/profile -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 +([ -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 --- +# [[ $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 ( [[ $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 \ No newline at end of file diff --git a/setup/etc/profile b/setup/etc/profile index 682e317..09a0b09 100644 --- a/setup/etc/profile +++ b/setup/etc/profile @@ -1,14 +1,21 @@ -#!/bin/bash + #!/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 diff --git a/setup/user/.bash_profile b/setup/user/.bash_profile index 67da5f5..684b513 100644 --- a/setup/user/.bash_profile +++ b/setup/user/.bash_profile @@ -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" \ No newline at end of file diff --git a/setup/user/.bashrc b/setup/user/.bashrc index 490d279..9ac9cbc 100644 --- a/setup/user/.bashrc +++ b/setup/user/.bashrc @@ -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"} && \ -[[ -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 +#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) diff --git a/setup/user/.profile b/setup/user/.profile index 21f7625..ee76ceb 100644 --- a/setup/user/.profile +++ b/setup/user/.profile @@ -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" \ No newline at end of file