This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues/pull-requests.
bash-shell-base/startup.sh

41 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
function startup_load () {
local SDIRS
local SDIR
local DIRS
local DIR
local excludes
[[ $(declare -F | grep module_load) ]] && echo module lib already loaded || source "$BASH_SHELL_BASE/module.lib"
module_load file
[[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1
[[ $1 ]] && DIRS=($1) || DIRS=(${BASH_SHELL_DIRS})
# llog "startup directories to try ${DIRS[*]}"
SDIRS=()
j=0
cnt=${#DIRS[@]}
for ((i=0;i<cnt;i++)); do
# echo $i of $cnt
DIR="${DIRS[i]}/startup"
# echo ----- trying $DIR
[ -d $DIR ] && SDIRS[j]=$DIR && j+=1
done
# STARTUP_DIRS is array of any other startup directores where scripts may be loaded from
[ $STARTUP_DIRS ] && SDIRS=("$STARTUP_DIRS" "${SDIRS[@]}")
for SDIR in "${SDIRS[@]}"
do
DIR=$(dirname $SDIR)
IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore"
llog "startup dir to source $SDIR"
source_dir -f "$IGNORE_FILE" -d 0 $SDIR
done
}
# if script was executed then call the function
(return 0 2>/dev/null) || startup_load