feat: separating network repo loading from base/host/user

master
Kebler Network System Administrator 2022-12-23 08:24:33 -08:00
parent e02a7c71fb
commit 3e8be4da72
2 changed files with 83 additions and 47 deletions

75
load.sh
View File

@ -1,5 +1,30 @@
#!/bin/bash #!/bin/bash
reload_shell () {
source $BASH_SHELL_BASE/load.sh $@
}
load_shell_host () {
module_load shell-process-directory
[[ $BASH_SHELL_HOST ]] && shell_process_directory $BASH_SHELL_HOST
}
load_shell_user () {
module_load shell-process-directory
[[ -d $HOME/${BASH_SHELL_USER:-shell} ]] && shell_process_directory $HOME/${BASH_SHELL_USER:-shell}
}
load_shell_dev () {
module_load shell-process-directory
[[ $BASH_SHELL_DEV ]] && shell_process_directory $BASH_SHELL_DEV
}
load_shell_host_user_dev () {
load_shell_host
load_shell_user
load_shell_dev
}
# PRIMARY SHELL LOAD SCRIPT - RUN FOR ALL INTERACTIVE SHELLS # PRIMARY SHELL LOAD SCRIPT - RUN FOR ALL INTERACTIVE SHELLS
# don't bother if bash is not the shell # don't bother if bash is not the shell
@ -25,29 +50,39 @@ unset BASH_SHELL_LOADED
module_load shell-process-directory module_load shell-process-directory
if [[ $SSH_SESSION ]]; then # if [[ $SSH_SESSION ]]; then
# ssh session only process base by default # # ssh session only process base by default
# env | grep SSH # # env | grep SSH
# echo ssh session bash load # # echo ssh session bash load
# TODO process network dirs if environment variable is set # # TODO process network dirs if environment variable is set
# process only base, nothing (i.e. BASH_SAFE_MODE, SSH_SHELL_CLEAN) if env variables are set # # process only base, nothing (i.e. BASH_SAFE_MODE, SSH_SHELL_CLEAN) if env variables are set
# see https://stackoverflow.com/a/59461195 # # see https://stackoverflow.com/a/59461195
shell_process_directory $BASH_SHELL_BASE # shell_process_directory $BASH_SHELL_BASE
shell_process_directory $BASH_SHELL_ANY_HOST # shell_process_directory $BASH_SHELL_ANY_HOST
shell_process_directory $BASH_SHELL_HOST # shell_process_directory $BASH_SHELL_HOST
export BASH_SHELL_BASE_LOADED=true # export BASH_SHELL_BASE_LOADED=true
else # process base any
# local shell so process all directories for dir in ${1:-$BASH_SHELL_DIRS}; do
for dir in ${1:-$BASH_SHELL_DIRS}; do # env | grep BASH
# env | grep BASH # echo base $dir
# echo $dir shell_process_directory $dir
shell_process_directory $dir [[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true
[[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true done
done
# set one or the other of these in shell.env if you want to load networks with every shell
if [[ $BASH_SHELL_HOME_NETWORK_LOAD ]] || [[ $BASH_SHELL_NETWORKS_LOAD ]] || [[ $BASH_SHELL_NETWORK ]] ; then
if [[ $BASH_SHELL_ANY_NETWORK ]]; then
module_load networks
[[ $(is_function _load_networks) ]] && _load_networks $BASH_SHELL_NETWORK
fi
fi fi
load_shell_host_user_dev
export BASH_SHELL_LOADED=true export BASH_SHELL_LOADED=true
# Note: $HOME/shell or $HOME/BASH_SHELL_USER are processed via $HOME/.bashrc # Note: $HOME/shell or $HOME/BASH_SHELL_USER are processed via $HOME/.bashrc

View File

@ -77,44 +77,46 @@ parent=$(dirname $BASH_SHELL_BASE)
# Any Host # Any Host
BASH_SHELL_ANY_HOST=${parent}/any/host # or set to BASH_SHELL_ANY_HOST=${parent}/any/host # or set to
# export BASH_SHELL_ALL_HOSTS=<some directory> # export BASH_SHELL_ALL_HOSTS=<some directory>
# Host [[ -d $BASH_SHELL_ANY_HOST ]] && BASH_SHELL_DIRS+="$BASH_SHELL_ANY_HOST " && export BASH_SHELL_ANY_HOST
BASH_SHELL_HOST=$parent/$(hostname)
# export BASH_SHELL_HOST=<some directory>
BASH_SHELL_ANY_NETWORK=$parent/any/network BASH_SHELL_ANY_NETWORK=$parent/any/network
# export BASH_SHELL_ALL_NETWORKS=<some directory> # BASH_SHELL_ALL_NETWORKS=<some directory>
[[ -d $BASH_SHELL_ANY_NETWORK ]] && BASH_SHELL_DIRS+="$BASH_SHELL_ANY_NETWORK " && export BASH_SHELL_ANY_NETWORK
# these are all the base directories to source
export BASH_SHELL_DIRS
# machine specific shell
BASH_SHELL_HOST=$parent/$(hostname)
# BASH_SHELL_HOST=<some directory>
# if there is a host directory add it to list and export env var
# [[ -d $BASH_SHELL_HOST ]] && BASH_SHELL_DIRS+="$BASH_SHELL_HOST " && export BASH_SHELL_HOST
[[ -d $BASH_SHELL_HOST ]] && export BASH_SHELL_HOST
# if this directory exists it is included first in the sourcing
# if allows on the develop scripts and modules, etc for later incorporation into a repo
BASH_SHELL_DEV=${BASH_SHELL_DEV:-/opt/shell}
[[ -d $BASH_SHELL_DEV ]] && export BASH_SHELL_DEV
# by default USER shell sources will be looked for under $HOME/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 export BASH_SHELL_USER=${BASH_SHELL_USER:-shell}
# or add this export to .bashrc for custom directory. This can be done during or after using the user setup script
[[ -d $BASH_SHELL_ANY_HOST ]] && BASH_SHELL_DIRS+="$BASH_SHELL_ANY_HOST " && export BASH_SHELL_ANY_HOST
[[ -d $BASH_SHELL_ANY_NETWORK ]] && BASH_SHELL_DIRS+="$BASH_SHELL_ANY_NETWORK " && export BASH_SHELL_ANY_NETWORK
# now load and export module loading functions library
source $BASH_SHELL_BASE/module.lib
module_load network-dirs
# set up default location to look for other network shell directories
BASH_NETWORKS_DIR=$parent/networks BASH_NETWORKS_DIR=$parent/networks
# BASH_NETWORKS_DIR=<some directory> # alt directory to look for networks # BASH_NETWORKS_DIR=<some directory> # alt directory to look for networks
export BASH_NETWORKS_DIR export BASH_NETWORKS_DIR
# These will be loaded for all users on a host # set one or the other of these if you want to load networks with every shell
network_dirs "$BASH_SHELL_HOST/.networks" export BASH_SHELL_HOME_NETWORK_LOAD=true
# export BASH_SHELL_NETWORKS_LOAD=true
# export BASH_SHELL_NETWORK=<some directory>
# export BASH_SHELL_NETWORK=238.kebler.net
[[ -d $BASH_SHELL_HOST ]] && BASH_SHELL_DIRS+="$BASH_SHELL_HOST " && export BASH_SHELL_HOST # now load and export module loading functions library so it is always available
source $BASH_SHELL_BASE/module.lib
# these loaded only for specific user on a host
network_dirs "$HOME/${BASH_SHELL_USER:-"shell"}/.networks"
# if this directory exists it is included first in the sourcing
# if allows on the develop scripts and modules, etc for later incorporation into a repo
export BASH_SHELL_DEV=/opt/shell
BASH_SHELL_DIRS+="$BASH_SHELL_DEV "
export BASH_SHELL_DIRS
# echo ALL DIRS: $BASH_SHELL_DIRS # echo ALL DIRS: $BASH_SHELL_DIRS
@ -129,7 +131,6 @@ export BASH_SHELL_DIRS
# echo end shell env # echo end shell env
#archived ---for deletion or better explanation #archived ---for deletion or better explanation
# echo enabling aliases with non-interactive shell # echo enabling aliases with non-interactive shell