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
|
|
|
|
[[ $? -ne 0 ]] && echo unable to access the file module && return 1
|
|
|
|
|
|
|
|
[[ ! $1 ]] && return 1
|
|
|
|
local network;
|
|
|
|
network=$1
|
|
|
|
[[ $2 ]] && network=$2/$network
|
|
|
|
if [[ $(isAbsPath $network) ]]; then
|
|
|
|
[[ ! -d $network ]] && continue
|
|
|
|
else
|
|
|
|
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 () {
|
|
|
|
|
|
|
|
(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
|
|
|
|
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
|
|
|
|
# echo $networks
|
|
|
|
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
|
|
|
|
|
|
|
|
# env | grep NETWORK
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-23 08:29:06 -08:00
|
|
|
|
|
|
|
loadssh () {
|
|
|
|
module_load ssh
|
|
|
|
module_load ssh-config
|
|
|
|
ssh_config
|
|
|
|
module_load ssh-copy
|
|
|
|
module_load ssh-pubkey
|
|
|
|
module_load sshfs
|
|
|
|
enable_mounts
|
|
|
|
# echo ssh modules are loaded
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
load_home_network() {
|
2022-12-30 09:14:39 -08:00
|
|
|
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
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
load_all_networks () {
|
|
|
|
# unset BASH_SHELL_HOME_NETWORK_LOAD
|
|
|
|
# export BASH_SHELL_NETWORKS_LOAD=true
|
2022-12-30 09:14:39 -08:00
|
|
|
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
|
|
|
|
fi
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|
|
|
|
|
2022-12-30 09:14:39 -08:00
|
|
|
load_a_network () {
|
|
|
|
[[ ! $1 ]] && return 1
|
|
|
|
for dir in $1; do
|
|
|
|
# echo network $dir processed
|
|
|
|
shell_process_directory $dir
|
|
|
|
done
|
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
|
|
|
|
2022-12-31 23:29:20 -08:00
|
|
|
# echo load_networks called $@
|
2022-12-23 08:29:06 -08:00
|
|
|
|
2022-12-30 09:14:39 -08:00
|
|
|
[[ $1 == "-h" ]] && { shift 1; load_home_network || return $?; }
|
|
|
|
[[ $1 == "-a" ]] && { shift 1; load_all_networks || return $?; }
|
2022-12-31 23:29:20 -08:00
|
|
|
[[ $1 ]] && { load_a_network $@ || return 1; }
|
2022-12-30 09:14:39 -08:00
|
|
|
# echo loading ssh
|
2022-12-23 08:29:06 -08:00
|
|
|
loadssh
|
|
|
|
[[ $BASH_SHELL_LOADED ]] && load_shell_host_user_dev
|
2022-12-30 09:14:39 -08:00
|
|
|
|
2022-12-23 08:29:06 -08:00
|
|
|
}
|