60 lines
1.4 KiB
Bash
60 lines
1.4 KiB
Bash
#!/bin/bash
|
|
# to be sourced (below) not run in subshell!
|
|
|
|
function network_path () {
|
|
|
|
[[ ! $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 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
|
|
[[ ! $1 ]] && return 2
|
|
[[ -f $1 ]] && networks=$(cat $1 | tr -s "\n" " ")
|
|
echo networks to add $networks
|
|
for network in $networks;
|
|
do
|
|
if [[ ${network} = *!* ]]; then
|
|
network=${network/!/}
|
|
BASH_NETWORK_HOME=$network
|
|
fi
|
|
network=$(network_path $network $2)
|
|
if [[ $network ]]; then
|
|
[[ $network =~ $BASH_NETWORK_HOME ]] && BASH_NETWORK_HOME_DIR=${network}
|
|
# echo adding $network to list of networks
|
|
BASH_SHELL_NETWORK_PATHS+="${network} "
|
|
fi
|
|
done
|
|
|
|
export BASH_NETWORK_HOME
|
|
export BASH_NETWORK_HOME_DIR
|
|
export BASH_SHELL_NETWORK_PATHS
|
|
|
|
}
|
|
|