set default user subdirectory to .shell

get BASH_SHELL_BASE in both profile and bash.bashrc
master
Kebler Network System Administrator 2021-12-29 21:09:36 -08:00
parent 75297c7cdb
commit a15a290328
9 changed files with 17 additions and 28 deletions

View File

@ -9,14 +9,6 @@ Clone to a directory
`git clone https://git.kebler.net/bashrc <repo path>` suggestion: /opt/shell/base `git clone https://git.kebler.net/bashrc <repo path>` suggestion: /opt/shell/base
now edit your `~/.bashrc` with nano or other available editor
add this
```
# BASH_SHELL is a common parent directory that should be set in /etc/bash.bashrc
export BASH_SHELL_REPO=<repo path>/setup.
source $BASH_SHELL_REPO/setup.sh
```
The idea is to keep the .bashrc file completely clean and manage this repo instead The idea is to keep the .bashrc file completely clean and manage this repo instead
so you should really find a home for all the existing content of your .bashrc file within the repo so you should really find a home for all the existing content of your .bashrc file within the repo
@ -31,13 +23,13 @@ if you include any of these environment variables all files in there directories
# unless below specific directories are set # unless below specific directories are set
# shell files are sourced in this order # shell files are sourced in this order
# sourced via /etc/bash.bashrc so for all machine users # sourced via /etc/bash.bashrc so for all machine users
# $BASH_SHELL_BASE # this MUST be set in /etc/bash.bashrc # $BASH_SHELL_BASE # this is set in /etc/bash.bashrc and etc/profile via the deploy script
# $BASH_SHELL_NETWORK/all # $BASH_SHELL_NETWORK/all
# $BASH_SHELL_NETWORK/$NETWORKNAME # $BASH_SHELL_NETWORK/$NETWORKNAME
# $BASH_SHELL_HOST/all # $BASH_SHELL_HOST/all
# $BASH_SHELL_HOST/<hostname> # $BASH_SHELL_HOST/<hostname>
# sourced via $HOME/.bashrc # sourced via $HOME/.bashrc
# $HOME/shell or $HOME/BASH_SHELL_USER # $HOME/.shell or $HOME/BASH_SHELL_USER
# within each of those directories if setup.sh exits it will be run # within each of those directories if setup.sh exits it will be run
# otherwise files will be sourced exactly like in the base # otherwise files will be sourced exactly like in the base
@ -52,7 +44,7 @@ export BASH_SHELL_NETWORK=$BASH_SHELL/network
# will use $BASH_SHELL_HOST/<hostname> unless specifically set # will use $BASH_SHELL_HOST/<hostname> unless specifically set
export BASH_SHELL_HOST=$BASH_SHELL/host export BASH_SHELL_HOST=$BASH_SHELL/host
# by default SHELL sources will be looked for under $HOME/bash/shell # by default SHELL sources will be looked for under $HOME/.shell
# but can be user set below to $HOME/$BASH_SHELL_USER # but can be user set below to $HOME/$BASH_SHELL_USER
# export BASH_SHELL_USER=<some directory under $HOME> # export BASH_SHELL_USER=<some directory under $HOME>
if there is a script setup.sh in the root of these directoies it will be run. If not then all files no matter how deep will be sourced in alpha order order. if there is a script setup.sh in the root of these directoies it will be run. If not then all files no matter how deep will be sourced in alpha order order.
@ -63,10 +55,7 @@ If need to turn off a file just add `.off` to the file name rather than move or
If you are really done with something but want to keep a copy in the repo move it to /archive folder within the primary subfolders If you are really done with something but want to keep a copy in the repo move it to /archive folder within the primary subfolders
if sourcing some file depends on another preface with numbers to put it before. Functions are all sourced before aliases so can be refered to there. if sourcing some file depends on another preface with numbers to put it before. Functions are all sourced before aliases so can be referred to there.
Be aware that an alias or function set in the repo could be subsuming some existing binary or script. Be aware that an alias or function set in the repo could be subsuming some existing binary or script.
`[[ $BASHPID -eq $$ ]] && echo was called directly || echo was called in a subshell`
https://unix.stackexchange.com/a/594809/201387

View File

@ -19,7 +19,7 @@ function logit(){
} }
# #
# LOG_DIR=/opt/bash/logs # LOG_DIR=/shell/logs
# mkdir -p $LOG_DIR # mkdir -p $LOG_DIR
# LOG_FILE=$LOG_DIR/bash_profile # LOG_FILE=$LOG_DIR/bash_profile
# #

View File

@ -103,7 +103,7 @@ unset BASH_SHELL_LOADED
# add in any network directories # add in any network directories
declare networks declare networks
source "$HOME/.bashrc" source "$HOME/.bashrc"
networks="$HOME/${BASH_SHELL_USER:-"bash/shell"}/.networks" networks="$HOME/${BASH_SHELL_USER:-".shell"}/.networks"
NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) " NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) "
# These will be loaded for all users # These will be loaded for all users
networks="$BASH_SHELL_HOST/$(hostname)/.networks" networks="$BASH_SHELL_HOST/$(hostname)/.networks"

View File

@ -36,7 +36,7 @@ local DIRS
local MODULE=$1 local MODULE=$1
# Precidence is user. current hosts, all hosts, current network, all networks, base # Precidence is user. current hosts, all hosts, current network, all networks, base
DIRS=( \ DIRS=( \
$([ $BASH_SHELL_USER ] && echo $HOME/$BASH_SHELL_USER || echo $HOME/bash/shell) \ $([ $BASH_SHELL_USER ] && echo $HOME/$BASH_SHELL_USER || echo $HOME/.shell) \
$BASH_SHELL_HOST/$(hostname) $BASH_SHELL_HOST/$(hostname)
$BASH_SHELL_HOST/all \ $BASH_SHELL_HOST/all \
$BASH_SHELL_NETWORK/$NETWORKNAME \ $BASH_SHELL_NETWORK/$NETWORKNAME \

View File

@ -34,9 +34,9 @@ for file in $files; do
cmd="install -C -m 660 -o $_USER -g sudo $file $_USER_DIR" cmd="install -C -m 660 -o $_USER -g sudo $file $_USER_DIR"
[[ $USER = "$_USER" ]] && eval $cmd || sudo -E -- bash -c "$cmd" [[ $USER = "$_USER" ]] && eval $cmd || sudo -E -- bash -c "$cmd"
done done
echo "the default user bash shell repo subdirecty is \`bash/shell\`" echo "the default user bash shell repo subdirecty is \`.shell\`"
echo "enter an alternative subdirectory under $_USER_DIR or just <enter> to accept default" echo "enter an alternative subdirectory under $_USER_DIR or just <enter> to accept default"
read -e answer read -e answer
[[ ! $answer ]] && echo will source default user shell repo at $_USER_DIR/bash/shell && exit 0 [[ ! $answer ]] && echo will source default user shell repo at $_USER_DIR/.shell && exit 0
sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER='$answer'' $_USER_DIR/.bashrc sed -i '/[[ $BASH_SHELL_BASE_LOADED = true ]]/ i\ BASH_SHELL_USER='$answer'' $_USER_DIR/.bashrc
echo will be processing user shell repo at $_USER_DIR/$answer echo will be processing user shell repo at $_USER_DIR/$answer

View File

@ -35,7 +35,8 @@ read -e answer
echo -----------------;echo deploying /etc shell files echo -----------------;echo deploying /etc shell files
files=$(find $BASH_SHELL_BASE/setup/etc/ -maxdepth 1 -type f) files=$(find $BASH_SHELL_BASE/setup/etc/ -maxdepth 1 -type f)
for file in $files; do sudo install -C -m 644 -o root -g root $file /etc; done for file in $files; do sudo install -C -m 644 -o root -g root $file /etc; done
echo setting BASH_SHELL_BASE to $BASH_SHELL_BASE in etc/profile echo setting BASH_SHELL_BASE to $BASH_SHELL_BASE in etc/bash.bashrc and /etc/profile
sudo sed -i 's:_BASH_SHELL_BASE_:'${BASH_SHELL_BASE}':' /etc/bash.bashrc
sudo sed -i 's:BASH_SHELL_BASE=.*:BASH_SHELL_BASE='${BASH_SHELL_BASE}':' /etc/profile sudo sed -i 's:BASH_SHELL_BASE=.*:BASH_SHELL_BASE='${BASH_SHELL_BASE}':' /etc/profile
files=$(find $BASH_SHELL_BASE/setup/etc/profile.d -maxdepth 1 -type f) files=$(find $BASH_SHELL_BASE/setup/etc/profile.d -maxdepth 1 -type f)
for file in $files; do sudo install -C -m 644 -o root -g root $file /etc/profile.d; done for file in $files; do sudo install -C -m 644 -o root -g root $file /etc/profile.d; done

View File

@ -7,7 +7,7 @@ shopt -q login_shell && export SHELL_LOGIN=true
[ $EUID -eq 0 ] && export USER_ROOT=true [ $EUID -eq 0 ] && export USER_ROOT=true
#uncomment these for debugging. #uncomment these for debugging.
# echo ---- sourcing system wide bash.bashrc --- # echo ---- sourcing system wide bash.bashrc ---
# [[ $USER_ROOT ]] && echo 'Root User' || echo 'Non Root User' # [[ $USER_ROOT ]] && echo 'Root User' || echo 'Non Root User'
# [[ $SHELL_INTERACTIVE ]] && echo 'Interactive' || echo 'Not interactive' # [[ $SHELL_INTERACTIVE ]] && echo 'Interactive' || echo 'Not interactive'
# [[ $SHELL_LOGIN ]] && echo 'Login shell' || echo 'Not login shell' # [[ $SHELL_LOGIN ]] && echo 'Login shell' || echo 'Not login shell'
@ -19,8 +19,7 @@ source /etc/profile
else else
# Set the initial path # Set the initial path
export PATH=/bin:/usr/bin:/usr/local/bin export PATH=/bin:/usr/bin:/usr/local/bin
# set this for access to any shell sources # loading just the module functions which will give access to load any module in shell dirs
export BASH_SHELL_BASE=/opt/bash/shell/base # _BASH_SHELL_BASE_ is/was replaced by the deploy script with actual path
# loading module functions source _BASH_SHELL_BASE_/module.lib
source $BASH_SHELL_BASE/module.lib
fi fi

View File

@ -11,7 +11,7 @@
if ( [[ $SHELL_INTERACTIVE ]] );then if ( [[ $SHELL_INTERACTIVE ]] );then
if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then if ( [[ $BASH_SHELL_BASE_LOADED = true ]] ) ; then
# echo loading user shell sources # echo loading user shell sources
export BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} export BASH_SHELL_USER=${BASH_SHELL_USER:-".shell"}
[[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\ [[ -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 echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template
fi fi

View File

@ -67,7 +67,7 @@ export BASH_SHELL_NETWORK=$([[ -d $parent/network ]] && echo $parent/network ||
# or comment above and set explictly # or comment above and set explictly
# export BASH_SHELL_NETWORK=<some directory> # export BASH_SHELL_NETWORK=<some directory>
# by default USER shell sources will be looked for under $HOME/bash/shell # by default USER shell sources will be looked for under $HOME/.shell
# but the default directory for all users can be set manually below # but the default directory for all users can be set manually below
# export BASH_SHELL_USER=<some directory under $HOME> # export BASH_SHELL_USER=<some directory under $HOME>
# add this export to .bashrc for custom directory. This can be done during or after using the user setup script # add this export to .bashrc for custom directory. This can be done during or after using the user setup script