From 75297c7cdb3cbc3f4b962222bb24598df88d7ff1 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Sat, 20 Nov 2021 17:20:44 -0800 Subject: [PATCH] additional network shell directories now set by a .network file under the $HOSTNAME host shell directory (for all users) or the same within the USER shell directory for per user networks. Network proceeded by ! indicates the home/lan network of that machine. Also added -t to _find for setting the search type. --- load.sh | 28 ++++++++++++++++++++++++++++ modules/utility/file.lib | 10 ++++++++-- shell.env | 36 +++++++++++------------------------- 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/load.sh b/load.sh index 6003c08..8937dbd 100755 --- a/load.sh +++ b/load.sh @@ -100,6 +100,34 @@ function shell_process_directory () { unset BASH_SHELL_BASE_LOADED unset BASH_SHELL_LOADED +# add in any network directories +declare networks +source "$HOME/.bashrc" +networks="$HOME/${BASH_SHELL_USER:-"bash/shell"}/.networks" +NETWORK_DOMAINS="$([[ -f $networks ]] && cat $networks) " +# These will be loaded for all users +networks="$BASH_SHELL_HOST/$(hostname)/.networks" +NETWORK_DOMAINS+="$([[ -f $networks ]] && cat $networks)" +NETWORK_DOMAINS=(${NETWORK_DOMAINS}) + +if [[ ! $NETWORK_DOMAINS = "" ]]; then +declare domain +BASH_SHELL_NETWORK_DIRS="" +for domain in "${NETWORK_DOMAINS[@]}"; do +# echo processing ${BASH_SHELL_NETWORK}/${domain} +if [[ ${domain} = !* ]]; then +domain=${domain/#!/} +export NETWORK_HOME=$domain +fi +if [[ -d ${BASH_SHELL_NETWORK}/${domain} ]]; then + BASH_SHELL_NETWORK_DIRS+="${BASH_SHELL_NETWORK}/${domain} " + fi +done +unset domain +export BASH_SHELL_NETWORK_DIRS +BASH_SHELL_DIRS+=" ${BASH_SHELL_NETWORK_DIRS}" +fi + # echo bash shell dirs: $BASH_SHELL_DIRS dirs=${1:-$BASH_SHELL_DIRS} diff --git a/modules/utility/file.lib b/modules/utility/file.lib index 817f95b..8edd858 100644 --- a/modules/utility/file.lib +++ b/modules/utility/file.lib @@ -54,8 +54,12 @@ local HIDDEN declare OPTION declare OPTARG declare OPTIND -while getopts 'p:d:e:n:f:h' OPTION; do +while getopts 't:p:d:e:n:f:h' OPTION; do case "$OPTION" in + t) + TYPE=$OPTARG + # echo "TYPE $TYPE" + ;; f) EXCLUDE_FILE=$OPTARG # echo EXCLUDE FILE $EXCLUDE_FILE >&2 @@ -110,7 +114,9 @@ fi local FIND FIND="command find $DIR" FIND+=$([ ! $DEPTH == 0 ] && echo " -maxdepth $DEPTH ") -FIND+=" -type f " +# FIND+=" -type $([ $TYPE ] && echo "$TYPE" || echo "f")" +TYPE=${TYPE:-f} +FIND+=" -type $TYPE " # include HIDDEN files and directories IS FALSE BY DEFULT [[ ! $HIDDEN ]] && FIND+="! -path \"*/.*/*\" ! -name \".*\" " diff --git a/shell.env b/shell.env index 5060d67..bb6647f 100755 --- a/shell.env +++ b/shell.env @@ -52,43 +52,29 @@ export BASH_USE_ALIAS=true # will source aliases for non-interactive # set ssh session if non-interactive only ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true -# identify a network name that this host resides on -# make a directory of the same name -# if unset then only /all will be sourced -# TODO just read all directories in BASH_SHELL_NETWORK. -export NETWORK_DOMAINS=(238.kebler.net 645.kebler.net 3115.kebler.net 312.kebler.net) -# network domain folder entry will be made for each domain set, first is home domain, others via vpn -if [[ $NETWORK_DOMAINS ]]; then -export NETWORK_HOME=${NETWORK_DOMAINS[0]} -# TODO needs to be automatically set not hard coded + declare parent parent=$(dirname $BASH_SHELL_BASE) -export BASH_SHELL_NETWORK=$([[ -d $parent/network ]] && echo $parent/network || echo /opt/bash/shell/network) -# or comment above and set explictly -# export BASH_SHELL_NETWORK= - -declare domain -BASH_SHELL_NETWORK_DIRS="" -for domain in "${NETWORK_DOMAINS[@]}"; do - BASH_SHELL_NETWORK_DIRS+="${BASH_SHELL_NETWORK}/${domain} " -done -fi -unset domain -export BASH_SHELL_NETWORK_DIRS - export BASH_SHELL_HOST=$([[ -d $parent/host ]] && echo $parent/host || echo /opt/bash/shell/host) # or comment above and set explictly # export BASH_SHELL_HOST= -# by default SHELL sources will be looked for under $HOME/bash/shell -# but can be user set below to $HOME/$BASH_SHELL_USER +# identify a network name that this host resides on +# make a directory of the same name + +export BASH_SHELL_NETWORK=$([[ -d $parent/network ]] && echo $parent/network || echo /opt/bash/shell/network) +# or comment above and set explictly +# export BASH_SHELL_NETWORK= + +# by default USER shell sources will be looked for under $HOME/bash/shell +# but the default directory for all users can be set manually below # export BASH_SHELL_USER= +# add this export to .bashrc for custom directory. This can be done during or after using the user setup script temp=" $BASH_SHELL_BASE $BASH_SHELL_NETWORK/all -${BASH_SHELL_NETWORK_DIRS[@]} $BASH_SHELL_HOST/all $BASH_SHELL_HOST/$(hostname) "