2022-12-31 23:28:18 -08:00
|
|
|
# !/bin/bash
|
2023-01-20 17:17:55 -08:00
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# UCI SHELL REPOS ENVIRONMENT
|
|
|
|
# see README.md for details of how the system work
|
|
|
|
# In a nutshell its a set of directories that are sourced when creating a shell
|
|
|
|
# The repos allow one to organize functionality across machines, users and networks
|
|
|
|
|
2022-12-30 09:18:39 -08:00
|
|
|
# In general do not change or edit this base shell.env file
|
2022-12-31 23:28:18 -08:00
|
|
|
# Instead add a custom shell.env to specific shell host directory,
|
2022-12-30 09:18:39 -08:00
|
|
|
# user shell directory or dev shell directory
|
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# echo DEBUG: sourcing shell.env
|
|
|
|
|
2022-12-31 23:28:18 -08:00
|
|
|
# This file gets sourced early in /etc/profile for all login and
|
|
|
|
# for interactive non-login shells via /etc/bash.bashrc
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# for interactive login shell (ssh is about the only case)
|
|
|
|
# loading the shell might cause issues specially using rsync
|
|
|
|
# It can be turned off per user or host in the appropriate directory
|
|
|
|
# with NO_BASH_SHELL_SSH=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
|
|
|
|
2022-03-01 22:44:26 -08: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
|
2022-12-31 23:28:18 -08:00
|
|
|
export SHELL="$(command -v bash )"
|
2022-03-01 22:44:26 -08:00
|
|
|
|
|
|
|
# without changing /etc/profile you can disable loading the UCI Shell system
|
|
|
|
# by uncommenting this line. It will only set up a simple prompt instead.
|
2022-12-31 23:28:18 -08:00
|
|
|
# if UCI shell is causing issues then one can invoke this
|
2022-03-01 22:44:26 -08:00
|
|
|
# BASH_SAFE_MODE=true
|
|
|
|
# todo add safemode enable/disable function that (un)comments
|
2020-11-13 10:25:04 -08:00
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
if [[ $BASH_SAFE_MODE ]]; then
|
|
|
|
RED='\033[0;31m';NC='\033[0m'
|
|
|
|
printf "${RED}BASH SHELL SAFE MODE ENABLED${NC}\n"
|
|
|
|
export BASH_SAFE_MODE;
|
|
|
|
return 2
|
|
|
|
fi
|
2020-11-13 10:25:04 -08:00
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# You can overwrite the default environment variables in this file
|
|
|
|
# There is NOT a lot of reasons to do so unless you prefer other directory locations
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# within each of those directories if a load.sh exits it will be run
|
|
|
|
# otherwise files will be sourced according to load.sh in the base repo
|
2022-12-31 23:28:18 -08:00
|
|
|
export BASH_SHELL_LOAD="$BASH_SHELL_BASE/load.sh" # load.sh is default"
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2022-12-31 23:28:18 -08:00
|
|
|
export BASH_SHELL_STARTUP="$BASH_SHELL_BASE/startup.sh # startup.sh is default"
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2022-12-31 23:28:18 -08:00
|
|
|
# for non-interactive login shells (like at boot)
|
2022-03-01 22:44:26 -08:00
|
|
|
# load this library that allows loading additional modules
|
2022-12-31 23:28:18 -08:00
|
|
|
export BASH_ENV="$BASH_SHELL_BASE/module.lib # module loading functions"
|
2022-03-01 22:44:26 -08:00
|
|
|
# otherwise comment above and uncommented next line
|
|
|
|
# export BASH_ENV=$BASH_SHELL_LOAD # load same as interactive shell, beware usually causes issues!!!
|
2020-11-13 10:25:04 -08:00
|
|
|
|
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
|
|
|
|
|
2022-03-01 22:44:26 -08:00
|
|
|
# By default it will set up a master directory /shell
|
|
|
|
|
|
|
|
# DEFAULT DIRECTORY STRUCTURE
|
2022-12-31 23:28:18 -08:00
|
|
|
# /shell
|
|
|
|
# -- base # $BASH_SHELL_BASE=/shell/base (default) is set in /etc/profile during setup
|
|
|
|
# -- host
|
2023-12-14 21:09:19 -08:00
|
|
|
# --<specific host>
|
2022-12-31 23:28:18 -08:00
|
|
|
# -- network
|
|
|
|
# -- networks
|
2023-12-14 21:09:19 -08:00
|
|
|
# -- <network name>
|
|
|
|
# -- <another network name>
|
2022-12-31 23:28:18 -08:00
|
|
|
# -- $HOME/shell # user
|
2022-03-01 22:44:26 -08:00
|
|
|
|
|
|
|
# default loading preference is first in list is lowest and last is highest
|
|
|
|
# for example a function "test" in the BASE will be overwritten by one the HOST repo
|
2022-12-31 23:28:18 -08:00
|
|
|
# that is the same for startup scripts and module loading.
|
2021-11-20 17:20:44 -08:00
|
|
|
|
2022-02-20 12:44:29 -08:00
|
|
|
BASH_SHELL_DIRS="$BASH_SHELL_BASE "
|
2022-03-01 22:44:26 -08:00
|
|
|
|
2021-01-14 13:55:25 -08:00
|
|
|
declare parent
|
2022-12-31 23:28:18 -08:00
|
|
|
parent="$(dirname $BASH_SHELL_BASE)"
|
2021-01-14 13:55:25 -08:00
|
|
|
|
2022-02-20 12:44:29 -08:00
|
|
|
# Any Host
|
2023-12-14 21:09:19 -08:00
|
|
|
BASH_SHELL_HOST="${parent}/host"
|
2022-02-20 12:44:29 -08:00
|
|
|
# export BASH_SHELL_ALL_HOSTS=<some directory>
|
2023-12-14 21:09:19 -08:00
|
|
|
[[ -d $BASH_SHELL_HOST ]] && BASH_SHELL_DIRS+="$BASH_SHELL_HOST " && export BASH_SHELL_HOST
|
2021-01-14 13:55:25 -08:00
|
|
|
|
2023-12-14 21:09:19 -08:00
|
|
|
BASH_SHELL_NETWORK=$parent/network
|
2022-12-23 08:24:33 -08:00
|
|
|
# BASH_SHELL_ALL_NETWORKS=<some directory>
|
2023-12-14 21:09:19 -08:00
|
|
|
[[ -d $BASH_SHELL_NETWORK ]] && BASH_SHELL_DIRS+="$BASH_SHELL_NETWORK " && export BASH_SHELL_NETWORK
|
2022-12-23 08:24:33 -08:00
|
|
|
# these are all the base directories to source
|
|
|
|
export BASH_SHELL_DIRS
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2022-12-23 08:24:33 -08:00
|
|
|
# machine specific shell
|
2023-12-14 21:09:19 -08:00
|
|
|
BASH_SHELL_HOSTNAME="$parent/$([[ -f /etc/hostname ]] && cat /etc/hostname || echo nohostname)"
|
|
|
|
# BASH_SHELL_HOSTNAME=<some directory>
|
2022-12-23 08:24:33 -08:00
|
|
|
# if there is a host directory add it to list and export env var
|
2023-12-14 21:09:19 -08:00
|
|
|
# [[ -d $BASH_SHELL_HOSTNAME ]] && BASH_SHELL_DIRS+="$BASH_SHELL_HOSTNAME " && export BASH_SHELL_HOSTNAME
|
|
|
|
[[ -d $BASH_SHELL_HOSTNAME ]] && export BASH_SHELL_HOSTNAME
|
2022-12-23 08:24:33 -08:00
|
|
|
|
|
|
|
# if this directory exists it is included first in the sourcing
|
|
|
|
# if allows on the develop scripts and modules, etc for later incorporation into a repo
|
2022-12-31 23:28:18 -08:00
|
|
|
BASH_SHELL_DEV=${BASH_SHELL_DEV:-/opt/shell}
|
2022-12-23 08:24:33 -08:00
|
|
|
[[ -d $BASH_SHELL_DEV ]] && export BASH_SHELL_DEV
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2023-01-05 12:36:23 -08:00
|
|
|
# #################### NETWORKING #########################
|
|
|
|
|
2022-12-31 23:28:18 -08:00
|
|
|
# set up default location to look for other network shell directories
|
2022-02-20 12:44:29 -08:00
|
|
|
BASH_NETWORKS_DIR=$parent/networks
|
|
|
|
# BASH_NETWORKS_DIR=<some directory> # alt directory to look for networks
|
|
|
|
export BASH_NETWORKS_DIR
|
|
|
|
|
2023-01-20 17:17:55 -08:00
|
|
|
# NOTE: one can set one or the other of these in custom shell.env under HOST/USER/DEV repo directories
|
2022-12-30 09:18:39 -08:00
|
|
|
# if you want to load networks with every shell
|
|
|
|
# export BASH_SHELL_HOME_NETWORK_LOAD=true
|
2022-12-23 08:24:33 -08:00
|
|
|
# export BASH_SHELL_NETWORKS_LOAD=true
|
|
|
|
# export BASH_SHELL_NETWORK=<some directory>
|
2022-12-30 09:18:39 -08:00
|
|
|
|
2023-01-20 17:17:55 -08:00
|
|
|
# source any custom environment or early overrides for current user, in particular BASH_SHELL_USER_DIR
|
|
|
|
[[ -f $HOME/.ucishell ]] && source $HOME/.ucishell > /dev/null
|
|
|
|
# by default USER shell sources will be looked for under $HOME/shell
|
|
|
|
export BASH_SHELL_USER_DIR=${BASH_SHELL_USER_DIR:-$HOME/shell}
|
2022-02-20 12:44:29 -08:00
|
|
|
|
2023-01-05 12:36:23 -08:00
|
|
|
# now load and export bootstrap module loading functions library so it is always available
|
|
|
|
set -a;source $BASH_SHELL_BASE/module.lib;set +a
|
2022-03-01 22:44:26 -08:00
|
|
|
|
2022-12-30 09:18:39 -08:00
|
|
|
# echo done shell.env
|
2022-02-20 12:44:29 -08:00
|
|
|
|
|
|
|
# echo ALL DIRS: $BASH_SHELL_DIRS
|
2020-11-18 15:32:09 -08:00
|
|
|
# env | grep BASH
|
|
|
|
# env | grep NETWORK_DIRS
|
|
|
|
# echo ---------------------------------
|
|
|
|
# echo $BASH_SHELL_DIRS
|
|
|
|
# echo ---------------------------------
|
|
|
|
|
2022-12-31 23:28:18 -08:00
|
|
|
# archived ---for deletion or better explanation
|
2022-03-01 22:44:26 -08:00
|
|
|
# echo enabling aliases with non-interactive shell
|
|
|
|
# DEPRECATED # export BASH_USE_ALIAS=true # will source aliases for non-interactive
|
|
|
|
# if not using implicit sourcing for non-interactive shells then one can do this per script
|
2022-12-31 23:28:18 -08:00
|
|
|
# #################
|
2022-03-01 22:44:26 -08:00
|
|
|
# expanding aliases is optional
|
|
|
|
# shopt -s expand_aliases
|
|
|
|
# source $BASH_SHELL_LOAD
|
2022-12-31 23:28:18 -08:00
|
|
|
# < your script code >
|
2022-03-01 22:44:26 -08:00
|
|
|
# shopt -u expand_aliases
|
2022-12-31 23:28:18 -08:00
|
|
|
# ###################
|
2022-12-30 09:18:39 -08:00
|
|
|
|
|
|
|
|