feat: allow easier seperate loading of network repos from within terminal session uses new networks module functions

master
Kebler Network System Administrator 2022-12-23 08:29:06 -08:00
parent 762b1c3709
commit 279d5c1863
4 changed files with 161 additions and 0 deletions

3
alias/networks Normal file
View File

@ -0,0 +1,3 @@
alias homenet="module_load networks && load_home_network"
alias allnets="module_load networks && load_all_networks"
alias clrnets="module_load networks && clear_networks"

View File

@ -92,4 +92,11 @@ domain=$(echo $1 | awk -F\. '{print $(NF-1) FS $NF}')
echo "$domain" echo "$domain"
} }
publicip () {
dig +short myip.opendns.com @resolver1.opendns.com
}
getip () {
dig +short $1 | tail -1
}

48
modules/network-dirs.func Normal file
View File

@ -0,0 +1,48 @@
#!/bin/bash
# to be sourced (below) not run in subshell!
function network_dirs () {
(return 0 2>/dev/null) || (echo network_dirs must be sourced; return 1)
module_load path
[[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1
[[ ! $1 ]] && return 1
local networks;
networks=$1
[[ -f $1 ]] && networks=$(cat $1 | tr -s "\n" " ")
for network in $networks;
# while read -r network || [ -n "$network" ]
do
if [[ ${network} = *!* ]]; then
network=${network/!/}
BASH_NETWORK_HOME=$network
fi
[[ $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
continue
fi
fi
fi
[[ $network =~ $NETWORK_HOME ]] && BASH_NETWORK_HOME_DIR=${network}
# echo adding $network to list of networks
BASH_SHELL_NETWORK_DIRS+="${network} "
done
# done < "$1"
# echo after network-dirs $1
# echo DIRS: $BASH_SHELL_NETWORK_DIRS
export BASH_NETWORK_HOME
export BASH_NETWORK_HOME_DIR
export BASH_SHELL_NETWORK_DIRS
}

103
modules/networks.mod Normal file
View File

@ -0,0 +1,103 @@
#!/bin/bash
# module_load network-dirs
# # 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
# # BASH_SHELL_NETWORK_DIRS
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() {
# unset BASH_SHELL_NETWORKS_LOAD
# export BASH_SHELL_HOME_NETWORK_LOAD=true
_load_networks -h
# loadssh
}
load_all_networks () {
# unset BASH_SHELL_HOME_NETWORK_LOAD
# export BASH_SHELL_NETWORKS_LOAD=true
_load_networks -a
# dssh
}
load_network () {
unset BASH_SHELL_HOME_NETWORK_LOAD
unset BASH_SHELL_NETWORKS_LOAD
_load_networks $@
# loadssh
}
clear_networks () {
unset BASH_SHELL_NETWORKS_LOAD
unset BASH_SHELL_HOME_NETWORK_LOAD
unset BASH_SHELL_NETWORK_DIRS
unset BASH_SHELL_NETWORK
reload_shell
ssh_config
}
# called from reload_shell
_load_networks () {
# echo load_networks called $@
[[ $1 == "-h" ]] && BASH_SHELL_HOME_NETWORK_LOAD=true && shift 1
[[ $1 == "-a" ]] && BASH_SHELL_NETWORKS_LOAD=true && shift 1
if [[ ! $BASH_SHELL_NETWORKS_LOAD ]] && [[ ! $BASH_SHELL_HOME_NETWORK_LOAD ]]; then
[[ ! $1 ]] && return 0
# echo $1 was passed
fi
# echo loading networks
module_load network-dirs
# echo before unset $BASH_SHELL_NETWORK_DIRS
unset BASH_SHELL_NETWORK_DIRS
unset BASH_NETWORK_HOME
unset BASH_NETWORK_HOME_DIR
# echo after unset $BASH_SHELL_NETWORK_DIRS
if [[ $1 ]]; then
network_dirs $1
else
# These will be added for all users on a host
network_dirs "$BASH_SHELL_HOST/.networks"
# these added only for specific user on a host and take precedence
network_dirs "$HOME/${BASH_SHELL_USER:-"shell"}/.networks"
# these added only for development and take precedence
network_dirs "$BASH_SHELL_DEV/.networks"
fi
if [[ $BASH_SHELL_HOME_NETWORK_LOAD ]]; then
# echo Home nework $BASH_NETWORK_HOME_DIR processed
shell_process_directory $BASH_NETWORK_HOME_DIR
export BASH_SHELL_NETWORK_DIRS=$BASH_NETWORK_HOME_DIR
else
for dir in ${1:-$BASH_SHELL_NETWORK_DIRS}; do
# echo network $dir processed
shell_process_directory $dir
done
fi
unset BASH_SHELL_NETWORKS_LOAD
unset BASH_SHELL_HOME_NETWORK_LOAD
loadssh
[[ $BASH_SHELL_LOADED ]] && load_shell_host_user_dev
# echo loaded $BASH_SHELL_NETWORK_DIRS
}