tenir compte de la configuration de ssh_config pour le choix du user de connexion
This commit is contained in:
parent
f2f6bada9e
commit
32d5a83fa6
69
ussh
69
ussh
|
@ -184,16 +184,60 @@ function remove_keys() {
|
||||||
eend
|
eend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __have_ssh_config() {
|
||||||
|
local host="$1" config="$2"
|
||||||
|
[ -f "$config" ] || return 1
|
||||||
|
awkrun host="$host" '
|
||||||
|
BEGIN {
|
||||||
|
in_host = 0
|
||||||
|
ec = 1
|
||||||
|
}
|
||||||
|
tolower($1) == "host" {
|
||||||
|
in_host = 0
|
||||||
|
for (i = 2; i <= NF; i++) {
|
||||||
|
if ($i == host) {
|
||||||
|
in_host = 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
in_host && tolower($1) == "user" {
|
||||||
|
ec = 0
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
exit ec
|
||||||
|
}
|
||||||
|
' -- "$config"
|
||||||
|
}
|
||||||
|
|
||||||
|
function __update_sshopts_l() {
|
||||||
|
# Ajouter l'option -l USSH_USER au tableau sshopts si aucune définition pour
|
||||||
|
# l'hôte $1 n'existe dans l'un des fichiers de configuration de ssh
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
__have_ssh_config "$1" ~/.ssh/config && return
|
||||||
|
__have_ssh_config "$1" /etc/ssh/ssh_config && return
|
||||||
|
fi
|
||||||
|
# Rajouter l'option au début pour que l'utilisateur puisse la surcharger
|
||||||
|
sshopts=(${USSH_USER:+-l "$USSH_USER"} "${sshopts[@]}")
|
||||||
|
}
|
||||||
|
|
||||||
function show_vars() {
|
function show_vars() {
|
||||||
[ "${#hosts[*]}" -gt 1 ] && exec=
|
[ "${#hosts[*]}" -gt 1 ] && exec=
|
||||||
|
|
||||||
|
local -a sshopts
|
||||||
|
array_copy sshopts SSHOPTS
|
||||||
|
__update_sshopts_l "${hosts[0]}"
|
||||||
|
|
||||||
set_var_cmd ssh "$SSH"
|
set_var_cmd ssh "$SSH"
|
||||||
set_var_cmd exec "$exec"
|
set_var_cmd exec "$exec"
|
||||||
set_array_cmd options SSHOPTS
|
set_array_cmd options sshopts
|
||||||
set_array_cmd hosts
|
set_array_cmd hosts
|
||||||
set_array_cmd args @ "$@"
|
set_array_cmd args @ "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_ssh() {
|
function do_ssh() {
|
||||||
|
local -a sshopts
|
||||||
local onehost r
|
local onehost r
|
||||||
if [ "${#hosts[*]}" -gt 1 ]; then
|
if [ "${#hosts[*]}" -gt 1 ]; then
|
||||||
onehost=
|
onehost=
|
||||||
|
@ -203,15 +247,20 @@ function do_ssh() {
|
||||||
fi
|
fi
|
||||||
for host in "${hosts[@]}"; do
|
for host in "${hosts[@]}"; do
|
||||||
[ -z "$onehost" ] && etitle "$host"
|
[ -z "$onehost" ] && etitle "$host"
|
||||||
${exec:+exec} "$SSH" "${SSHOPTS[@]}" "$host" "$@" || r=$?
|
|
||||||
|
array_copy sshopts SSHOPTS
|
||||||
|
__update_sshopts_l "$host"
|
||||||
|
${exec:+exec} "$SSH" "${sshopts[@]}" "$host" "$@" || r=$?
|
||||||
|
|
||||||
[ -z "$onehost" ] && eend
|
[ -z "$onehost" ] && eend
|
||||||
done
|
done
|
||||||
return "${r:-0}"
|
return "${r:-0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __update_SSHOPTS() { SSHOPTS=("${SSHOPTS[@]}" "$@"); }
|
||||||
|
|
||||||
|
# charger USSH_DOMAIN et USSH_USER
|
||||||
set_defaults nutools
|
set_defaults nutools
|
||||||
SSHOPTS=(${USSH_USER:+-l "$USSH_USER"}) # options de ssh
|
|
||||||
function sshopt() { SSHOPTS=("${SSHOPTS[@]}" "$@"); }
|
|
||||||
|
|
||||||
DOMAIN="$USSH_DOMAIN"
|
DOMAIN="$USSH_DOMAIN"
|
||||||
SSH=
|
SSH=
|
||||||
|
@ -221,12 +270,12 @@ exec=1
|
||||||
parse=
|
parse=
|
||||||
parse_opts "${PRETTYOPTS[@]}" \
|
parse_opts "${PRETTYOPTS[@]}" \
|
||||||
--help '$exit_with display_help' \
|
--help '$exit_with display_help' \
|
||||||
-1,-2,-4,-6,-A,-a,-C,-f,-g,-K,-k,-M,-N,-n,-q,-s,-T,-t,-V,-v,-X,-x,-Y,-y '$sshopt "$option_"' \
|
-1,-2,-4,-6,-A,-a,-C,-f,-g,-K,-k,-M,-N,-n,-q,-s,-T,-t,-V,-v,-X,-x,-Y,-y '$__update_SSHOPTS "$option_"' \
|
||||||
-b:,-c:,-D:,-e:,-F:,-I:,-i:,-L:,-l:,-m:,-O:,-o:,-p:,-R:,-S:,-W:,-w: '$sshopt "$option_" "$value_"' \
|
-b:,-c:,-D:,-e:,-F:,-I:,-i:,-L:,-l:,-m:,-O:,-o:,-p:,-R:,-S:,-W:,-w: '$__update_SSHOPTS "$option_" "$value_"' \
|
||||||
--quiet '$sshopt -q' \
|
--quiet '$__update_SSHOPTS -q' \
|
||||||
--tty '$sshopt -t' \
|
--tty '$__update_SSHOPTS -t' \
|
||||||
--login: '$sshopt -l "$value_"' \
|
--login: '$__update_SSHOPTS -l "$value_"' \
|
||||||
--port: '$sshopt -p "$value_"' \
|
--port: '$__update_SSHOPTS -p "$value_"' \
|
||||||
-d:,--domain: DOMAIN= \
|
-d:,--domain: DOMAIN= \
|
||||||
-z:,--ssh: SSH= \
|
-z:,--ssh: SSH= \
|
||||||
-r,--remove '$remove=1; parse=' \
|
-r,--remove '$remove=1; parse=' \
|
||||||
|
|
Loading…
Reference in New Issue