bugfix, esthetic cleanup, better comments, version bump

This commit is contained in:
Geoffray Levasseur-Brandin
2024-06-21 16:19:44 +02:00
parent 9e49e3e4d7
commit bef205ae84
18 changed files with 634 additions and 571 deletions

View File

@@ -1,3 +1,4 @@
#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# Protected by the BSD3 license. Please read bellow for details.
@@ -36,61 +37,60 @@
# ------------------------------------------------------------------------------
# Remove host from know_host (name and IP) for the active user
# ------------------------------------------------------------------------------
rmhost ()
rmhost()
{
if [[ "$#" -lt 1 ]]; then
disp E "Incorrect number of parameters."
disp E "Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]"
return 1
fi
while [[ $1 ]]; do
local hst=$1 && shift
isipv4 $hst > /dev/null
local v4=$?
isipv6 $hst > /dev/null
local v6=$?
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
local ip=$hst
unset hst
fi
unset v4 v6
if [[ ! $ip && $hst ]]; then
ip=$(host $hst | grep "has address" | awk '{print $NF}')
[[ ! $? ]] &&
disp E "Impossible to extract IP from hostname." &&
return 1
fi
if [[ $hst ]]; then
disp I "Removing host $hst from ssh known_host..."
ssh-keygen -R $hst > /dev/null
fi
if [[ $ip ]]; then
disp I "Removing IP $ip from ssh known_host..."
ssh-keygen -R $ip > /dev/null
fi
unset hst ip
local hst=$1 && shift
isipv4 $hst >/dev/null
local v4=$?
isipv6 $hst >/dev/null
local v6=$?
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
local ip=$hst
unset hst
fi
unset v4 v6
if [[ ! $ip && $hst ]]; then
ip=$(host $hst | grep "has address" | awk '{print $NF}')
[[ ! $? ]] &&
disp E "Impossible to extract IP from hostname." &&
return 1
fi
if [[ $hst ]]; then
disp I "Removing host $hst from ssh known_host..."
ssh-keygen -R $hst >/dev/null
fi
if [[ $ip ]]; then
disp I "Removing IP $ip from ssh known_host..."
ssh-keygen -R $ip >/dev/null
fi
unset hst ip
done
}
export -f rmhost
# ------------------------------------------------------------------------------
# Login root via SSH on the given machine
# ------------------------------------------------------------------------------
ssr ()
ssr()
{
for opt in $@ ; do
for opt in $@; do
case $opt in
"-h"|"--help")
echo "ssr: do a root user ssh login."
echo
echo "Usage: ssr <server [ssh options]>"
return 0
;;
"-h" | "--help")
echo "ssr: do a root user ssh login."
echo
echo "Usage: ssr <server [ssh options]>"
return 0
;;
esac
done
@@ -103,3 +103,6 @@ ssr ()
ssh -Y root@$srv $@
}
export -f ssr
# ------------------------------------------------------------------------------
# EOF