48 lines
1.3 KiB
Plaintext
48 lines
1.3 KiB
Plaintext
|
#!/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
|
||
|
|
||
|
}
|