ajout de USSH_USER

ajout de l'option -c
This commit is contained in:
Jephté Clain 2014-02-25 07:45:43 +04:00
parent ad0d651416
commit b3ff42ea8e
2 changed files with 54 additions and 40 deletions

View File

@ -5,5 +5,7 @@
# auto (par défaut), system-or-local, default, manual ou vanilla # auto (par défaut), system-or-local, default, manual ou vanilla
#SHELL_TYPE=auto #SHELL_TYPE=auto
# Utilisateur par défaut pour la commande ussh
#USSH_USER=root
# Domaine par défaut pour la commande ussh # Domaine par défaut pour la commande ussh
#USSH_DOMAIN= #USSH_DOMAIN=

86
ussh
View File

@ -106,29 +106,7 @@ function fix_hosts() {
array_map hosts __dot_is_localhost array_map hosts __dot_is_localhost
} }
action=ssh function ussh() {
quiet=
tty=
login=
options=()
domain="$USSH_DOMAIN"
ssh=
parse_opts + "${PRETTYOPTS[@]}" \
--help '$exit_with display_help' \
-q,--quiet quiet=1 \
-t,--tty tty=1 \
-l:,--login: login= \
-o options \
-d:,--domain: domain= \
-S:,--ssh ssh= \
-R,--remove action=remove \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
if [ "$action" == "ssh" ]; then
[ -n "$1" ] || die "Vous devez spécifier l'hôte sur lequel faire la connexion"
hosts=("$1"); shift
fix_hosts
args=(${quiet:+-q} ${tty:+-t} ${login:+-l "$login"}) args=(${quiet:+-q} ${tty:+-t} ${login:+-l "$login"})
for option in "${options[@]}"; do for option in "${options[@]}"; do
args=("${args[@]}" -o "$option") args=("${args[@]}" -o "$option")
@ -144,44 +122,78 @@ if [ "$action" == "ssh" ]; then
"$ssh" "${user:+$user@}$host" "${args[@]}" "$ssh" "${user:+$user@}$host" "${args[@]}"
[ -n "$showtitle" ] && eend [ -n "$showtitle" ] && eend
done done
}
elif [ "$action" == "remove" ]; then function remove_key() {
urequire ipcalc
function remove() {
estep "$1" estep "$1"
ssh-keygen -R "$1" >&/dev/null ssh-keygen -R "$1" >&/dev/null
} }
function remove_keys() {
[ -n "$1" ] || die "Vous devez spécifier les hôtes à supprimer de ~/.ssh/known_hosts" local -a __hosts; array_copy __hosts hosts
hosts=("$@") local -a allhosts hosts ips; local host user ip
fix_hosts array_copy allhosts __hosts
etitle "Suppression des entrées dans ~/.ssh/known_hosts" etitle "Suppression des entrées dans ~/.ssh/known_hosts"
allhosts=("${hosts[@]}")
for host in "${allhosts[@]}"; do for host in "${allhosts[@]}"; do
splituserhost "$host" user host splituserhost "$host" user host
[[ "$host" == *.* ]] || host="$host${domain:+.$domain}" [[ "$host" == *.* ]] || host="$host${domain:+.$domain}"
if ipcalc_checkip "$host" >/dev/null; then if ipcalc_checkip "$host" >/dev/null; then
ip="$host" ip="$host"
remove "$ip" remove_key "$ip"
resolv_hosts hosts "$ip" resolv_hosts hosts "$ip"
for host in "${hosts[@]}"; do for host in "${hosts[@]}"; do
remove "$host" remove_key "$host"
hostname="${host%%.*}" hostname="${host%%.*}"
[ "$hostname" != "$host" ] && remove "$hostname" [ "$hostname" != "$host" ] && remove_key "$hostname"
done done
else else
remove "$host" remove_key "$host"
hostname="${host%%.*}" hostname="${host%%.*}"
[ "$hostname" != "$host" ] && remove "$hostname" [ "$hostname" != "$host" ] && remove_key "$hostname"
resolv_ips ips "$host" resolv_ips ips "$host"
for ip in "${ips[@]}"; do for ip in "${ips[@]}"; do
remove "$ip" remove_key "$ip"
done done
fi fi
done done
eend eend
}
action=ssh
quiet=
tty=
login="$USSH_USER"
options=()
domain="$USSH_DOMAIN"
ssh=
connect_after_remove=
parse_opts + "${PRETTYOPTS[@]}" \
--help '$exit_with display_help' \
-q,--quiet quiet=1 \
-t,--tty tty=1 \
-l:,--login: login= \
-o options \
-d:,--domain: domain= \
-S:,--ssh ssh= \
-R,--remove action=remove \
-c,--connect connect_after_remove=1 \
@ args -- "$@" && set -- "${args[@]}" || die "$args"
if [ "$action" == "ssh" ]; then
[ -n "$1" ] || die "Vous devez spécifier l'hôte sur lequel faire la connexion"
hosts=("$1"); shift
fix_hosts
ussh "$@"
elif [ "$action" == "remove" ]; then
urequire ipcalc
[ -n "$1" ] || die "Vous devez spécifier les hôtes à supprimer de ~/.ssh/known_hosts"
hosts=("$@")
fix_hosts
remove_keys
[ -n "$connect_after_remove" ] && ussh
fi fi