refactor: improve network loading use LOADED environment variable
parent
24ed7b60dc
commit
8e83daa3a5
|
@ -39,10 +39,10 @@ function network_path () {
|
|||
|
||||
function get_network_paths () {
|
||||
|
||||
(return 0 2>/dev/null) || (echo network_dirs must be sourced; return 1)
|
||||
|
||||
local lookin="$BASH_SHELL_HOST $BASH_SHELL_USER_DIR $BASH_SHELL_DEV"
|
||||
local networks
|
||||
local home
|
||||
[[ $1 == "-h" ]] && home=true && shift 1
|
||||
for dir in $lookin; do
|
||||
# echo checking in $dir
|
||||
if [[ -f $dir/.networks ]]; then
|
||||
|
@ -73,11 +73,12 @@ for network in $networks; do
|
|||
export BASH_NETWORK_HOME_PATH
|
||||
export BASH_SHELL_NETWORK_PATHS
|
||||
|
||||
[[ $home ]] && echo $BASH_NETWORK_HOME_PATH || echo $BASH_SHELL_NETWORK_PATHS
|
||||
|
||||
# env | grep NETWORK
|
||||
|
||||
}
|
||||
|
||||
|
||||
loadssh () {
|
||||
module_load ssh
|
||||
module_load ssh-config
|
||||
|
@ -86,39 +87,44 @@ loadssh () {
|
|||
module_load ssh-pubkey
|
||||
module_load sshfs
|
||||
enable_mounts
|
||||
export BASH_SHELL_SSH_LOADED=true
|
||||
# echo ssh modules are loaded
|
||||
}
|
||||
|
||||
|
||||
load_home_network() {
|
||||
unset BASH_NETWORK_HOME
|
||||
unset BASH_NETWORK_HOME_PATH
|
||||
get_network_paths
|
||||
if [[ $BASH_NETWORK_HOME_PATH ]]; then
|
||||
# echo loading home $BASH_NETWORK_HOME_PATH
|
||||
shell_process_directory $BASH_NETWORK_HOME_PATH
|
||||
fi
|
||||
}
|
||||
|
||||
load_all_networks () {
|
||||
# unset BASH_SHELL_HOME_NETWORK_LOAD
|
||||
# export BASH_SHELL_NETWORKS_LOAD=true
|
||||
unset BASH_SHELL_NETWORK_PATHS
|
||||
get_network_paths
|
||||
if [[ $BASH_SHELL_NETWORK_PATHS ]]; then
|
||||
for dir in ${1:-$BASH_SHELL_NETWORK_PATHS}; do
|
||||
# echo network $dir processed
|
||||
shell_process_directory $dir
|
||||
done
|
||||
local home
|
||||
home=$(get_network_paths -h)
|
||||
# echo returned $home
|
||||
if [[ $home ]]; then
|
||||
# echo loading home $BASH_NETWORK_HOME_PATH
|
||||
[[ ! "$BASH_SHELL_NETWORKS_LOADED" == *"$home"* ]] && BASH_SHELL_NETWORKS_LOADED+="$home "
|
||||
export BASH_SHELL_NETWORKS_LOADED
|
||||
fi
|
||||
}
|
||||
|
||||
load_a_network () {
|
||||
[[ ! $1 ]] && return 1
|
||||
for dir in $1; do
|
||||
# echo network $dir processed
|
||||
shell_process_directory $dir
|
||||
loaded_networks () {
|
||||
echo $BASH_SHELL_NETWORKS_LOADED
|
||||
}
|
||||
|
||||
load_networks () {
|
||||
# echo load networks $1
|
||||
local network; local networks; local path
|
||||
if [[ $1 ]]; then
|
||||
for network in "$@"; do
|
||||
networks+="$(network_path $network) "
|
||||
done
|
||||
else
|
||||
unset BASH_SHELL_NETWORK_PATHS
|
||||
networks=$(get_network_paths)
|
||||
fi
|
||||
# echo networks to load $networks
|
||||
for path in $networks; do
|
||||
# echo network $path processed
|
||||
shell_process_directory $path
|
||||
[[ ! "$BASH_SHELL_NETWORKS_LOADED" == *"$path"* ]] && BASH_SHELL_NETWORKS_LOADED+="$path "
|
||||
done
|
||||
export BASH_SHELL_NETWORKS_LOADED
|
||||
}
|
||||
|
||||
clear_networks () {
|
||||
|
@ -132,13 +138,10 @@ clear_networks () {
|
|||
|
||||
networks_load () {
|
||||
|
||||
# echo load_networks called $@
|
||||
# echo networks_load called $@
|
||||
|
||||
[[ $1 == "-h" ]] && { shift 1; load_home_network || return $?; }
|
||||
[[ $1 == "-a" ]] && { shift 1; load_all_networks || return $?; }
|
||||
[[ $1 ]] && { load_a_network $@ || return 1; }
|
||||
# echo loading ssh
|
||||
loadssh
|
||||
[[ $1 == "-h" ]] && { shift 1; load_home_network || return $?; } || load_networks "$@"
|
||||
if [[ $BASH_SHELL_SSH_LOADED ]]; then enable_mounts; ssh_config; else loadssh; fi
|
||||
[[ $BASH_SHELL_LOADED ]] && load_shell_host_user_dev
|
||||
|
||||
}
|
|
@ -71,7 +71,7 @@ if [[ (! $SSH_CONFIG || $RESET ) ]]; then
|
|||
chmod 600 $SSH_CONFIG
|
||||
fi
|
||||
|
||||
[[ ! $DIRS ]] && DIRS=($BASH_SHELL_NETWORK_PATHS "$BASH_SHELL_HOST" "$BASH_SHELL_USER_DIR" "$BASH_SHELL_DEV")
|
||||
[[ ! $DIRS ]] && DIRS=($BASH_SHELL_NETWORKS_LOADED "$BASH_SHELL_HOST" "$BASH_SHELL_USER_DIR" "$BASH_SHELL_DEV")
|
||||
# echo DIRS "${DIRS[@]}"
|
||||
# echo $SSH_CONFIG
|
||||
CDIRS=()
|
||||
|
|
|
@ -123,7 +123,7 @@ function umntBackup() {
|
|||
|
||||
function enable_mounts() {
|
||||
|
||||
DIRS=($BASH_SHELL_NETWORK_PATHS "$BASH_SHELL_HOST" "$BASH_SHELL_USER_DIR" "$BASH_SHELL_DEV")
|
||||
DIRS=($BASH_SHELL_NETWORKS_LOADED "$BASH_SHELL_HOST" "$BASH_SHELL_USER_DIR" "$BASH_SHELL_DEV")
|
||||
# echo DIRS "${DIRS[@]}"
|
||||
CDIRS=()
|
||||
j=0
|
||||
|
|
Loading…
Reference in New Issue