diff --git a/README.md b/README.md index 9d49060..1c665a9 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,8 @@ if sourcing some file depends on another preface with numbers to put it before. Be aware that an alias or function set in the repo could be subsuming some existing binary or script. + +interactive non-login shells source /etc/profile via /etc/bash.bashrc otherwise non-interactive non-login shells only load a basic path and access to the module library. One needs to one off source the modules needed for the script. Aliases too are not loaded in this case. + +Thus for non-interactive/non-login shells it is best to symlink a non-module file/directory in modules folder in order to give access to non-interactive shells + diff --git a/archive/.ftpconfig.off b/archive/.ftpconfig.off deleted file mode 100644 index 2f544e0..0000000 --- a/archive/.ftpconfig.off +++ /dev/null @@ -1,23 +0,0 @@ -{ - "protocol": "sftp", - "host": "router", - "port": 22, - "user": "sysadmin", - "pass": "", - "promptForPass": false, - "remote": "/home/sysadmin/.kbd-aliases", - "local": "", - "agent": "env", - "privatekey": "", - "passphrase": "", - "hosthash": "", - "ignorehost": true, - "connTimeout": 10000, - "keepalive": 10000, - "keyboardInteractive": false, - "keyboardInteractiveForPass": false, - "remoteCommand": "", - "remoteShell": "", - "watch": [], - "watchTimeout": 500 -} diff --git a/archive/bower.off b/archive/bower.off deleted file mode 100644 index 20151ba..0000000 --- a/archive/bower.off +++ /dev/null @@ -1,5 +0,0 @@ -# bower -alias bidv="bower install --save-dev" -alias brdv="bower uninstall --save-dev" -alias bi="bower install --save" -alias br="bower uninstall --save" diff --git a/archive/iptables b/archive/iptables deleted file mode 100644 index 378d19e..0000000 --- a/archive/iptables +++ /dev/null @@ -1,9 +0,0 @@ -alias iptl="sudo iptables -S" -alias iptlf="sudo iptables -L" -alias iptln="sudo iptables -L -t nat" -alias iptd="sudo /etc/iptables/iptables-default.sh" -alias iptf="sudo /etc/iptables/iptables-flush.sh" -alias ipts="sudo systemctl start iptables" -alias iptst="sudo systemctl status iptables" -alias iptstp="sudo systemctl stop iptables" -alias iptstpp="sudo /etc/iptables/iptables-default.sh" diff --git a/archive/save.off b/archive/save.off deleted file mode 100644 index 14a8c3e..0000000 --- a/archive/save.off +++ /dev/null @@ -1,14 +0,0 @@ -# if parameter(s) is needed instead of just at the end of alias then create a "little" function instead. -# like mymv() { mv $1 $2; } -# or rsynchc() { rsync --help | grep "\-$1"; } - - -alias sdns="nmcli device show eth0 | grep IP4.DNS" -# shows running processes with ntfs that might hang gparted, then kill with next command -alias ntfs='ps -ef | egrep "dosfsck|ntfs"' - -alias lo="gnome-session-quit" - -#mongo via docker container name mongodbmo -alias mg="docker exec -it mongodbserver mongo" -alias mongodb="docker exec -it mongodbserver mongo" diff --git a/archive/shell.lib b/archive/shell.lib deleted file mode 100644 index ee20ed5..0000000 --- a/archive/shell.lib +++ /dev/null @@ -1,135 +0,0 @@ -#!/bin/bash - -function lines_2_str () ( - [[ ! -f "$1" ]] && return 1 - local str='' - local lines=$(cat "$1") - for line in $lines ; do - str+='"'$line'" ' - done - echo $str - return 0 -) - -function source_dir () { -# USAGE -# will never source source .files or .directories -# all option arguments that contain globs/wildcards must be quoted to avoid expansion -# p option excludes additional paths below of the given name (and depth) -# d option sets the directory depth which is current directy by default, 0 is all -# x excludes file globs -# f inclucdes only file globs otherwise it's all except .files -# if no directory is given it will attempt to source the present working directory -# example: -# source_dir -p "archive" -x '"*.off" "*.md"' -d 0 # $DIR/$SUBDIR -declare OPTION -declare OPTARG -declare OPTIND -local EXCLUDE_FILE -local PATHS -local NAMES -local ENAMES -local DEPTH=1 -local VERBOSE=0 - -while getopts 'p:d:e:n:f:' OPTION; do -case "$OPTION" in - f) - EXCLUDE_FILE=$OPTARG - # echo EXCLUDE FILE $EXCLUDE_FILE - ;; - p) - # PATHS=("$OPTARG") - IFS=',' read -r -a PATHS <<< "$OPTARG" - # echo EXCLUDING THESE PATHS ${PATHS[*]} - ;; - e) - IFS=',' read -r -a ENAMES <<< "${OPTARG}" - # echo EXCLUDING THESE FILE NAMES ${ENAMES[*]} - ;; - n) - # NAMES=("$OPTARG") - IFS=',' read -r -a NAMES <<< "${OPTARG}" - # echo INCLUDING ONLY THESE FILE NAMES ${NAMES[*]} - ;; - d) - DEPTH=$OPTARG - # echo "SOURCING TO DEPTH (0=any)" "$DEPTH" - ;; - *) - echo unknown option $OPTION - ;; -esac -done - -shift $(( OPTIND - 1 )) - -local DIR -DIR="$@" -if [ ! "$DIR" ]; then - if [ -v PS1 ]; then - echo no directory to source provided - echo sourcing present working directory $(pwd) - read -p "Do you want to continue? " -n 1 -r - [[ $REPLY =~ ^[Yy]$ ]] && DIR=$(pwd) || return 1 - else - return 1 - fi -fi - -[ ! -d "$DIR" ] && echo " directory $DIR does not exist, aborting" && return 1 - -# echo dir $DIR - -local FIND -FIND="find $DIR" -FIND+=$([ ! $DEPTH == 0 ] && echo " -maxdepth $DEPTH ") -# ignore all .name and .path by default -# TODO change to having a string -FIND+=" -type f ! -path \"*/.*/*\" ! -name \".*\" " - - -local name -local path - -if [[ -f $EXCLUDE_FILE ]]; then - local ignores=$(cat "$EXLUCDE_FILE") - for exclude in $ignores ; do - [[ "$exclude" =~ '/'$ ]] && PATHS+=(${exclude::-1}) || ENAMES+=($exclude) - done -fi - -if [[ ${PATHS[0]} ]]; then - for path in ${PATHS[@]}; do - # echo excluding $path - FIND+=$(echo ' ! -path "*/'$path'/*"') - done -fi - -if [[ ${ENAMES[0]} ]]; then - for name in ${ENAMES[@]}; do - # echo excluding name $name - FIND+=$(echo " ! -name ${name}") - done -fi - -if [[ ${NAMES[0]} ]]; then - for name in ${NAMES[@]}; do - # echo only finding $name - FIND+=$(echo " -name ${name}") - done -fi - -echo -echo find dir: $DIR -echo find command: $FIND - -local FILES -FILES=$(eval $FIND | sort) -# echo $FILES | xargs -n 1 - for f in $FILES; do - echo sourcing: $f - # source "$f" -done - -} diff --git a/archive/source.func.off b/archive/source.func.off deleted file mode 100644 index 17a2b2d..0000000 --- a/archive/source.func.off +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash - -function source_dir () { -# USAGE -# will never source source .files or .directories -# all option arguments that contain globs/wildcards must be quoted to avoid expansion -# f sets path and file excludes from a supplied file path -# p option excludes additional paths below of the given name (and depth) -# d option sets the directory depth which is current directy by default, 0 is all -# x excludes file globs -# n inclucdes only file globs otherwise it's all except .files -# if no directory is given it will attempt to source the present working directory -# example: -# source_dir -p "archive" -x '"*.off" "*.md"' -d 0 # $DIR/$SUBDIR -declare OPTION -declare OPTARG -declare OPTIND -local EXCLUDE_FILE -local PATHS -local NAMES -local ENAMES -local DEPTH=1 -local VERBOSE=0 - -while getopts 'p:d:e:n:f:' OPTION; do -case "$OPTION" in - f) - EXCLUDE_FILE=$OPTARG - # echo EXCLUDE FILE $EXCLUDE_FILE - ;; - p) - # PATHS=("$OPTARG") - IFS=',' read -r -a PATHS <<< "$OPTARG" - # echo EXCLUDING THESE PATHS ${PATHS[*]} - ;; - e) - IFS=',' read -r -a ENAMES <<< "${OPTARG}" - # echo EXCLUDING THESE FILE NAMES ${ENAMES[*]} - ;; - n) - # NAMES=("$OPTARG") - IFS=',' read -r -a NAMES <<< "${OPTARG}" - # echo INCLUDING ONLY THESE FILE NAMES ${NAMES[*]} - ;; - d) - DEPTH=$OPTARG - # echo "SOURCING TO DEPTH (0=any)" "$DEPTH" - ;; - *) - echo unknown option $OPTION - ;; -esac -done - -shift $(( OPTIND - 1 )) - -local DIR -DIR="$@" -if [ ! "$DIR" ]; then - if [ -v PS1 ]; then - echo no directory to source provided - echo sourcing present working directory $(pwd) - read -p "Do you want to continue? " -n 1 -r - [[ $REPLY =~ ^[Yy]$ ]] && DIR=$(pwd) || return 1 - else - return 1 - fi -fi - -[ ! -d "$DIR" ] && echo " directory $DIR does not exist, aborting" && return 1 - -# echo dir $DIR - -local FIND -FIND="find $DIR" -FIND+=$([ ! $DEPTH == 0 ] && echo " -maxdepth $DEPTH ") -# ignore all .name and .path by default -# TODO change to having a string -FIND+=" -type f ! -path \"*/.*/*\" ! -name \".*\" " - - -local name -local path - -if [[ -f $EXCLUDE_FILE ]]; then - local ignores=$(cat "$EXLUCDE_FILE") - for exclude in $ignores ; do - [[ "$exclude" =~ '/'$ ]] && PATHS+=(${exclude::-1}) || ENAMES+=($exclude) - done -fi - -if [[ ${PATHS[0]} ]]; then - for path in ${PATHS[@]}; do - # echo excluding $path - FIND+=$(echo ' ! -path "*/'$path'/*"') - done -fi - -if [[ ${ENAMES[0]} ]]; then - for name in ${ENAMES[@]}; do - # echo excluding name $name - FIND+=$(echo " ! -name ${name}") - done -fi - -if [[ ${NAMES[0]} ]]; then - for name in ${NAMES[@]}; do - # echo only finding $name - FIND+=$(echo " -name ${name}") - done -fi - -echo -echo find dir: $DIR -echo find command: $FIND - -local FILES -FILES=$(eval $FIND | sort) -# echo $FILES | xargs -n 1 - for f in $FILES; do - echo sourcing: $f - # source "$f" -done - -} diff --git a/load.sh b/load.sh index fc1d386..978ee28 100755 --- a/load.sh +++ b/load.sh @@ -25,9 +25,9 @@ unset BASH_SHELL_LOADED module_load shell-process-directory for dir in ${1:-$BASH_SHELL_DIRS}; do - # echo $dir + echo $dir $BASH_SHELL_BASE shell_process_directory $dir - [[ $dir == "$BASH_SHELL_BASE" ]] && BASH_SHELL_BASE_LOADED=true + [[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true done export BASH_SHELL_LOADED=true diff --git a/module.lib b/module.lib index c45a97d..b12086a 100644 --- a/module.lib +++ b/module.lib @@ -9,7 +9,7 @@ local NAME DIR=$1 NAME=$2 # echo finding $NAME in $DIR -FILE="$(command find ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh)" +FILE="$(command find -L ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh)" # echo files found $FILE COUNT=0 if [ "$FILE" ]; then diff --git a/modules/editing/block/block.sh b/modules/editing/block/block.sh deleted file mode 100755 index 752a76f..0000000 --- a/modules/editing/block/block.sh +++ /dev/null @@ -1,164 +0,0 @@ -#!/bin/bash - -BLOCK_FILE="" -BLOCK_NAME='BLOCK' -BLOCK_COMMENT_CHAR="#" -# a comment added before the block -BLOCK_DESCRIPTION="" - -function __update_block () { - if [ ! -z "$BLOCK_FILE" ]; then - mkdir -p "$(dirname $BLOCK_FILE)" - touch $BLOCK_FILE - tail -c1 $BLOCK_FILE | read -r _ || echo >> $BLOCK_FILE - fi - BLOCK_BEGIN="$BLOCK_COMMENT_CHAR --- ${BLOCK_NAME} BEGIN ---" - BLOCK_END="$BLOCK_COMMENT_CHAR --- ${BLOCK_NAME} END ---" - BLOCK="\n$([ -z "$BLOCK_DESCRIPTION" ] || echo "${BLOCK_COMMENT_CHAR} ${BLOCK_DESCRIPTION}\n")${BLOCK_BEGIN}\n${BLOCK_END}" - # for testing - # BLOCK="a line before\n${BLOCK}\nanother line outside" - -} - -# set block to defaults -__update_block - # echo -e "default block template follows use: block-set before block-add to change>\n" $BLOCK - -function set_block () { - - declare OPTION - declare OPTARG - declare OPTIND - - while getopts ':f:c:d:n:' OPTION; do - # echo $OPTION $OPTARG - case "$OPTION" in - f) - BLOCK_FILE=$OPTARG - echo File set to $BLOCK_FILE - ;; - c) - BLOCK_COMMENT_CHAR=$OPTARG - ;; - d) - BLOCK_DESCRIPTION=$OPTARG - ;; - n) - BLOCK_NAME=$OPTARG - ;; - *) - echo unknown option $OPTION - ;; - esac -done - -shift $(( OPTIND - 1 )) - -__update_block - # echo -e "new block template follows use: block-add >\n" $BLOCK - # echo ---- - echo $([ -e "$BLOCK_FILE" ] || echo "Warning: No output file set yet, use block-set -f " && echo "block will be placed in $BLOCK_FILE") - # echo ------- -} - -function add_block () { -block_remove_content -# only add if it doesn't exist, existance is only based on block begin -local ADD -ADD=$(echo "${BLOCK}" | sed 's/\//\\\//g') -if [ -e "$BLOCK_FILE" ]; then -sed -n '/^[ \t]*'"${BLOCK_BEGIN}"'/{q50}' "${BLOCK_FILE}" -[ $? == 50 ] && return -WHERE=${1-${BLOCK_BEGIN}} # default is end -# echo Where $WHERE -sed -i '/'"${WHERE}"'/{s/.*/&\n'"${ADD}"'/;h};${x;/^$/{s//'"$ADD"'/;H};x}' "${BLOCK_FILE}" -[[ $1 ]] && block_add_line $1 -else - echo "no file set in which to add block, use: ${RED_COLOR}set-block -f " -fi -} - -list_block () { -if [[ $1 =~ -?r(aw)? ]]; then - echo $BLOCK -else - local block - block=${BLOCK##'\n'}'\n' - printf "$block" -fi -} - -get_block_file () { - [ $BLOCK_FILE ] && echo ${BLOCK_FILE} - [[ $1 = -v ]] && echo "no output file set, use set_block -f " -} - -modify_block () { - sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { - /'"${BLOCK_BEGIN}"'/b - /'"${BLOCK_END}"'/b - s/'"${1}"'/'"${2}"'/ - }' "${BLOCK_FILE}" -} - -block_remove_leading () { - printf "%s\n" "$(tac $BLOCK_FILE \ - | sed '/'"${BLOCK_BEGIN}"'/,/^./{ /^[ \t]*$/d}' | tac)" > $BLOCK_FILE -} - -remove_block () { - [[ "$BLOCK_DESCRIPTION" ]] || sed -ni '/'"${BLOCK_BEGIN}"'/{x;d;};1h;1!{x;p;};${x;p;}' "${BLOCK_FILE}" - block_remove_leading - sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { - d - }' "${BLOCK_FILE}" -} - -block_remove_content () { - sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { - /'"${BLOCK_BEGIN}"'/b - /'"${BLOCK_END}"'/b - d - }' "${BLOCK_FILE}" -} - -block_add_line () { -# echo argument count $#, $1, $2, $3 -local ADD -ADD="/^${BLOCK_BEGIN}/a\\${1}" -if [ $# -gt 1 ]; then - if [ "$1" == "--end" ];then - ADD="/${BLOCK_END}/i\\${2}" -else - if [ "$1" == "--before" ];then - ADD="/${2}/i\\${3}" - else - ADD="/${1}/a\\${2}" - fi -fi -fi -# echo $ADD -sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { -'"${ADD}"' -}' "${BLOCK_FILE}" -} - -block_remove_line () { - sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { - /'"${1}"'/d - }' "${BLOCK_FILE}" -} - -block_change_line () { - sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { - /'"${1}"'/c\'"${2}"' - }' "${BLOCK_FILE}" -} - -block_modify_line () { - sed -i '/^'"${BLOCK_BEGIN}"'/,/^'"${BLOCK_END}"$'/ { - /'"${BLOCK_BEGIN}"'/b - /'"${BLOCK_END}"'/b - /'"${1}"'/{s/'"${2}"'/'"${3}"'/} - }' "${BLOCK_FILE}" -} diff --git a/modules/editing/block/test/test.sh b/modules/editing/block/test/test.sh deleted file mode 100755 index 4ae3972..0000000 --- a/modules/editing/block/test/test.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash -rm test.txt -echo "some first text -some middle text -some after text" > test.txt -source ./block.sh -set-block -n "GO ENVIRONMENT" -d "comment before" -set-block -f "./test.txt" -# add-block "some middle text" -add-block -block-remove-content -block-add-line "1 added to beginning" -block-add-line --end "2 added to end" -block-add-line "3 yet another added to beginning" -block-add-line "4 yet yet another added to beginning -- remove later" -block-add-line --end "5 finally one added to end" -block-add-line ^2 "added after line 2" -block-add-line --before ^2 "added before line 2" -block-change-line "finally" "last line was changed to this" -echo modifying block -sleep 5 -block-modify-line "3" yet **yet** -modify-block added *added* -echo removing line with "remove" -sleep 5 -block-remove-line "remove" -echo "done with example, deleting" -sleep 5 -echo removing block now -remove-block diff --git a/modules/editing/replace/replace.sh b/modules/editing/replace/replace.sh deleted file mode 100755 index cdbb08f..0000000 --- a/modules/editing/replace/replace.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -function replace { - local PATTERN=$1; shift - local NEW_LINE=$1; shift - local FILE=$1; shift - [ ! "$PATTERN" ] || [ ! $FILE ] && return 1 - local BEFORE=$1 - local NEW=$(echo "${NEW_LINE}" | sed 's/\//\\\//g') - echo finding: $PATTERN Replace with $NEW before $BEFORE in $FILE - touch "${FILE}" || return 1 - echo matching: $PATTERN - match=false - if [ "$NEW_LINE" ]; then - sed -i '/'"${PATTERN}"'/{s/.*/'"${NEW}"'/;h};${x;/./{x;q100};{x;q20}}' "${FILE}" - [[ $? -eq 100 ]] && match=true - echo match $match - if [ $match == false ]; then - echo adding new entry $NEW_LINE - if [ "$BEFORE" ]; then - echo searching for $BEFORE to add line before - # sed -i '/'"${BEFORE}"'/{i/.*/'"${NEW}"'/;h};${x;/./{x;q100};x}' "${FILE}" - sed -i '/'"${BEFORE}"'/!{q20};/'"${BEFORE}"'/i\'"${NEW}" "${FILE}" - echo return $? - exit - # ;/i '"${NEW}"'' "${FILE}" - [[ $? -eq 100 ]] && match=true || match=false - echo before match $match - fi - # if [ $match == false ]; then - # echo appending to file - # echo "${NEW_LINE}" >> "${FILE}" - # fi - else echo line matched/replaced - fi - else - sed '/'"${PATTERN}"'/d' "${FILE}" - echo line removed - fi -} diff --git a/modules/utility/bundle.sh b/modules/utility/bundle.sh index 9e7a8e4..7880177 100644 --- a/modules/utility/bundle.sh +++ b/modules/utility/bundle.sh @@ -4,6 +4,9 @@ # if no output file then the bundled source is returned # it can be immediately invoked like this # source <(bundle myscript.sh) +# or +# scpt=$(bundle myscript.sh) +# source <(echo -e "$scpt") bundle () { @@ -13,7 +16,7 @@ module_load file if [[ ! $2 == "__recurse__" ]]; then tmp_file=$( mktemp -t TEMP_FILE_bundle.XXXXXXXX ) chmod 600 "$tmp_file" -cp $1 $tmp_file +\cp $1 $tmp_file else tmp_file=$1 fi @@ -35,8 +38,8 @@ fi if [[ ! $2 == "__recurse__" ]]; then if [[ $2 ]]; then - cp $tmp_file $2 - echo $2 + \cp $tmp_file $2 + # echo $2 else echo -e "$(cat $tmp_file)" fi diff --git a/modules/utility/file.lib b/modules/utility/file.lib index 7de9595..be58838 100644 --- a/modules/utility/file.lib +++ b/modules/utility/file.lib @@ -203,8 +203,6 @@ source_dir () { } - - prepend_file () { # ---------------------------------------------------------------------------------------------------------------------- # usage prepend_file @@ -214,8 +212,8 @@ prepend_file () { # ---------------------------------------------------------------------------------------------------------------------- # check # echo $1 $2 -[[ -f $1 ]] || { iecho "no file $1 to prepend";return 1; } -[[ -f $2 ]] || { iecho "no file $2 to which to prepend $1";return 2; } +[[ -f $1 ]] || return 1 +[[ -f $2 ]] || return 2 # init tmp_fn=$( mktemp -t TEMP_FILE_prepend.XXXXXXXX ) chmod 600 "$tmp_fn" @@ -225,7 +223,6 @@ cat $2 >> $tmp_fn \mv "$tmp_fn" "$2" # cleanup rm -f "$tmp_fn" -iecho "file $1 prepened to $2" return 0 # [End] diff --git a/setup/etc/profile b/setup/etc/profile index 09a0b09..aa5f38b 100644 --- a/setup/etc/profile +++ b/setup/etc/profile @@ -1,13 +1,26 @@ - #!/bin/bash +#!/bin/bash + +# do not add code here for non-interative login shell +# rather put additional non-interactive profile script code in files in /etc/profile.d + +# this files is sourced for all login shells and also interactive non-login shells via /etc/bash.bashrc +# more info see http://www.linuxfromscratch.org/blfs/view/svn/postlfs/profile.html + +# interactive non-login and login shells will call the BASH_SHELL_LOAD script below +# non-interative login shells only source /etc/profile.d +# in profile.d is 03-startup.sh which will call +# any of the scripts in a repo's startup subdirectory +# non-interactive non-login shells are not handled here only via /etc/bash.bashrc +# interactive login -# do not add code here. -# organize additional profile script code in files /etc/profile.d ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]) && export SSH_SESSION=true [[ $- == *i* ]] && export SHELL_INTERACTIVE=true shopt -q login_shell && export SHELL_LOGIN=true [ $EUID -eq 0 ] && export USER_ROOT=true +# uncomment for debugging non-interactive login shell, i.e. $ . /etc/profile +#unset SHELL_INTERACTIVE #uncomment these for debugging. # echo ---- sourcing system /etc/profile --- @@ -17,32 +30,32 @@ shopt -q login_shell && export SHELL_LOGIN=true # [[ $SSH_SESSION ]] && echo ssh remote user || echo local user # echo --------------------- -# 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:/usr/local/bin # set directory for base shell repo export BASH_SHELL_BASE=THISWILLCHANGEDBYDEPLOYSCRIPT # now bootstrap by souring the shell repo envinroment source $BASH_SHELL_BASE/shell.env -# uncomment to NOT load the BASH SHELL Repos for interactive login shell -# NO_BASH_SHELL=true +# set $BASH_SAFE_MODE=true in shell.env to disable UCI interactive shell from loading +# TODO see if $NO_BASH_SHELL_SSH=true in user or host directory (at the remote machine) +# if so don't source the load command below and make just a simple prompt. if [[ $SHELL_INTERACTIVE ]]; then - if [[ ! $NO_BASH_SHELL ]]; then + if [[ ! $BASH_SAFE_MODE ]]; then # echo interactive shell loading $BASH_SHELL_LOAD source "$BASH_SHELL_LOAD" else + # safe mode # just set a simple prompt instead NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" + YELLOW='\e[1;33m' if [[ $EUID == 0 ]] ; then - PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL" + PS1="${YELLOW}SAFE:$RED\u [ $NORMAL\w$RED ]# $NORMAL" else - PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL" + PS1="${YELLOW}SAFE:$GREEN \u [ $NORMAL\w$GREEN ]\$ $NORMAL" fi - unset RED GREEN NORMAL + unset RED GREEN NORMAL YELLOW fi else # this is non-interactive login (e.g. at user machine login) diff --git a/shell.env b/shell.env index 2c1b950..40b3420 100755 --- a/shell.env +++ b/shell.env @@ -1,63 +1,76 @@ #!/bin/bash -# Shell Repos Environment -# Customize Bash Shell setup here +# 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 + +# 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 ) -# 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_HOST=$BASH_SHELL_BASE -# $BASH_SHELL_NETWORK/all -# $BASH_NETWORK_DIR # extra directory to look for networks, $BASH_SHELL_NETWORK is always checked -# $BASH_SHELL_HOST/all -# $BASH_SHELL_HOST/ -# also -# sourced via $HOME/.bashrc -# $HOME/shell or $HOME/BASH_SHELL_USER +# 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 -# 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 +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 -# 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 - - -# BASH_SHELL_BASE is set in /etc/profile do not change here! +# 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 # strtup.sh is default -# if uncommented next lines sets up implicit sourcing for non-interactive shells -# echo ----NON_INTERACTIVE SHELL----- -# 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 # 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 --------- +export BASH_SHELL_STARTUP=$BASH_SHELL_BASE/startup.sh # startup.sh is default -# 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 -#################### +# 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 +# -- any +# -- 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) @@ -96,6 +109,11 @@ network_dirs "$BASH_SHELL_HOST/.networks" # these loaded only for specific user on a host network_dirs "$HOME/${BASH_SHELL_USER:-"shell"}/.networks" +# 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 +export BASH_SHELL_DEV=/opt/shell +BASH_SHELL_DIRS+="$BASH_SHELL_DEV " + export BASH_SHELL_DIRS # echo ALL DIRS: $BASH_SHELL_DIRS @@ -109,6 +127,18 @@ export BASH_SHELL_DIRS # echo $BASH_SHELL_DIRS # echo --------------------------------- - - # echo end shell env + + +#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 +#################### diff --git a/startup.sh b/startup.sh index f73728d..692ec70 100755 --- a/startup.sh +++ b/startup.sh @@ -2,7 +2,7 @@ [[ $(declare -F | grep module_load) ]] && echo module lib already loaded || source "$BASH_SHELL_BASE/module.lib" module_load file -[[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1 +[[ $? -ne 0 ]] && echo unable to access the file module, aborting load && return 1 DIRS=(${BASH_SHELL_DIRS}) # llog "startup directories to try ${DIRS[*]}" diff --git a/test/path.tst b/test/path.tst deleted file mode 100755 index de6b0ea..0000000 --- a/test/path.tst +++ /dev/null @@ -1,12 +0,0 @@ -#!/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