added debug module with debug function - a first cut
load.sh now loads debug module or a noop file library, file.lib - refactored _find function, added alias superceed * added h option to include .hidden files * - added build_file function to append file to another refactored comment and uncomment functions added find_mountpoint function to filesystem module added ssh_config builder function and ssh override to use it. added github module with binary release fetch function (needs work)master
parent
1304c3afe7
commit
22b3c0cc36
|
@ -0,0 +1,4 @@
|
||||||
|
# any binary superceed by a function with
|
||||||
|
# initial binary available as s<name> as in super
|
||||||
|
alias find="_find"
|
||||||
|
alias sfind="command find"
|
|
@ -2,5 +2,4 @@
|
||||||
# export EDITOR=atom
|
# export EDITOR=atom
|
||||||
# export ELECTRON_TRASH=gio
|
# export ELECTRON_TRASH=gio
|
||||||
export EDITOR=nano
|
export EDITOR=nano
|
||||||
|
|
||||||
export BROWSER=google-chrome
|
export BROWSER=google-chrome
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
function comment_line() {
|
function comment() {
|
||||||
local regex="${1:?}"
|
[[ $# -lt 2 ]] && echo must supply pattern and file && return 1
|
||||||
local file="${2:?}"
|
sed -i '/'$1'/s/^#*/#/g' "$2"
|
||||||
local comment_mark="${3:-#}"
|
|
||||||
sed -ri "s:^([ ]*)($regex):\\1$comment_mark\\2:" "$file"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function uncomment_line() {
|
function uncomment() {
|
||||||
local regex="${1:?}"
|
[[ $# -lt 2 ]] && echo must supply pattern and file && return 1
|
||||||
local file="${2:?}"
|
sed -i '/'$1'/s/^#*//g' "$2"
|
||||||
local comment_mark="${3:-#}"
|
|
||||||
sed -ri "s:^([ ]*)[$comment_mark]+[ ]?([ ]*$regex):\\1\\2:" "$file"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
#!/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 "$@"
|
||||||
|
}
|
15
load.sh
15
load.sh
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# [[ ! $- == *i* ]] && exec >> ~/logs/load.log && exec 2>&1
|
# [[ ! $- == *i* ]] && exec >> ~/logs/load.log && exec 2>&1
|
||||||
|
# export BASH_DEBUG=true
|
||||||
function nilog () {
|
function nilog () {
|
||||||
[[ ! $- == *i* ]] && echo -e "-----\n $USER $*" &>> ~/logs/load.log
|
[[ ! $- == *i* ]] && echo -e "-----\n $USER $*" &>> ~/logs/load.log
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,15 @@ DIR=${1:-$(dirname ${BASH_SOURCE[0]})}
|
||||||
module_load file
|
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, aboarting load && return 1
|
||||||
|
|
||||||
|
module_load debug
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
echo "unable to load a 'debug' module using a noop for debug function"
|
||||||
|
# noop
|
||||||
|
function debug () {
|
||||||
|
:
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
([[ $BASH_ENV ]] && [[ ! $- == *i* ]] && [[ $BASH_USE_ALIAS ]]) && shopt -s expand_aliases
|
([[ $BASH_ENV ]] && [[ ! $- == *i* ]] && [[ $BASH_USE_ALIAS ]]) && shopt -s expand_aliases
|
||||||
|
|
||||||
function shell_process_directory () {
|
function shell_process_directory () {
|
||||||
|
@ -92,12 +101,12 @@ unset BASH_SHELL_BASE_LOADED
|
||||||
unset BASH_SHELL_LOADED
|
unset BASH_SHELL_LOADED
|
||||||
|
|
||||||
# echo bash shell dirs: $BASH_SHELL_DIRS
|
# echo bash shell dirs: $BASH_SHELL_DIRS
|
||||||
DIRS=${1:-$BASH_SHELL_DIRS}
|
dirs=${1:-$BASH_SHELL_DIRS}
|
||||||
|
|
||||||
BASH_SHELL_BASE_SUBDIRS=$(cat "$BASH_SHELL_BASE/.bash-shell-include")
|
BASH_SHELL_BASE_SUBDIRS=$(cat "$BASH_SHELL_BASE/.bash-shell-include")
|
||||||
# echo subdir includes: $BASH_SHELL_BASE_SUBDIRS
|
# echo subdir includes: $BASH_SHELL_BASE_SUBDIRS
|
||||||
|
|
||||||
for dir in $DIRS; do
|
for dir in $dirs; do
|
||||||
# echo $dir
|
# echo $dir
|
||||||
shell_process_directory $dir
|
shell_process_directory $dir
|
||||||
[[ $dir == "$BASH_SHELL_BASE" ]] && BASH_SHELL_BASE_LOADED=true
|
[[ $dir == "$BASH_SHELL_BASE" ]] && BASH_SHELL_BASE_LOADED=true
|
||||||
|
|
|
@ -7,7 +7,7 @@ local NAME
|
||||||
DIR=$1
|
DIR=$1
|
||||||
NAME=$2
|
NAME=$2
|
||||||
# echo finding $NAME in $DIR
|
# echo finding $NAME in $DIR
|
||||||
FILE="$(find ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh)"
|
FILE="$(command find ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh)"
|
||||||
# echo files found $FILE
|
# echo files found $FILE
|
||||||
COUNT=0
|
COUNT=0
|
||||||
if [ "$FILE" ]; then
|
if [ "$FILE" ]; then
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# if you have run into github api anonymous access limits which happens during debugging/dev then add user and token here or sourced from a separate file
|
||||||
|
# set to location for tokens in file
|
||||||
|
source ~/githubapitoken
|
||||||
|
|
||||||
|
if [ "$GITHUB_TOKEN" != "" ]; then
|
||||||
|
echo using access token with script
|
||||||
|
echo $GITHUB_USER $GITHUB_TOKEN
|
||||||
|
fi
|
||||||
|
|
||||||
|
DIR=$(dirname "$(readlink -f "$0")") || exit
|
||||||
|
|
||||||
|
ORG=$1
|
||||||
|
REPO=$2
|
||||||
|
TYPE=$3
|
||||||
|
NAME=$4
|
||||||
|
EXCLUDE=$5
|
||||||
|
|
||||||
|
URL=$(curl -s https://api.github.com/repos/$ORG/$REPO/releases/latest \
|
||||||
|
# | grep 'browser_download_url.*'$TYPE''
|
||||||
|
# | sed -n -e 's/^.*: //p' \
|
||||||
|
# | sed 's/"//g'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
echo "Pulling $URL"
|
||||||
|
TODO put back tokens here.
|
||||||
|
# wget $URL -O $NAME.$TYPE
|
||||||
|
# chmod +x $DIR/$NAME.$TYPE
|
||||||
|
# ln -s $DIR/$NAME.$TYPE /opt/bin/$NAME
|
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# TODO allow debug to have managment flags and levels
|
||||||
|
function debug () {
|
||||||
|
[[ $BASH_DEBUG ]] && echo -e "#### DEBUG ####\n $@ \n#####" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# alias debug_on="sudo -i uncomment BASH_DEBUG /etc/bash.bashrc"
|
||||||
|
# alias debug_off="sudo -i comment BASH_DEBUG /etc/bash.bashrc"
|
|
@ -1,5 +1,16 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# export BASH_DEBUG=true
|
||||||
|
|
||||||
|
build_file () {
|
||||||
|
[[ -f "$2" ]] || (echo "output file $2 does not exist";return 1)
|
||||||
|
if [[ -f "$1" ]]; then
|
||||||
|
echo -e "\n####### ADDED $1 ########" >> $2
|
||||||
|
cat "$1" | sed '/^\s*#/d' | sed '/^$/{:a;N;s/\n$//;ta}' >> $2
|
||||||
|
else debug "no such file $1 to append"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function lines_2_str () {
|
function lines_2_str () {
|
||||||
[[ ! -f "$1" ]] && return 1
|
[[ ! -f "$1" ]] && return 1
|
||||||
local str=''
|
local str=''
|
||||||
|
@ -19,9 +30,9 @@ done < $1
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function super_find () {
|
# find, superceeds find use `command find` to get the super
|
||||||
# echo super_find $@ >&2
|
function _find () {
|
||||||
# USAGE
|
# USAGE
|
||||||
# all option arguments that contain globs/wildcards must be quoted to avoid expansion
|
# all option arguments that contain globs/wildcards must be quoted to avoid expansion
|
||||||
# f sets path and file excludes from a supplied file path
|
# f sets path and file excludes from a supplied file path
|
||||||
# all lines ending in / will be treated as directory names to ignore, otherwise files
|
# all lines ending in / will be treated as directory names to ignore, otherwise files
|
||||||
|
@ -32,17 +43,17 @@ function super_find () {
|
||||||
# if no directory is given it will attempt to source the present working directory
|
# if no directory is given it will attempt to source the present working directory
|
||||||
# example:
|
# example:
|
||||||
# source_dir -p "archive" -x '"*.off" "*.md"' -d 0 # $DIR/$SUBDIR
|
# source_dir -p "archive" -x '"*.off" "*.md"' -d 0 # $DIR/$SUBDIR
|
||||||
declare OPTION
|
|
||||||
declare OPTARG
|
|
||||||
declare OPTIND
|
|
||||||
local EXCLUDE_FILE
|
local EXCLUDE_FILE
|
||||||
local PATHS
|
local PATHS
|
||||||
local NAMES
|
local NAMES
|
||||||
local ENAMES
|
local ENAMES
|
||||||
local DEPTH=1
|
local DEPTH=1
|
||||||
local VERBOSE=0
|
local HIDDEN
|
||||||
|
|
||||||
while getopts 'p:d:e:n:f:' OPTION; do
|
declare OPTION
|
||||||
|
declare OPTARG
|
||||||
|
declare OPTIND
|
||||||
|
while getopts 'p:d:e:n:f:h' OPTION; do
|
||||||
case "$OPTION" in
|
case "$OPTION" in
|
||||||
f)
|
f)
|
||||||
EXCLUDE_FILE=$OPTARG
|
EXCLUDE_FILE=$OPTARG
|
||||||
|
@ -66,6 +77,10 @@ case "$OPTION" in
|
||||||
DEPTH=$OPTARG
|
DEPTH=$OPTARG
|
||||||
# echo "SOURCING TO DEPTH (0=any)" "$DEPTH"
|
# echo "SOURCING TO DEPTH (0=any)" "$DEPTH"
|
||||||
;;
|
;;
|
||||||
|
h)
|
||||||
|
HIDDEN=true
|
||||||
|
# echo "SOURCING TO DEPTH (0=any)" "$DEPTH"
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo unknown option $OPTION
|
echo unknown option $OPTION
|
||||||
;;
|
;;
|
||||||
|
@ -78,8 +93,8 @@ local DIR
|
||||||
DIR="$*"
|
DIR="$*"
|
||||||
if [ ! "$DIR" ]; then
|
if [ ! "$DIR" ]; then
|
||||||
if [ -v PS1 ]; then
|
if [ -v PS1 ]; then
|
||||||
echo no directory to source provided
|
echo no directory provided to search
|
||||||
echo sourcing present working directory $(pwd)
|
echo searching present working directory $(pwd)
|
||||||
read -p "Do you want to continue? " -n 1 -r
|
read -p "Do you want to continue? " -n 1 -r
|
||||||
[[ $REPLY =~ ^[Yy]$ ]] && DIR=$(pwd) || return 1
|
[[ $REPLY =~ ^[Yy]$ ]] && DIR=$(pwd) || return 1
|
||||||
else
|
else
|
||||||
|
@ -92,10 +107,11 @@ fi
|
||||||
# echo dir $DIR
|
# echo dir $DIR
|
||||||
|
|
||||||
local FIND
|
local FIND
|
||||||
FIND="find $DIR"
|
FIND="command find $DIR"
|
||||||
FIND+=$([ ! $DEPTH == 0 ] && echo " -maxdepth $DEPTH ")
|
FIND+=$([ ! $DEPTH == 0 ] && echo " -maxdepth $DEPTH ")
|
||||||
# ignore all .name and .path by default
|
FIND+=" -type f "
|
||||||
FIND+=" -type f ! -path \"*/.*/*\" ! -name \".*\" "
|
# include HIDDEN files and directories IS FALSE BY DEFULT
|
||||||
|
[[ ! $HIDDEN ]] && FIND+="! -path \"*/.*/*\" ! -name \".*\" "
|
||||||
|
|
||||||
local name
|
local name
|
||||||
local path
|
local path
|
||||||
|
@ -135,21 +151,23 @@ fi
|
||||||
|
|
||||||
# echo
|
# echo
|
||||||
# echo find dir: $DIR >&2
|
# echo find dir: $DIR >&2
|
||||||
# echo find command: $FIND >&2
|
debug "find command: $FIND"
|
||||||
|
|
||||||
local FILES
|
local FILES
|
||||||
FILES=$(eval $FIND | sort)
|
FILES=$(eval $FIND | sort)
|
||||||
echo $FILES
|
[[ $FILES ]] && echo $FILES
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
source_dir () {
|
source_dir () {
|
||||||
# echo passed: $*
|
# echo passed: $*
|
||||||
|
debug function: source_dir
|
||||||
local FILES
|
local FILES
|
||||||
FILES=$(super_find "$@")
|
FILES=$(_find "$@") # find function
|
||||||
|
# echo $FILES >&2
|
||||||
[[ $? -ne 0 ]] && return 1
|
[[ $? -ne 0 ]] && return 1
|
||||||
for f in $FILES; do
|
for f in $FILES; do
|
||||||
# echo sourcing: $f
|
# echo sourcing: $f >&2
|
||||||
source "$f"
|
source "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,14 @@ mounted () {
|
||||||
[[ ! $1 ]] && echo no mount point to test && return 2
|
[[ ! $1 ]] && echo no mount point to test && return 2
|
||||||
mountpoint "$1" &> /dev/null && echo yes || return 1
|
mountpoint "$1" &> /dev/null && echo yes || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# peals back sub-directories until if finds a mountpoing
|
||||||
|
find_mountpoint () {
|
||||||
|
local dir=$1
|
||||||
|
if [[ ! $dir = "/" ]]; then
|
||||||
|
# echo trying $dir for mountpoint
|
||||||
|
[[ $(mounted $dir) ]] && echo $dir || find_mountpoint "$(dirname $1)"
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
@ -11,4 +11,7 @@ if ([ -n "$SSH_CONNECTION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]); then
|
||||||
export SSH_SESSION=true
|
export SSH_SESSION=true
|
||||||
source /etc/profile
|
source /etc/profile
|
||||||
fi
|
fi
|
||||||
|
# global debug on or off via debug_on debug_off aliases
|
||||||
|
# can add this export to any file
|
||||||
|
#export BASH_DEBUG=true
|
||||||
source $BASH_SHELL_LOAD
|
source $BASH_SHELL_LOAD
|
||||||
|
|
|
@ -2,6 +2,6 @@
|
||||||
# echo "$USER .bashrc"
|
# echo "$USER .bashrc"
|
||||||
# processing user's shell repo if base was loaded
|
# processing user's shell repo if base was loaded
|
||||||
[[ $BASH_SHELL_BASE_LOADED = true ]] && \
|
[[ $BASH_SHELL_BASE_LOADED = true ]] && \
|
||||||
BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} && \
|
export BASH_SHELL_USER=${BASH_SHELL_USER:-"bash/shell"} && \
|
||||||
[[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\
|
[[ -d $HOME/$BASH_SHELL_USER ]] && shell_process_directory "$HOME/$BASH_SHELL_USER" ||\
|
||||||
echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template
|
echo no user shell directory $HOME/$BASH_SHELL_USER to process, create one or clone a template
|
||||||
|
|
|
@ -55,6 +55,7 @@ export BASH_USE_ALIAS=true # will source aliases for non-interactive
|
||||||
# identify a network name that this host resides on
|
# identify a network name that this host resides on
|
||||||
# make a directory of the same name
|
# make a directory of the same name
|
||||||
# if unset then only /all will be sourced
|
# if unset then only /all will be sourced
|
||||||
|
# TODO just read all directories in BASH_SHELL_NETWORK.
|
||||||
export NETWORK_DOMAINS=(238.kebler.net 645.kebler.net 3115.kebler.net)
|
export NETWORK_DOMAINS=(238.kebler.net 645.kebler.net 3115.kebler.net)
|
||||||
# network domain folder entry will be made for each domain set, first is home domain, others via vpn
|
# network domain folder entry will be made for each domain set, first is home domain, others via vpn
|
||||||
if [[ $NETWORK_DOMAINS ]]; then
|
if [[ $NETWORK_DOMAINS ]]; then
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
*anything in /config will be used as configuration file with ssh function that calls ssh binary*
|
Reference in New Issue