shell-base/shell.env

108 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# Shell Repos Environment
# if bash is not installed then don't bother to continue
! command -v bash >/dev/null 2>&1 && echo no bash command && return 1
export SHELL=$(command -v bash )
# sourced for non-login interactive shells
# sourced via /etc/bash.bashrc so for all machine users
# $BASH_SHELL_BASE # this MUST be set in /etc/profile
# $BASH_SHELL_NETWORK/all
# $BASH_SHELL_NETWORK/(array of Domains)
# $BASH_SHELL_HOST/all
# $BASH_SHELL_HOST/<hostname>
# also
# sourced via $HOME/.bashrc
# $HOME/shell or $HOME/BASH_SHELL_USER
# for the rare interactive login shell
# if you don't want the repos above sourced uncomment this next line
# $NO_LOGIN_BASHRC=true
# this does not effect non-interactive login shells like at user first login
# within each of those directories if load.sh exits it will be run
# otherwise files will be sourced exactly like load.sh in the base
# Using base shell setup repository
# https://git.kebler.net/kebler.net/bash-shell-base.git
# use these two if you want a common directory for all shell repos
# BASH_SHELL_BASE is set in /etc/profile
# load script in base repo to run
export BASH_SHELL_LOAD=$BASH_SHELL_BASE/load.sh # load.sh is default
export BASH_SHELL_STARTUP=$BASH_SHELL_BASE/startup.sh # strtup.sh is default
# if uncommented next lines sets up implicit sourcing for non-interactive shells
# echo ----NON_INTERACTIVE SHELL INFO-----
# echo enabling bash shell repos for non-inactive shell
# export BASH_ENV=$BASH_SHELL_LOAD # same as interactive shell, beware usually too much
export BASH_ENV=$BASH_SHELL_BASE/module.lib # only load module loading functions
# echo enabling aliases with non-interactive shell
export BASH_USE_ALIAS=true # will source aliases for non-interactive
# echo see $BASH_SHELL_BASE/shell.env
# echo ---------
# if not using implicit sourcing for non-interactive shells then on can do this per script
##################
# expanding aliases is optional
# shopt -s expand_aliases
# source $BASH_SHELL_LOAD
# < your script code >
# shopt -u expand_aliases
####################
# 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=<some directory>
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=<some directory>
# by default SHELL sources will be looked for under $HOME/bash/shell
# but can be user set below to $HOME/$BASH_SHELL_USER
# export BASH_SHELL_USER=<some directory under $HOME>
temp="
$BASH_SHELL_BASE
$BASH_SHELL_NETWORK/all
${BASH_SHELL_NETWORK_DIRS[@]}
$BASH_SHELL_HOST/all
$BASH_SHELL_HOST/$(hostname)
"
export BASH_SHELL_DIRS=$(echo $temp)
# env | grep BASH
# env | grep NETWORK_DIRS
# echo ---------------------------------
# echo $BASH_SHELL_DIRS
# echo ---------------------------------
# now load and export module loading functions library
source $BASH_SHELL_BASE/module.lib
# echo end shell env