2020-11-03 12:07:49 -08:00
|
|
|
#!/bin/bash
|
2020-11-13 10:25:04 -08:00
|
|
|
|
2020-11-27 09:59:16 -08:00
|
|
|
# [[ ! $- == *i* ]] && exec >> ~/logs/load.log && exec 2>&1
|
2020-12-03 20:48:04 -08:00
|
|
|
# export BASH_DEBUG=true
|
2020-11-27 09:59:16 -08:00
|
|
|
function nilog () {
|
|
|
|
[[ ! $- == *i* ]] && echo -e "-----\n $USER $*" &>> ~/logs/load.log
|
|
|
|
}
|
|
|
|
|
|
|
|
nilog "called load.sh $(date)"
|
|
|
|
# nilog caller: $(caller)
|
|
|
|
# nilog pid: $(ps -o comm= $PPID)
|
|
|
|
|
2020-11-13 10:25:04 -08:00
|
|
|
# don't bother if bash is not the shell
|
|
|
|
[ ! "$SHELL" = "/bin/bash" ] && return 1
|
|
|
|
|
2020-11-03 12:07:49 -08:00
|
|
|
DIR=${1:-$(dirname ${BASH_SOURCE[0]})}
|
|
|
|
|
2020-11-21 08:55:51 -08:00
|
|
|
[[ $(declare -F | grep module_load) ]] || source "$BASH_SHELL_BASE/module.lib"
|
2020-11-20 08:48:48 -08:00
|
|
|
|
2020-11-18 15:32:09 -08:00
|
|
|
# uncomment for debuggin
|
|
|
|
# echo $USER running load script in $DIR
|
|
|
|
# echo callers
|
|
|
|
# caller
|
|
|
|
# echo $(ps -o comm= $PPID)
|
|
|
|
# echo -----
|
|
|
|
# echo $BASH_SHELL_DIRS
|
|
|
|
|
2020-11-20 08:48:48 -08:00
|
|
|
module_load file
|
|
|
|
[[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1
|
|
|
|
|
2020-12-03 20:48:04 -08:00
|
|
|
module_load debug
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
echo "unable to load a 'debug' module using a noop for debug function"
|
|
|
|
# noop
|
|
|
|
function debug () {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2020-11-27 09:59:16 -08:00
|
|
|
([[ $BASH_ENV ]] && [[ ! $- == *i* ]] && [[ $BASH_USE_ALIAS ]]) && shopt -s expand_aliases
|
|
|
|
|
2020-11-20 08:48:48 -08:00
|
|
|
function shell_process_directory () {
|
2020-11-03 12:07:49 -08:00
|
|
|
local SUBDIRS
|
|
|
|
local DIR
|
|
|
|
|
|
|
|
DIR=${1:-$BASH_SHELL_BASE}
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo soucring directory $DIR
|
2020-11-20 08:48:48 -08:00
|
|
|
# if [[ $DIR = "$BASH_SHELL_BASE" ]]; then
|
|
|
|
# BASH_SHELL_IGNORE=$(shell_get_ignores)
|
|
|
|
# excludes=$BASH_SHELL_IGNORE
|
|
|
|
# else
|
|
|
|
# excludes=$(shell_get_ignores $DIR)
|
|
|
|
# [[ $? -ne 0 ]] && excludes=$BASH_SHELL_IGNORE
|
|
|
|
# fi
|
2020-11-03 12:07:49 -08:00
|
|
|
|
|
|
|
if [ -d "$DIR" ]; then
|
2020-11-13 10:25:04 -08:00
|
|
|
if [ "$DIR" = "$BASH_SHELL_BASE" ] && [ "$BASH_SHELL_BASE_LOADED" = "true" ]; then
|
2020-11-03 12:07:49 -08:00
|
|
|
if [ -v PS1 ]; then
|
|
|
|
echo base directory already sourced
|
|
|
|
read -p "do you want to re-source the base (not recommended)? " -n 1 -r
|
|
|
|
echo
|
|
|
|
[[ ! $REPLY =~ ^[Yy]$ ]] && return 1
|
2020-11-06 14:24:10 -08:00
|
|
|
# else
|
|
|
|
# echo non-interactive shell
|
|
|
|
# return 1
|
2020-11-03 12:07:49 -08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-11-20 08:48:48 -08:00
|
|
|
if [[ $DIR != "$BASH_SHELL_BASE" ]] && [[ -f $DIR/load.sh ]]; then
|
|
|
|
# echo "$DIR/load.sh" found, running instead of default load
|
|
|
|
source "$DIR/load.sh"
|
2020-11-03 12:07:49 -08:00
|
|
|
else
|
|
|
|
# default processing
|
|
|
|
local SUBDIRS
|
2020-11-20 08:48:48 -08:00
|
|
|
local IGNORE_FILE
|
|
|
|
SUBDIRS=$([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || echo $BASH_SHELL_BASE_SUBDIRS)
|
2020-12-02 10:26:41 -08:00
|
|
|
[[ $SSH_SESSION ]] && SUBDIRS+=" ssh/session"
|
2020-11-20 08:48:48 -08:00
|
|
|
IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore"
|
|
|
|
for SUBDIR in $SUBDIRS; do
|
|
|
|
if [ -e "$DIR/$SUBDIR" ]; then
|
|
|
|
# echo processing subdirectory $DIR/$SUBDIR
|
|
|
|
# must quote all globs to avoid bash glob expansion which is likely on
|
|
|
|
# TODO have default set of ignores plus check for .shell-ignore
|
|
|
|
# source_dir -p "archive" -x '"*.off" "*.md" "*TODO*" "LICENSE" "*.sample"' -d 0 $DIR/$SUBDIR
|
|
|
|
# source_dir -p "archive" -x "$excludes" -d 0 $DIR/$SUBDIR
|
|
|
|
source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR
|
|
|
|
# else
|
|
|
|
# echo no subdirectory $DIR/$SUBDIR to process, ignorning
|
|
|
|
fi
|
2020-11-03 12:07:49 -08:00
|
|
|
done
|
|
|
|
fi
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo "done sourcing directory $DIR"
|
|
|
|
# else
|
|
|
|
# echo $DIR does not exist nothing to source
|
2020-11-03 12:07:49 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# process the base directory by default
|
2020-11-13 10:25:04 -08:00
|
|
|
unset BASH_SHELL_BASE_LOADED
|
|
|
|
unset BASH_SHELL_LOADED
|
|
|
|
|
2021-11-20 17:20:44 -08:00
|
|
|
# add in any network directories
|
|
|
|
declare networks
|
|
|
|
source "$HOME/.bashrc"
|
|
|
|
networks="$HOME/${BASH_SHELL_USER:-"bash/shell"}/.networks"
|
|
|
|
NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) "
|
|
|
|
# These will be loaded for all users
|
|
|
|
networks="$BASH_SHELL_HOST/$(hostname)/.networks"
|
|
|
|
NETWORK_DOMAINS+="$([[ -f $networks ]] && cat $networks)"
|
|
|
|
NETWORK_DOMAINS=(${NETWORK_DOMAINS})
|
|
|
|
|
|
|
|
if [[ ! $NETWORK_DOMAINS = "" ]]; then
|
|
|
|
declare domain
|
|
|
|
BASH_SHELL_NETWORK_DIRS=""
|
|
|
|
for domain in "${NETWORK_DOMAINS[@]}"; do
|
|
|
|
# echo processing ${BASH_SHELL_NETWORK}/${domain}
|
|
|
|
if [[ ${domain} = !* ]]; then
|
|
|
|
domain=${domain/#!/}
|
|
|
|
export NETWORK_HOME=$domain
|
|
|
|
fi
|
|
|
|
if [[ -d ${BASH_SHELL_NETWORK}/${domain} ]]; then
|
|
|
|
BASH_SHELL_NETWORK_DIRS+="${BASH_SHELL_NETWORK}/${domain} "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
unset domain
|
|
|
|
export BASH_SHELL_NETWORK_DIRS
|
|
|
|
BASH_SHELL_DIRS+=" ${BASH_SHELL_NETWORK_DIRS}"
|
|
|
|
fi
|
|
|
|
|
2020-11-18 15:32:09 -08:00
|
|
|
# echo bash shell dirs: $BASH_SHELL_DIRS
|
2020-12-03 20:48:04 -08:00
|
|
|
dirs=${1:-$BASH_SHELL_DIRS}
|
2020-11-18 15:32:09 -08:00
|
|
|
|
2020-11-20 08:48:48 -08:00
|
|
|
BASH_SHELL_BASE_SUBDIRS=$(cat "$BASH_SHELL_BASE/.bash-shell-include")
|
|
|
|
# echo subdir includes: $BASH_SHELL_BASE_SUBDIRS
|
|
|
|
|
2020-12-03 20:48:04 -08:00
|
|
|
for dir in $dirs; do
|
2020-11-18 15:32:09 -08:00
|
|
|
# echo $dir
|
|
|
|
shell_process_directory $dir
|
|
|
|
[[ $dir == "$BASH_SHELL_BASE" ]] && BASH_SHELL_BASE_LOADED=true
|
|
|
|
done
|
2020-11-13 10:25:04 -08:00
|
|
|
|
|
|
|
export BASH_SHELL_LOADED=true
|
|
|
|
|
2020-11-03 12:07:49 -08:00
|
|
|
# process user
|
|
|
|
# Note: $HOME/shell or $HOME/BASH_SHELL_USER are sourced via $HOME/.bashrc
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo $(envg BASH) | xargs -n 1
|