2020-11-18 15:32:09 -08:00
|
|
|
#!/bin/bash
|
|
|
|
# Shell Repos Environment
|
2021-04-19 17:25:22 -07:00
|
|
|
# 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 )
|
2020-11-13 10:25:04 -08:00
|
|
|
# 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
|
2020-11-18 15:32:09 -08:00
|
|
|
# $BASH_SHELL_NETWORK/(array of Domains)
|
2020-11-13 10:25:04 -08:00
|
|
|
# $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
|
2021-02-05 13:00:57 -08:00
|
|
|
# this does not effect non-interactive login shells like at user first login
|
2020-11-13 10:25:04 -08:00
|
|
|
|
|
|
|
# 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
|
2021-02-05 13:00:57 -08:00
|
|
|
# if uncommented next lines sets up implicit sourcing for non-interactive shells
|
2020-11-27 09:59:16 -08:00
|
|
|
# echo ----NON_INTERACTIVE SHELL INFO-----
|
|
|
|
# echo enabling bash shell repos for non-inactive shell
|
2021-02-05 13:00:57 -08:00
|
|
|
# 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
|
2020-11-27 09:59:16 -08:00
|
|
|
# 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 ---------
|
2020-11-13 10:25:04 -08:00
|
|
|
# if not using implicit sourcing for non-interactive shells then on can do this per script
|
|
|
|
##################
|
2020-11-18 15:32:09 -08:00
|
|
|
# expanding aliases is optional
|
2020-11-13 10:25:04 -08:00
|
|
|
# shopt -s expand_aliases
|
2020-11-18 15:32:09 -08:00
|
|
|
# source $BASH_SHELL_LOAD
|
|
|
|
# < your script code >
|
2020-11-13 10:25:04 -08:00
|
|
|
# shopt -u expand_aliases
|
|
|
|
####################
|
|
|
|
|
2020-11-27 09:59:16 -08:00
|
|
|
# set ssh session if non-interactive only
|
2020-11-23 15:14:18 -08:00
|
|
|
([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true
|
|
|
|
|
2021-11-20 17:20:44 -08:00
|
|
|
|
2021-01-14 13:55:25 -08:00
|
|
|
declare parent
|
|
|
|
parent=$(dirname $BASH_SHELL_BASE)
|
|
|
|
|
2021-11-20 17:20:44 -08:00
|
|
|
export BASH_SHELL_HOST=$([[ -d $parent/host ]] && echo $parent/host || echo /opt/bash/shell/host)
|
2021-01-14 13:55:25 -08:00
|
|
|
# or comment above and set explictly
|
2021-11-20 17:20:44 -08:00
|
|
|
# export BASH_SHELL_HOST=<some directory>
|
2021-01-14 13:55:25 -08:00
|
|
|
|
2021-11-20 17:20:44 -08:00
|
|
|
# identify a network name that this host resides on
|
|
|
|
# make a directory of the same name
|
2020-11-13 10:25:04 -08:00
|
|
|
|
2021-11-20 17:20:44 -08:00
|
|
|
export BASH_SHELL_NETWORK=$([[ -d $parent/network ]] && echo $parent/network || echo /opt/bash/shell/network)
|
2021-01-14 13:55:25 -08:00
|
|
|
# or comment above and set explictly
|
2021-11-20 17:20:44 -08:00
|
|
|
# export BASH_SHELL_NETWORK=<some directory>
|
2020-11-13 10:25:04 -08:00
|
|
|
|
2021-12-31 17:38:58 -08:00
|
|
|
# by default USER shell sources will be looked for under $HOME/shell
|
2021-11-20 17:20:44 -08:00
|
|
|
# but the default directory for all users can be set manually below
|
2020-11-13 10:25:04 -08:00
|
|
|
# export BASH_SHELL_USER=<some directory under $HOME>
|
2021-11-20 17:20:44 -08:00
|
|
|
# add this export to .bashrc for custom directory. This can be done during or after using the user setup script
|
2020-11-13 10:25:04 -08:00
|
|
|
|
2020-11-18 15:32:09 -08:00
|
|
|
temp="
|
|
|
|
$BASH_SHELL_BASE
|
|
|
|
$BASH_SHELL_NETWORK/all
|
|
|
|
$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
|
2020-11-13 10:25:04 -08:00
|
|
|
source $BASH_SHELL_BASE/module.lib
|
2021-04-19 17:25:22 -07:00
|
|
|
|
|
|
|
# echo end shell env
|