2022-12-23 08:29:06 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# module_load network-dirs
|
2022-12-30 09:14:39 -08:00
|
|
|
|
2022-12-23 08:29:06 -08:00
|
|
|
# # These will be loaded for all users on a host
|
|
|
|
# network_dirs "$BASH_SHELL_HOST/.networks"
|
|
|
|
# # these loaded only for specific user on a host and take precedence
|
|
|
|
# network_dirs "$HOME/${BASH_SHELL_USER:-"shell"}/.networks"
|
|
|
|
# # these are exported from network_dirs
|
|
|
|
# # env | grep NETWORK
|
|
|
|
# # NETWORK_HOME
|
|
|
|
# # NETWORK_HOME_DIR
|
2022-12-30 09:14:39 -08:00
|
|
|
# # BASH_SHELL_NETWORK_PATHS
|
|
|
|
|
|
|
|
function network_path () {
|
|
|
|
|
|
|
|
module_load path
|
2023-02-07 12:45:27 -08:00
|
|
|
[[ $? -ne 0 ]] && echo unable to access the path module && return 1
|
2022-12-30 09:14:39 -08:00
|
|
|
|
|
|
|
[[ ! $1 ]] && return 1
|
|
|
|
local network;
|
|
|
|
network=$1
|
|
|
|
[[ $2 ]] && network=$2/$network
|
|
|
|
if [[ $(isAbsPath $network) ]]; then
|
2023-02-07 12:45:27 -08:00
|
|
|
[[ ! -d $network ]] && return 2
|
|
|
|
else
|
2022-12-30 09:14:39 -08:00
|
|
|
if [[ -d ${HOME}/${BASH_SHELL_USER}/${network} ]];then
|
|
|
|
network=${HOME}/${BASH_SHELL_USER}/${network}
|
|
|
|
else
|
|
|
|
if [[ -d ${BASH_NETWORKS_DIR}/${network} ]];then
|
|
|
|
network=${BASH_NETWORKS_DIR}/${network}
|
|
|
|
else
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
echo $network
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_network_paths () {
|
|
|
|
|
|
|
|
local lookin="$BASH_SHELL_HOST $BASH_SHELL_USER_DIR $BASH_SHELL_DEV"
|
|
|
|
local networks
|
2023-01-01 10:43:15 -08:00
|
|
|
local home
|
|
|
|
[[ $1 == "-h" ]] && home=true && shift 1
|
2022-12-30 09:14:39 -08:00
|
|
|
for dir in $lookin; do
|
|
|
|
# echo checking in $dir
|
|
|
|
if [[ -f $dir/.networks ]]; then
|
|
|
|
local _networks=$(cat $dir/.networks | tr -s "\n" " ")
|
|
|
|
for network in $_networks; do
|
|
|
|
[[ ! "$networks" == *" $network"* ]] && networks+=" $network" || echo $network already in list
|
2023-02-07 12:45:27 -08:00
|
|
|
# echo $networks
|
2022-12-30 09:14:39 -08:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for network in $networks; do
|
|
|
|
# echo $network
|
|
|
|
if [[ ${network} = *!* ]]; then
|
|
|
|
network=${network/!/}
|
|
|
|
BASH_NETWORK_HOME=$network
|
|
|
|
fi
|
|
|
|
network=$(network_path $network $2)
|
|
|
|
# echo $network
|
|
|
|
if [[ $network ]]; then
|
|
|
|
[[ $network =~ $BASH_NETWORK_HOME ]] && BASH_NETWORK_HOME_PATH=${network}
|
|
|
|
# echo adding $network to list of networks
|
|
|
|
BASH_SHELL_NETWORK_PATHS+="${network} "
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
export BASH_NETWORK_HOME
|
|
|
|
export BASH_NETWORK_HOME_PATH
|
|
|
|
export BASH_SHELL_NETWORK_PATHS
|
|
|
|
|
2023-01-01 10:43:15 -08:00
|
|
|
[[ $home ]] && echo $BASH_NETWORK_HOME_PATH || echo $BASH_SHELL_NETWORK_PATHS
|
|
|
|
|
2022-12-30 09:14:39 -08:00
|
|
|
# env | grep NETWORK
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-23 08:29:06 -08:00
|
|
|
loadssh () {
|
2023-02-07 12:45:27 -08:00
|
|
|
# echo loading ssh modules
|
2022-12-23 08:29:06 -08:00
|
|
|
module_load ssh
|
|
|
|
module_load ssh-config
|
|
|
|
ssh_config
|
|
|
|
module_load ssh-copy
|
|
|
|
module_load ssh-pubkey
|
|
|
|
module_load sshfs
|
|
|
|
enable_mounts
|
2023-01-01 10:43:15 -08:00
|
|
|
export BASH_SHELL_SSH_LOADED=true
|
|
|
|
# echo ssh modules are loaded
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
load_home_network() {
|
2023-01-01 10:43:15 -08:00
|
|
|
local home
|
|
|
|
home=$(get_network_paths -h)
|
|
|
|
# echo returned $home
|
|
|
|
if [[ $home ]]; then
|
2023-02-07 12:45:27 -08:00
|
|
|
# echo loading home @ $home
|
|
|
|
shell_process_directory $home
|
2023-01-01 10:43:15 -08:00
|
|
|
[[ ! "$BASH_SHELL_NETWORKS_LOADED" == *"$home"* ]] && BASH_SHELL_NETWORKS_LOADED+="$home "
|
|
|
|
export BASH_SHELL_NETWORKS_LOADED
|
|
|
|
fi
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|
|
|
|
|
2023-01-01 10:43:15 -08:00
|
|
|
loaded_networks () {
|
|
|
|
echo $BASH_SHELL_NETWORKS_LOADED
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|
|
|
|
|
2023-01-01 10:43:15 -08:00
|
|
|
load_networks () {
|
|
|
|
local network; local networks; local path
|
|
|
|
if [[ $1 ]]; then
|
|
|
|
for network in "$@"; do
|
2023-02-07 12:45:27 -08:00
|
|
|
# echo finding path of $network
|
2023-01-01 10:43:15 -08:00
|
|
|
networks+="$(network_path $network) "
|
2023-02-07 12:45:27 -08:00
|
|
|
# echo list of networks $networks
|
2022-12-30 09:14:39 -08:00
|
|
|
done
|
2023-01-01 10:43:15 -08:00
|
|
|
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
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
clear_networks () {
|
|
|
|
unset BASH_SHELL_NETWORKS_LOAD
|
|
|
|
unset BASH_SHELL_HOME_NETWORK_LOAD
|
2022-12-30 09:14:39 -08:00
|
|
|
unset BASH_SHELL_NETWORK_PATHS
|
2022-12-23 08:29:06 -08:00
|
|
|
unset BASH_SHELL_NETWORK
|
|
|
|
reload_shell
|
|
|
|
ssh_config
|
|
|
|
}
|
|
|
|
|
2022-12-30 09:14:39 -08:00
|
|
|
networks_load () {
|
2022-12-23 08:29:06 -08:00
|
|
|
|
2023-01-01 10:43:15 -08:00
|
|
|
# echo networks_load called $@
|
2022-12-23 08:29:06 -08:00
|
|
|
|
2023-01-01 10:43:15 -08:00
|
|
|
[[ $1 == "-h" ]] && { shift 1; load_home_network || return $?; } || load_networks "$@"
|
2023-02-07 12:45:27 -08:00
|
|
|
if [[ $BASH_SHELL_SSH_LOADED ]]; then
|
|
|
|
module_load sshfs ssh-config
|
|
|
|
enable_mounts; ssh_config;
|
|
|
|
else loadssh;
|
|
|
|
fi
|
2022-12-23 08:29:06 -08:00
|
|
|
[[ $BASH_SHELL_LOADED ]] && load_shell_host_user_dev
|
2022-12-30 09:14:39 -08:00
|
|
|
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|