#!/bin/bash # 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 # In general do not change or edit this base shell.env file # Instead add a custom shell.env to specific shell host directory, # user shell directory or dev shell directory # echo DEBUG: sourcing shell.env # This file gets sourced early in /etc/profile for all login and # for interactive non-login shells via /etc/bash.bashrc # 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 # this does not effect non-interactive login shells like at user first login # 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 )" [[ -f $BASH_SHELL_BASE/shell.env.override ]] && source $BASH_SHELL_BASE/shell.env.override # 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. # if UCI shell is causing issues then one can invoke this # BASH_SAFE_MODE=true # todo add safemode enable/disable function that (un)comments 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 # 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 # 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 export BASH_SHELL_LOAD="$BASH_SHELL_BASE/load.sh" # load.sh is default" export BASH_SHELL_STARTUP="$BASH_SHELL_BASE/startup.sh # startup.sh is default" # for non-interactive login shells (like at boot) # load this library that allows loading additional modules export BASH_ENV="$BASH_SHELL_BASE/module.lib # module loading functions" # otherwise comment above and uncommented next line # export BASH_ENV=$BASH_SHELL_LOAD # load same as interactive shell, beware usually causes issues!!! # set ssh session if non-interactive only ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true # By default it will set up a master directory /shell # DEFAULT DIRECTORY STRUCTURE # /shell # -- base # $BASH_SHELL_BASE=/shell/base (default) is set in /etc/profile during setup # -- host # -- # -- network # -- networks # -- # -- # -- $HOME/shell # user # 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 # that is the same for startup scripts and module loading. BASH_SHELL_DIRS="$BASH_SHELL_BASE " declare parent parent="$(dirname $BASH_SHELL_BASE)" # Mainly used for installing scripts to the hostname directory (see below) BASH_SHELL_HOST="${parent}/host" [[ -d $BASH_SHELL_HOST ]] && BASH_SHELL_DIRS+="$BASH_SHELL_HOST " && export BASH_SHELL_HOST # source any additional shell env [[ -f $BASH_SHELL_HOST/shell.env ]] && source $BASH_SHELL_HOST/shell.env BASH_SHELL_NETWORK=${parent}/network [[ -d $BASH_SHELL_NETWORK ]] && BASH_SHELL_DIRS+="$BASH_SHELL_NETWORK " && export BASH_SHELL_NETWORK # source any additional shell env [[ -f $BASH_SHELL_NETWORK/shell.env ]] && source $BASH_SHELL_NETWORK/shell.env # these are all the base directories to source export BASH_SHELL_DIRS # machine specific shell based on hostname BASH_SHELL_HOSTNAME="$parent/$([[ -f /etc/hostname ]] && cat /etc/hostname || echo nohostname)" [[ -d $BASH_SHELL_HOSTNAME ]] && export BASH_SHELL_HOSTNAME [[ -f $BASH_SHELL_HOSTNAME/shell.env ]] && source $BASH_SHELL_HOSTNAME/shell.env # 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 BASH_SHELL_DEV=${BASH_SHELL_DEV:-/opt/shell} [[ -d $BASH_SHELL_DEV ]] && export BASH_SHELL_DEV [[ -f $BASH_SHELL_DEV/shell.env ]] && source $BASH_SHELL_DEV/shell.env # #################### NETWORKING ######################### # set up default location to look for other network shell directories BASH_NETWORKS_DIR=$parent/networks # BASH_NETWORKS_DIR= # alt directory to look for networks export BASH_NETWORKS_DIR # NOTE: one can set one or the other of these in custom shell.env under HOST/USER/DEV repo directories # if you want to load networks with every shell # export BASH_SHELL_HOME_NETWORK_LOAD=true # export BASH_SHELL_NETWORKS_LOAD=true # export BASH_SHELL_NETWORK= # 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} [[ -f $BASH_SHELL_USER_DIR/shell.env ]] && source $BASH_SHELL_USER_DEV/shell.env # now load and export bootstrap module loading functions library so it is always available even for non-interactive shells set -a;source $BASH_SHELL_BASE/module.base;set +a # echo done shell.env # echo ALL DIRS: $BASH_SHELL_DIRS # env | grep BASH # env | grep NETWORK_DIRS # echo --------------------------------- # echo $BASH_SHELL_DIRS # echo --------------------------------- # archived ---for deletion or better explanation # 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 # ################# # expanding aliases is optional # shopt -s expand_aliases # source $BASH_SHELL_LOAD # < your script code > # shopt -u expand_aliases # ###################