refactor the way the module library is loaded

added startup script callable from profile.d
renamed setup.sh to load.sh
added rsync copy function cprs
added shell.env that is called by /etc/profile to set up access to this  and related repos
master
David Kebler 2020-11-13 10:25:04 -08:00
parent e25e44a98d
commit 0ac5906eee
38 changed files with 357 additions and 237 deletions

View File

@ -1,7 +1,11 @@
# 00 will get loaded first # 00 will get loaded first
# does root login with calls profile and loads all the shells
alias sudo='sudo -i'
alias flist="function_list" alias flist="function_list"
alias flistg="function_list | grep" alias flistg="function_list | grep"
alias fprint="declare -f"
alias aliasg="alias | grep " alias aliasg="alias | grep "
alias envg="env | grep " alias envg="env | grep "
@ -11,9 +15,6 @@ alias envg="env | grep "
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# brings user path to sudo # brings user path to sudo
alias sudoi='sudo -i env PATH=$PATH'
alias sudoh='sudo -H'
alias reboot="sudo systemctl reboot" alias reboot="sudo systemctl reboot"
alias poweroff="sudo systemctl poweroff" alias poweroff="sudo systemctl poweroff"
@ -49,6 +50,7 @@ alias cd..='cd ..'
alias cp='cp -i' alias cp='cp -i'
alias mpath="echo $PATH" # machine path per /etc/environment alias mpath="echo $PATH" # machine path per /etc/environment
alias path='echo $PATH' alias path='echo $PATH'
alias pathg='echo $PATH | grep'
alias sysinfo='sudo inxi -Fzxd' alias sysinfo='sudo inxi -Fzxd'
alias efstab="cp /etc/fstab ~/fstab.bak && gedit admin:/etc/fstab" alias efstab="cp /etc/fstab ~/fstab.bak && gedit admin:/etc/fstab"

9
alias/shell Normal file
View File

@ -0,0 +1,9 @@
alias ebashrc="gedit $HOME/.bashrc"
alias eetcbashrc="sudo gedit /etc/bash.bashrc"
alias eetcprofile="sudo gedit /etc/profile"
alias eprofile="gedit $HOME/.bash_profile"
alias cbashrc="cp $HOME/.bashrc $BASH_SHELL_BASE/setup"
alias cetcbashrc="cp /etc/bash.bashrc $BASH_SHELL_BASE/setup"
alias cprofile="cp $HOME/.bash_profile $BASH_SHELL_BASE/setup"
alias cetcprofile="cp /etc/profile $BASH_SHELL_BASE/setup"

1
app/qt Normal file
View File

@ -0,0 +1 @@
export QT_SELECT=qt5

30
env/00-shell.env vendored
View File

@ -1,30 +0,0 @@
# Additional Shell Repos to Source
# BASH_SHELL is a common parent directory that should be set in /etc/bash.bashrc
# unless below specific directories are set
# shell files are sourced in this order
# sourced via /etc/bash.bashrc so for all machine users
# $BASH_SHELL_BASE # this MUST be set in /etc/bash.bashrc
# $BASH_SHELL_NETWORK/all
# $BASH_SHELL_NETWORK/$NETWORKNAME
# $BASH_SHELL_HOST/all
# $BASH_SHELL_HOST/<hostname>
# sourced via $HOME/.bashrc
# $HOME/shell or $HOME/BASH_SHELL_USER
# within each of those directories if setup.sh exits it will be run
# otherwise files will be sourced exactly like in the base
# identify a network name that this host resides on
# like hostname but for the LAN network
# if unset then only /all will be sourced
export NETWORKNAME=238
# will use $BASH_SHELL_NETWORK/$NETWORKNAME under this directory unless specifically set
export BASH_SHELL_NETWORK=$BASH_SHELL/network
# will use $BASH_SHELL_HOST/<hostname> unless specifically set
export BASH_SHELL_HOST=$BASH_SHELL/host
# 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>

4
env/01-opt.path vendored
View File

@ -1,4 +0,0 @@
# include binaries in /optu
if [ -d "/opt/bin" ] ; then
PATH="/opt/bin:$PATH"
fi

17
env/01-path vendored Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
# if [[ $(groups | grep sudo ) ]]; then
# path_insert /sbin after /usr/bin
# pathg bin
# path_insert /usr/sbin after :/sbin
# pathg bin
# path_insert /usr/local/sbin after /usr/sbin
# pathg sbin
# fi
if [[ $(groups | grep sudo ) ]]; then
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
fi
path_append /opt/bin
path_append "$HOME/bin"
path_append "$HOME/.local/bin"

9
env/02-user.path vendored
View File

@ -1,9 +0,0 @@
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi

5
env/editor.env vendored
View File

@ -1,3 +1,4 @@
# used by aliases that need an editor # used by aliases that need an editor
export EDITOR=atom # export EDITOR=atom
# export EDITOR=nano # export ELECTRON_TRASH=gio
export EDITOR=nano

View File

@ -7,8 +7,6 @@ shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will # If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories. # match all files and zero or more directories and subdirectories.
#shopt -s globstar #shopt -s globstar
# if expanding aliases in all non-interactive shell is desired then uncomment
shopt -s expand_aliases
# enable programmable completion features (you don't need to enable # enable programmable completion features (you don't need to enable
# if it's already enabled in /etc/bash.bashrc and /etc/profile # if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc). # sources /etc/bash.bashrc).

View File

@ -5,6 +5,7 @@
function function_list() { function function_list() {
if [ $1 ]; then if [ $1 ]; then
# will list functions in passed file
local STR local STR
local func local func
declare -a FUNCS declare -a FUNCS
@ -20,6 +21,7 @@ function function_list() {
done done
echo "${FUNCS[@]}" echo "${FUNCS[@]}"
else else
# will list all sourced/declared functions available
echo echo
echo -e "\033[1;4;32m""Functions:""\033[0;34m" echo -e "\033[1;4;32m""Functions:""\033[0;34m"
declare -F | grep -v "declare -f\s_" | awk {'print $3'} declare -F | grep -v "declare -f\s_" | awk {'print $3'}

View File

@ -1,24 +0,0 @@
path_remove () {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
path_prepend () {
path_remove $1 $2
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}
path_append () {
path_remove $1 $2
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}

49
function/02-path Normal file
View File

@ -0,0 +1,49 @@
#!/bin/bash
path_remove () {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
path_prepend () {
path_remove $1 $2
if [ -d "$1" ]; then
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
fi
}
path_append () {
path_remove $1 $2
if [ -d "$1" ]; then
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
fi
}
path_insert () {
if [ -d "$1" ]; then
local PATHVAR=${4:-PATH}
local temp
echo inserting $1 into ${!PATHVAR} $2 $3
boa=$([[ $2 == b* ]] && echo "$1:&" || echo "&:$1:")
temp="$(echo ${!PATHVAR} | sed -r "s#$3(:)?#$boa#" | sed 's#^:##' | sed 's#\:$##' | sed 's#::#:#g' )"
echo result: $temp
export PATHVAR=$temp
fi
}
# path_insert_before () {
# _path_insert b "$@"
# }
#
# path_insert_after () {
# _path_insert a "$@"
# }

View File

@ -1,45 +0,0 @@
#!/bin/bash
valid_ip()
{
local ip=$1
local stat=1
local res
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
res=$([ $? == 0 ] && echo true || echo false)
else
res=false
fi
echo $res
}
get_domain() {
local domain
domain=$(echo $1 | awk -F\. '{print $(NF-1) FS $NF}')
echo "$domain"
}
# must be json as a string, depends on jq
get_prop_value () {
local value
# echo in $1 get $2
value=$(echo $1 | jq -r .$2)
echo $value
}
mounted () {
[[ ! $1 ]] && echo no mount point to test && return 2
mountpoint "$1" &> /dev/null && echo yes || return 1
}
is_array() {
local variable_name=$1
[[ "$(declare -p $variable_name 2>/dev/null)" =~ "declare -a" ]]
}

13
function/rsync Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# simple copy using rsync. Preserves everything
# present working directory to supplied destination
module_load confirm
function cprs () {
[ $# -ne 2 ] && echo two directories source and destination need to be passed && return 1
[ ! -d "$1" ] && echo source: $1 is not a directory && return 1
[ ! -d "$2" ] && echo destination: $2 is not a directory && return 1
echo Command to run: rsync --progress -a -r -u "$1" "$2"
confirm Do you want to start the rsync copy? || return 0
echo copying.....
rsync --progress -a -r -u "$1" "$2"
}

View File

@ -1,9 +1,10 @@
#!/bin/bash #!/bin/bash
if command -v node >/dev/null 2>&1; then if command -v node >/dev/null 2>&1; then
# echo addding node langauge stuff
# gives access to packages with bin in a project # gives access to packages with bin in a project
export PATH=$PATH:./node_modules/.bin path_append ./node_modules/.bin
export PATH=$PATH:/opt/node-global-apps/bin path_append /opt/node-global-apps/bin
export NPM_REGISTRY=https://npm.kebler.net export NPM_REGISTRY=https://npm.kebler.net

40
load.sh
View File

@ -1,13 +1,27 @@
#!/bin/bash #!/bin/bash
# don't bother if bash is not the shell
[ ! "$SHELL" = "/bin/bash" ] && return 1
DIR=${1:-$(dirname ${BASH_SOURCE[0]})} DIR=${1:-$(dirname ${BASH_SOURCE[0]})}
# source the required directory source function # source the required directory source function
if [ ! -e "$BASH_SHELL_BASE/source-dir.func" ]; then if [ ! -e "$BASH_SHELL_BASE/source-dir.func" ]; then
echo "!Unable to load sourcing function at $DIR/source-dir, shell not set up!" echo "!Unable to load sourcing function at $DIR/source-dir, shell not set up!"
return 1
else else
. $BASH_SHELL_BASE/source-dir.func source "$BASH_SHELL_BASE/source-dir.func"
# source the default shopt options fi
[ -e "$DIR/options" ] && . $DIR/options
if [ ! -e "$BASH_SHELL_BASE/module.lib" ]; then
echo "!Unable to load module library functions function at $DIR/module.lib, shell not set up!"
return 1
else
source "$BASH_SHELL_BASE/module.lib"
fi
# REMOVED sourced via env directory
# [ -e "$DIR/options" ] && . $DIR/options
function shell_process_directory () { function shell_process_directory () {
local SUBDIRS local SUBDIRS
@ -18,7 +32,7 @@ else
# echo soucring directory $DIR # echo soucring directory $DIR
if [ -d "$DIR" ]; then if [ -d "$DIR" ]; then
if [ "$DIR" = "$BASH_SHELL_BASE" ] && [ "$BASH_SHELL_BASE_SOURCED" = "true" ]; then if [ "$DIR" = "$BASH_SHELL_BASE" ] && [ "$BASH_SHELL_BASE_LOADED" = "true" ]; then
if [ -v PS1 ]; then if [ -v PS1 ]; then
echo base directory already sourced echo base directory already sourced
read -p "do you want to re-source the base (not recommended)? " -n 1 -r read -p "do you want to re-source the base (not recommended)? " -n 1 -r
@ -31,7 +45,7 @@ else
fi fi
if [ -f "$DIR/$BASH_SHELL_LOAD" ] && [ "$DIR" != "$BASH_SHELL_BASE" ]; then if [ -f "$DIR/$BASH_SHELL_LOAD" ] && [ "$DIR" != "$BASH_SHELL_BASE" ]; then
echo "$DIR/$BASH_SHELL_LOAD" found, running instead of default processing # echo "$DIR/$BASH_SHELL_LOAD" found, running instead of default processing
source "$DIR/$BASH_SHELL_LOAD" source "$DIR/$BASH_SHELL_LOAD"
else else
# default processing # default processing
@ -39,7 +53,7 @@ else
local DSUBDIRS local DSUBDIRS
# default subdirectories to source # default subdirectories to source
# TODO allow passing in additional directories # TODO allow passing in additional directories
DSUBDIRS="function env alias misc lang app" DSUBDIRS="function alias env misc lang app"
IFS=' ' read -r -a SUBDIRS <<< "${2:-$DSUBDIRS}" IFS=' ' read -r -a SUBDIRS <<< "${2:-$DSUBDIRS}"
# echo ${SUBDIRS[@]} # echo ${SUBDIRS[@]}
for SUBDIR in "${SUBDIRS[@]}" for SUBDIR in "${SUBDIRS[@]}"
@ -62,18 +76,20 @@ else
} }
# process the base directory by default # process the base directory by default
unset BASH_SHELL_BASE_SOURCED unset BASH_SHELL_BASE_LOADED
shell_process_directory unset BASH_SHELL_LOADED
export BASH_SHELL_BASE_SOURCED=true
shell_process_directory # process base
export BASH_SHELL_BASE_LOADED=true
# process network # process network
shell_process_directory "$BASH_SHELL_NETWORK/all" shell_process_directory "$BASH_SHELL_NETWORK/all"
[ $NETWORKNAME ] && shell_process_directory "$BASH_SHELL_NETWORK/$NETWORKNAME" [ $NETWORKNAME ] && shell_process_directory "$BASH_SHELL_NETWORK/$NETWORKNAME"
# process host # process host
shell_process_directory "$BASH_SHELL_HOST/all" shell_process_directory "$BASH_SHELL_HOST/all"
shell_process_directory "$BASH_SHELL_HOST/$(hostname)" shell_process_directory "$BASH_SHELL_HOST/$(hostname)"
export BASH_SHELL_LOADED=true
# process user # process user
# Note: $HOME/shell or $HOME/BASH_SHELL_USER are sourced via $HOME/.bashrc # Note: $HOME/shell or $HOME/BASH_SHELL_USER are sourced via $HOME/.bashrc
# echo $(envg BASH) | xargs -n 1 # echo $(envg BASH) | xargs -n 1
fi

View File

@ -98,6 +98,11 @@ module_loaded () {
return $ret return $ret
} }
# exported for login environment
export -f module_load
export -f module_find
export -f module_confirm
function test_modules { function test_modules {
RED='\033[0;31m' RED='\033[0;31m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
@ -117,3 +122,6 @@ echo ----------------------
echo -e "testing: ${RED}module_loaded${NC}" echo -e "testing: ${RED}module_loaded${NC}"
module_loaded $1 module_loaded $1
} }
#comment this out if testing
unset -f test_modules

View File

@ -0,0 +1,6 @@
#!/bin/bash
# must be json as a string, depends on jq
mounted () {
[[ ! $1 ]] && echo no mount point to test && return 2
mountpoint "$1" &> /dev/null && echo yes || return 1
}

View File

@ -0,0 +1,13 @@
#!/bin/bash
# must be json as a string, depends on jq
get_prop_value () {
local value
# echo in $1 get $2
value=$(echo $1 | jq -r .$2)
echo $value
}
is_array() {
local variable_name=$1
[[ "$(declare -p $variable_name 2>/dev/null)" =~ "declare -a" ]]
}

View File

@ -1,6 +0,0 @@
#!/bin/bash
# uncomment for debuggin
echo ".bash_profile sourced at user $USER login"
[[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"
[[ $- == *i* ]] || statup_load $HOME/$BASH_SHELL_USER

View File

@ -1,20 +0,0 @@
# source bash.bashrc for both login and non login shells
# note: bash.bashrc sources the base shell repo
echo in profile.d/bash.sh
if [ "${SHELL-}" ] && [ "$SHELL" != "/bin/sh" ] && [ -f /etc/bash.bashrc ]; then
# uncomment for debugging
echo sourcing bash.bashrc now from /etc/profile.d/bash.sh
source /etc/bash.bashrc
[ $EUID -ne 0 ] && startup_load # if not root source this
else # set up basic stuff (e.g a prompt) if not able to source bash.bashrc
echo Unable to source bash.bashrc, Setting up red prompt for root and a green one for users.
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
unset RED GREEN NORMAL
fi

View File

@ -1,27 +0,0 @@
#!/bin/bash
# uncomment these for debugging.
echo sourcing system wide bash.bashrc
[ $EUID -eq 0 ] && echo 'Root User' || echo 'Non Root User'
[[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
# Using base shell setup repository
# https://git.kebler.net/kebler.net/bash-shell-base.git
export BASH_SHELL_LOAD=load.sh # script to run that loads in base shell repo
# use these two if you want a common directory for all shell repos
export BASH_SHELL=/opt/bash/shell # set this based on where you cloned the base repo
export BASH_SHELL_BASE=$BASH_SHELL/base
# otherwise uncomment
# export BASH_SHELL_BASE=/opt/shell/base # set this based on where you cloned the base repo
# if uncommented next line sets up implicit sourcing for non-interactive shells
export BASH_ENV=$BASH_SHELL_BASE/$BASH_SHELL_LOAD # use base repo
# this gets the ball rolling my loading the base shell
source $BASH_SHELL_BASE/$BASH_SHELL_LOAD
# if not using implicit sourcing for non-interactive shells then on can do this per script likely
##################
# source $BASH_SHELL_BASE/load.sh
# shopt -s expand_aliases
# < your script code >
# shopt -u expand_aliases
####################

10
setup/etc/bash.bashrc Normal file
View File

@ -0,0 +1,10 @@
#!/bin/bash
# uncomment these for debugging.
# echo ---- sourcing system wide bash.bashrc ---
# [ $EUID -eq 0 ] && echo 'Root User' || echo 'Non Root User'
# [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
# shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
# echo ----
# echo sourcing $BASH_SHELL_LOAD
source $BASH_SHELL_LOAD

62
setup/etc/profile Normal file
View File

@ -0,0 +1,62 @@
#!/bin/bash
# put no script code directly here.
# organize all script code in files /etc/profile.d
# uncomment for debugging
# echo ---- system profile /etc/profile sourced at login ----
# [ $EUID -eq 0 ] && echo 'Root User' || echo 'Non Root User'
# [[ $- == *i* ]] && echo 'Interactive' || echo 'Not interactive'
# shopt -q login_shell && echo 'Login shell' || echo 'Not login shell'
# echo -----------
# main /etc/profile loaded for all logins
# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
export LOGIN_LOG=$HOME/logs/login.log
mkdir -p $HOME/logs
touch $LOGIN_LOG
llog () {
echo "$@" 2>&1 | tee -a $LOGIN_LOG
}
export -f llog
# Set the initial path
export PATH=/bin:/usr/bin:/usr/local/bin
# set directory for base shell repo
export BASH_SHELL_BASE=/opt/bash/shell/base # where
# now bootstrap by souring the shell repo envinroment
. $BASH_SHELL_BASE/shell.env
llog "$(env | grep BASH)"
if [[ $- == *i* ]]; then # interactive?
echo interactive login shell
if [[ ! $NO_LOGIN_BASHRC ]]; then
echo loading $BASH_SHELL_LOAD
source "$BASH_SHELL_LOAD"
else
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL"
else
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi
unset RED GREEN NORMAL
fi
else
echo "$(date)" > $LOGIN_LOG
llog "non-interactive login shell for $USER"
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
llog "sourcing $i"
source $i
fi
done
unset i
fi
fi

View File

@ -1,6 +1,6 @@
# root login setup only, put in if block # root login setup only, put in if block
if [ $EUID -eq 0 ] ; then # if root user if [ $EUID -eq 0 ] ; then # if root user
echo root specific setup echo login profile, root specific setup
export PATH=$PATH:/sbin:/usr/sbin export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
unset HISTFILE unset HISTFILE
fi fi

View File

@ -0,0 +1,8 @@
# this runs startups for bash shell base system
if [ "$SHELL" = "/bin/bash" ] && [ "${BASH_SHELL_STARTUP}" ]; then
# uncomment for debugging
if [[ -f $BASH_SHELL_STARTUP ]] && [[ $EUID -ne 0 ]]; then
llog "running startup script $BASH_SHELL_STARTUP async"
(${BASH_SHELL_STARTUP}) &
fi
fi

View File

@ -1,37 +0,0 @@
#!/bin/bash
# main /etc/profile loaded for all logins
# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html
# Set the initial path
export PATH=/bin:/usr/bin
# uncomment for debugging
echo system profile /etc/profile sourced at login
# put no script code directly here.
# organize all script code in files /etc/profile.d
# sourcing
if [[ $- == *i* ]] && [[ $EUID -ne 0 ]]; then
echo non root interactive login shell, will not source /etc/profile.d
if [[ $FORCE_LOAD_BASH_SHELL_BASE ]]; then
echo "forcing source of shell base: $BASH_SHELL_BASE/$BASH_SHELL_LOAD"
source "$BASH_SHELL_BASE/$BASH_SHELL_LOAD"
else
BASH_SHELL_BASE_SOURCED=false
NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
unset RED GREEN NORMAL
fi
else
echo sourcing /etc/profile.d
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
source $i
fi
done
unset i
fi
fi

6
setup/root/.bash_profile Normal file
View File

@ -0,0 +1,6 @@
# echo $USER .bash_profile
export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
source $BASH_SHELL_LOAD
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

1
setup/root/.bashrc Normal file
View File

@ -0,0 +1 @@
# echo $USER .bashrc

9
setup/root/.profile Normal file
View File

@ -0,0 +1,9 @@
# ~/.profile: executed by Bourne-compatible login shells.
echo $USER .profile
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi

7
setup/user/.bash_logout Normal file
View File

@ -0,0 +1,7 @@
# ~/.bash_logout: executed by bash(1) when login shell exits.
# when leaving the console clear the screen to increase privacy
if [ "$SHLVL" = 1 ]; then
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi

5
setup/user/.bash_profile Normal file
View File

@ -0,0 +1,5 @@
#!/bin/bash
# uncomment for debuggin
echo ".bash_profile sourced at user $USER login"
# [[ $- == *i* ]] && [[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc"

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
echo "$USER .bashrc" # echo "$USER .bashrc"
# processing user's shell directory # processing user's shell directory
[[ $BASH_SHELL_BASE_SOURCED = true ]] && \ [[ $BASH_SHELL_BASE_SOURCED = true ]] && \

2
setup/user/.profile Normal file
View File

@ -0,0 +1,2 @@
echo .profile, user $USER
echo "this only is sourced if .bash_profile doesn't exist"

60
shell.env Normal file
View File

@ -0,0 +1,60 @@
# Shell Repos to Source
# if bash is not the shell don't bother to continue
[ ! "$SHELL" = "/bin/bash" ] && return 1
# 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/$NETWORKNAME
# $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 is 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 line sets up implicit sourcing for non-interactive shells
export BASH_ENV=$BASH_SHELL_LOAD # use base repo
# if not using implicit sourcing for non-interactive shells then on can do this per script
##################
# source $BASH_SHELL_BASE/$BASH_SHELL_BASE/${$BASH_SHELL_LOAD:-load.sh}
# shopt -s expand_aliases
# < your script code >
# shopt -u expand_aliases
####################
# identify a network name that this host resides on
# like hostname but for the LAN network
# if unset then only /all will be sourced
export NETWORKNAME=238
# will use $BASH_SHELL_NETWORK/$NETWORKNAME under this directory unless specifically set
export BASH_SHELL_NETWORK=/opt/bash/shell/network
# will use $BASH_SHELL_HOST/<hostname> unless specifically set
export BASH_SHELL_HOST=/opt/bash/shell/host
# 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>
# load and export module loading functions library
source $BASH_SHELL_BASE/module.lib

View File

@ -105,7 +105,7 @@ FILES=$(eval $FIND | sort)
# echo $FILES | xargs -n 1 # echo $FILES | xargs -n 1
for f in $FILES; do for f in $FILES; do
# echo sourcing: $f # echo sourcing: $f
. "$f" source "$f"
done done
} }

18
function/startup → startup.sh Normal file → Executable file
View File

@ -5,15 +5,15 @@ local SDIRS
local SDIR local SDIR
local DIRS local DIRS
DIRS=( \ DIRS=( \
$BASH_SHELL_HOST/$(hostname)
$BASH_SHELL_HOST/all \
$BASH_SHELL_NETWORK/$NETWORKNAME \
$BASH_SHELL_NETWORK/all \
$BASH_SHELL_BASE \ $BASH_SHELL_BASE \
$BASH_SHELL_NETWORK/all \
$BASH_SHELL_NETWORK/$NETWORKNAME \
$BASH_SHELL_HOST/all \
$BASH_SHELL_HOST/$(hostname) \
) )
echo directories ${DIRS[*]}
[[ $1 ]] && DIRS=("$1") [[ $1 ]] && DIRS=("$1")
echo startup ${DIRS[@]} llog "startup directories to try ${DIRS[*]}"
SDIRS=() SDIRS=()
j=0 j=0
cnt=${#DIRS[@]} cnt=${#DIRS[@]}
@ -26,10 +26,14 @@ done
[ $STARTUP_DIRS ] && SDIRS=("$STARTUP_DIRS" "${SDIRS[@]}") [ $STARTUP_DIRS ] && SDIRS=("$STARTUP_DIRS" "${SDIRS[@]}")
# echo -e "Statup Directories to source \n ${SDIRS[@]} \n" # echo -e "Statup Directories to source \n ${SDIRS[@]} \n"
source $BASH_SHELL_BASE/source-dir.func
for SDIR in "${SDIRS[@]}" for SDIR in "${SDIRS[@]}"
do do
# echo startup dir to source $SDIR llog "startup dir to source $SDIR"
source_dir -p "archive" -x '"*.off" "*.md"' -d 0 $SDIR source_dir -p "archive" -x '"*.off" "*.md"' -d 0 $SDIR
done done
} }
# if script was executed then call the function
(return 0 2>/dev/null) || startup_load

12
test/path.tst Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
echo path functions test script
src=$BASH_SHELL_BASE/function/01-path
[[ -f $src ]] && source "$src" || echo no file: $src
export test_path=/bin:/usr/bin:/opt/go/bin
ins=/usr/sbin
path_insert $ins after /usr/bin test_path
path_insert $ins before /usr/bin test_path
path_insert $ins after /opt/go/bin test_path
path_insert $ins before ^/bin: test_path
unset test_path
unset ins