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.master
parent
de43f28f78
commit
3656f1420e
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
78
function/ssh
78
function/ssh
|
@ -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<cnt;i++)); do
|
||||
# echo $i of $cnt
|
||||
DIR="${DIRS[i]}$([[ ! $PDIRS ]] && echo /ssh/config)"
|
||||
# echo ----- trying $DIR
|
||||
[ -d $DIR ] && CDIRS[j]=$DIR;j+=1 || echo no directory $DIR
|
||||
done
|
||||
# CDIRS=("${CDIRS[@]}")
|
||||
# echo ${CDIRS[@]}
|
||||
|
||||
local HEADER="##############################################################
|
||||
# THIS FILE IS GENERATED BY function ssh_config. Do not edit #
|
||||
# It is created by combination of ssh configuration files #
|
||||
# which are listed in a comment line before each #
|
||||
# It is used by the ssh function which then calls ssh binary #
|
||||
##############################################################"
|
||||
|
||||
debug ssh config file at: $OUTPUT
|
||||
mkdir -p "$(dirname "$OUTPUT")"
|
||||
echo -e "$HEADER" > $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 "$@"
|
||||
}
|
60
module.lib
60
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
|
||||
|
|
|
@ -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 )"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
*anything in /config will be used as configuration file with ssh function that calls ssh binary*
|
|
@ -1,3 +0,0 @@
|
|||
if [[ $- == *i* ]]; then
|
||||
echo ssh interactive session
|
||||
fi
|
|
@ -1 +0,0 @@
|
|||
*anything in /session will be sourced if this is a remote ssh login session*
|
Loading…
Reference in New Issue