77 lines
2.2 KiB
Plaintext
77 lines
2.2 KiB
Plaintext
|
#!/bin/bash
|
||
|
# this will superceed the ssh binary in order to source all the config files
|
||
|
module_load file # loads find and build_file
|
||
|
|
||
|
[[ ! $SSH_CONFIG ]] && export SSH_CONFIG="$BASH_SHELL_ANY_NETWORK/ssh/_config"
|
||
|
|
||
|
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))
|
||
|
|
||
|
[[ $PDIRS ]] && DIRS=($PDIRS) || DIRS=(${BASH_SHELL_DIRS} "$HOME/$BASH_SHELL_USER")
|
||
|
# echo DIRS "${DIRS[@]}"
|
||
|
# echo $SSH_CONFIG
|
||
|
CDIRS=()
|
||
|
j=0
|
||
|
cnt=${#DIRS[@]}
|
||
|
for ((i = 0; i < cnt; i++)); do
|
||
|
# echo $i of $cnt
|
||
|
# looks in ssh/config subdirectory of each DIRS is not passed
|
||
|
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 #
|
||
|
##############################################################"
|
||
|
|
||
|
module_load debug
|
||
|
module_load file
|
||
|
|
||
|
debug ssh config file at: $SSH_CONFIG
|
||
|
mkdir -p "$(dirname "$SSH_CONFIG")"
|
||
|
echo -e "$HEADER" >$SSH_CONFIG
|
||
|
# build_file appends the given file to output file cleanly with checks
|
||
|
# append any system config
|
||
|
build_file "/etc/ssh/ssh_config" $SSH_CONFIG
|
||
|
# echo existing dirs ${CDIRS[@]}
|
||
|
# will append any .cfg file found in ssh/config subdir of any BASH_SHELL_DIRS, including home shell
|
||
|
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" $SSH_CONFIG
|
||
|
done
|
||
|
done
|
||
|
# append any tradtional home config
|
||
|
build_file "$HOME/.ssh/config" $SSH_CONFIG
|
||
|
}
|