From 3656f1420e789b81852530f9625bbad708271736 Mon Sep 17 00:00:00 2001 From: "kebler.net" Date: Fri, 5 Feb 2021 13:00:57 -0800 Subject: [PATCH] moved ssh to host repo. added acl function and alias - still work working on them. in shell.env allowed module.lib to get loaded for non-interactive shells so that can access modules without all the other stuff of login shell. prepend /opt/bin and .local/bin so they take precedence. --- alias/acl | 1 + env/01-path | 7 ++-- function/acl | 51 ++++++++++++++++++++++++ function/ssh | 78 ------------------------------------- module.lib | 60 ++++++++++++++-------------- modules/utility/helpers.mod | 12 ++++++ shell.env | 7 ++-- ssh/config/readme.md | 1 - ssh/interactive | 3 -- ssh/session/readme.md | 1 - 10 files changed, 102 insertions(+), 119 deletions(-) create mode 100644 alias/acl create mode 100644 function/acl delete mode 100644 function/ssh delete mode 100644 ssh/config/readme.md delete mode 100644 ssh/interactive delete mode 100644 ssh/session/readme.md diff --git a/alias/acl b/alias/acl new file mode 100644 index 0000000..000ace8 --- /dev/null +++ b/alias/acl @@ -0,0 +1 @@ +alias aud="acluserdir" \ No newline at end of file diff --git a/env/01-path b/env/01-path index b060ab6..b318959 100644 --- a/env/01-path +++ b/env/01-path @@ -12,6 +12,7 @@ export PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin fi -path_append /opt/bin -path_append "$HOME/bin" -path_append "$HOME/.local/bin" +# with prependthese take prescendence over stuff ones in /usr and /bin +path_prepend /opt/bin +path_prepend "$HOME/bin" +path_prepend "$HOME/.local/bin" diff --git a/function/acl b/function/acl new file mode 100644 index 0000000..ea8e0a1 --- /dev/null +++ b/function/acl @@ -0,0 +1,51 @@ +#!/bin/bash +acluserdir() { + module_load confirm + local uid + local usesudo + local del + local spec + local cmd="-R -m " + local cmdd="-dR -m" + if [[ $1 == "-d" ]]; then + shift + echo deleting an acl entries for $1 + opts="-R -x" + optsd="-dR -x" + spec="u:$1 $2" + else + opts="-R -m " + optsd="-dR -m" + spec="u:$1:rwX $2" + fi + [[ ! $2 ]] && echo acluserdir: both user and direcotory must be passed && return 1 + uid=$(id -u $1 2>/dev/null) + [[ $uid -lt 1000 ]] && echo no such regular user $1 && return 2 + [[ ! -d $2 ]] && echo no such directory $2 && return 3 + if [[ ! -w $2 ]];then + echo $2 not writable by current user $USER + if [[ ! $(sudo -l -U $USER 2>/dev/null) ]]; then + echo user does not have sudo privilges, aborting + return 4 + else + confirm "do you want to elevate to root and continue?" || return 5 + usesudo="sudo" + fi + fi + + echo this are the commands that you will run + echo '******************' + echo $usesudo setfacl $opts $spec + echo $usesudo setfacl $optsd $spec + echo '******************' + confirm Double Check. Do you want to continue? || return 6 + $usesudo setfacl $opts $spec + $usesudo setfacl $optsd $spec + echo '*** new acl entries ***' + $usesudo getfacl -p --omit-header $2 | grep $1 +} + + + + + diff --git a/function/ssh b/function/ssh deleted file mode 100644 index 0b9e7fe..0000000 --- a/function/ssh +++ /dev/null @@ -1,78 +0,0 @@ -#!/bin/bash -# this will superceed the ssh binary in order to source all the config files -module_load file # loads find and build_file - -function ssh_config () { -local CDIRS -local CDIR -local DIRS -local DIR -local PDIRS - -declare OPTION -declare OPTARG -declare OPTIND -while getopts 'd:' OPTION; do - # echo $OPTION $OPTARG -case "$OPTION" in - d) - PDIRS=$OPTARG - # echo option d: $DIRS - ;; - *) - echo unknown option $OPTION - ;; -esac -done - -shift $(( OPTIND - 1 )) - -local OUTPUT=${*:-"$BASH_SHELL_BASE/ssh/config/_config"} -[[ $PDIRS ]] && DIRS=($PDIRS) || DIRS=(${BASH_SHELL_DIRS} "$HOME/$BASH_SHELL_USER") -# echo DIRS "${DIRS[@]}" -# echo $OUTPUT -CDIRS=() -j=0 -cnt=${#DIRS[@]} -for ((i=0;i $OUTPUT -build_file "/etc/ssh/ssh_config" $OUTPUT -# echo existing dirs ${CDIRS[@]} -for CDIR in "${CDIRS[@]}" -do - # FILES=$(find -n '*.cfg' -d 0 $CDIR) - for f in $(_find -n '*.cfg' -p 'archive off' -d 0 $CDIR) ; - do - # echo "Processing $f"; - [[ $f ]] && build_file "$f" $OUTPUT - done -done -build_file "$HOME/.ssh/config" $OUTPUT -} - -ssh () { - if [[ $1 = "-F" ]]; then - CONFIG=${2:-"$BASH_SHELL_BASE/ssh/config/_config"} - shift;shift - fi - CONFIG=${CONFIG:-"$BASH_SHELL_BASE/ssh/config/_config"} - [[ -f "$CONFIG" ]] || ssh_config "$CONFIG" - command ssh -F $CONFIG "$@" -} diff --git a/module.lib b/module.lib index 6892a51..ad9dfec 100644 --- a/module.lib +++ b/module.lib @@ -1,6 +1,8 @@ #!/bin/bash # echo loading module library -module_confirm () { + +module_confirm() { + local FILE local DIR local NAME @@ -24,7 +26,7 @@ return 1 } # if succesfull returns the path -function module_find () { +module_find() { [ ! $1 ] && echo "no module specified" && return 1 @@ -63,9 +65,10 @@ for MDIR in "${MDIRS[@]}" [ $? -eq 0 ] && echo $RES && return 0 done return 1 + } -module_load () { +module_load() { [ ! $1 ] && echo "no module specified" && return 1 # (return 0 2>/dev/null) && echo "module_load was sourced" || echo "module_log was executed" local FILE @@ -77,7 +80,7 @@ source $FILE return 0 } -module_loaded () { +module_loaded() { [ ! $1 ] && echo "no module specified" && return 1 local func local ret @@ -97,32 +100,29 @@ module_loaded () { return $ret } - # exported for login environment -declare -f -x module_load -declare -f -x module_find -declare -f -x module_confirm +# declare -f -x module_load +# declare -f -x module_find +# declare -f -x module_confirm +# uncomment for testing +# function _test_modules { +# RED='\033[0;31m' +# NC='\033[0m' # No Color +# echo module to test: $1 +# echo -------------------- +# echo -e "testing: ${RED}module_find${NC}" +# FILE=$(module_find $1) +# [ $? -ne 0 ] && echo no module $1 found && return 1 +# echo module $FILE found +# # . $FILE +# echo --------------- +# echo -e "testing: ${RED}module_load${NC}" +# module_load $1 +# [ $? -ne 0 ] && echo no module $1 found && return 1 +# echo loaded module $1 +# echo ---------------------- +# echo -e "testing: ${RED}module_loaded${NC}" +# module_loaded $1 +# } -function test_modules { -RED='\033[0;31m' -NC='\033[0m' # No Color -echo module to test: $1 -echo -------------------- -echo -e "testing: ${RED}module_find${NC}" -FILE=$(module_find $1) -[ $? -ne 0 ] && echo no module $1 found && return 1 -echo module $FILE found -# . $FILE -echo --------------- -echo -e "testing: ${RED}module_load${NC}" -module_load $1 -[ $? -ne 0 ] && echo no module $1 found && return 1 -echo loaded module $1 -echo ---------------------- -echo -e "testing: ${RED}module_loaded${NC}" -module_loaded $1 -} - -#comment this out if testing -unset -f test_modules diff --git a/modules/utility/helpers.mod b/modules/utility/helpers.mod index 0d71830..26854ed 100644 --- a/modules/utility/helpers.mod +++ b/modules/utility/helpers.mod @@ -11,3 +11,15 @@ is_array() { local variable_name=$1 [[ "$(declare -p $variable_name 2>/dev/null)" =~ "declare -a" ]] } + +filename() { + # passed entire path + echo $(basename "$1" | rev | cut -f 2- -d '.' | rev) +} + +adirname() { + # passed entire path + echo "$(cd "$(dirname "$1")" >/dev/null 2>&1 ; pwd -P )" +} + + diff --git a/shell.env b/shell.env index f9a7de2..fe48698 100644 --- a/shell.env +++ b/shell.env @@ -17,7 +17,7 @@ # 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 +# this does 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 @@ -32,10 +32,11 @@ 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 +# if uncommented next lines sets up implicit sourcing for non-interactive shells # echo ----NON_INTERACTIVE SHELL INFO----- # echo enabling bash shell repos for non-inactive shell -# export BASH_ENV=$BASH_SHELL_LOAD # use base repo +# 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 # 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 diff --git a/ssh/config/readme.md b/ssh/config/readme.md deleted file mode 100644 index d2a51fe..0000000 --- a/ssh/config/readme.md +++ /dev/null @@ -1 +0,0 @@ -*anything in /config will be used as configuration file with ssh function that calls ssh binary* diff --git a/ssh/interactive b/ssh/interactive deleted file mode 100644 index fc790db..0000000 --- a/ssh/interactive +++ /dev/null @@ -1,3 +0,0 @@ -if [[ $- == *i* ]]; then -echo ssh interactive session -fi diff --git a/ssh/session/readme.md b/ssh/session/readme.md deleted file mode 100644 index 223d2e1..0000000 --- a/ssh/session/readme.md +++ /dev/null @@ -1 +0,0 @@ -*anything in /session will be sourced if this is a remote ssh login session*