parent
ad0d651416
commit
b3ff42ea8e
|
@ -5,5 +5,7 @@
|
|||
# auto (par défaut), system-or-local, default, manual ou vanilla
|
||||
#SHELL_TYPE=auto
|
||||
|
||||
# Utilisateur par défaut pour la commande ussh
|
||||
#USSH_USER=root
|
||||
# Domaine par défaut pour la commande ussh
|
||||
#USSH_DOMAIN=
|
||||
|
|
92
ussh
92
ussh
|
@ -106,29 +106,7 @@ function fix_hosts() {
|
|||
array_map hosts __dot_is_localhost
|
||||
}
|
||||
|
||||
action=ssh
|
||||
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
|
||||
|
||||
function ussh() {
|
||||
args=(${quiet:+-q} ${tty:+-t} ${login:+-l "$login"})
|
||||
for option in "${options[@]}"; do
|
||||
args=("${args[@]}" -o "$option")
|
||||
|
@ -144,44 +122,78 @@ if [ "$action" == "ssh" ]; then
|
|||
"$ssh" "${user:+$user@}$host" "${args[@]}"
|
||||
[ -n "$showtitle" ] && eend
|
||||
done
|
||||
}
|
||||
|
||||
elif [ "$action" == "remove" ]; then
|
||||
urequire ipcalc
|
||||
function remove() {
|
||||
estep "$1"
|
||||
ssh-keygen -R "$1" >&/dev/null
|
||||
}
|
||||
|
||||
[ -n "$1" ] || die "Vous devez spécifier les hôtes à supprimer de ~/.ssh/known_hosts"
|
||||
hosts=("$@")
|
||||
fix_hosts
|
||||
function remove_key() {
|
||||
estep "$1"
|
||||
ssh-keygen -R "$1" >&/dev/null
|
||||
}
|
||||
function remove_keys() {
|
||||
local -a __hosts; array_copy __hosts hosts
|
||||
local -a allhosts hosts ips; local host user ip
|
||||
array_copy allhosts __hosts
|
||||
|
||||
etitle "Suppression des entrées dans ~/.ssh/known_hosts"
|
||||
allhosts=("${hosts[@]}")
|
||||
for host in "${allhosts[@]}"; do
|
||||
splituserhost "$host" user host
|
||||
[[ "$host" == *.* ]] || host="$host${domain:+.$domain}"
|
||||
|
||||
if ipcalc_checkip "$host" >/dev/null; then
|
||||
ip="$host"
|
||||
remove "$ip"
|
||||
remove_key "$ip"
|
||||
|
||||
resolv_hosts hosts "$ip"
|
||||
for host in "${hosts[@]}"; do
|
||||
remove "$host"
|
||||
remove_key "$host"
|
||||
hostname="${host%%.*}"
|
||||
[ "$hostname" != "$host" ] && remove "$hostname"
|
||||
[ "$hostname" != "$host" ] && remove_key "$hostname"
|
||||
done
|
||||
else
|
||||
remove "$host"
|
||||
remove_key "$host"
|
||||
hostname="${host%%.*}"
|
||||
[ "$hostname" != "$host" ] && remove "$hostname"
|
||||
[ "$hostname" != "$host" ] && remove_key "$hostname"
|
||||
|
||||
resolv_ips ips "$host"
|
||||
for ip in "${ips[@]}"; do
|
||||
remove "$ip"
|
||||
remove_key "$ip"
|
||||
done
|
||||
fi
|
||||
done
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue