dracut-module-setup: get localhost alias by manual

'hostname -A' can not get the alias, meanwhile 'hostname -a' is deprecated.
So we should do it by ourselves.

The parsing is based on the format of /etc/hosts, i.e.
  IP_address canonical_hostname [aliases...]

Signed-off-by: Pingfan Liu <piliu@redhat.com>
Acked-by: Kairui Song <kasong@redhat.com>
This commit is contained in:
Pingfan Liu 2019-08-26 17:03:12 +08:00 committed by Kairui Song
parent d9c0c2f68f
commit f0b5493b2e

View File

@ -689,12 +689,31 @@ kdump_check_iscsi_targets () {
}
}
# hostname -a is deprecated, do it by ourself
get_alias() {
local ips
local entries
local alias_set
ips=$(hostname -I)
for ip in $ips
do
entries=$(grep $ip /etc/hosts | awk '{ $1=$2=""; print $0 }')
if [ $? -eq 0 ]; then
alias_set="$alias_set $entries"
fi
done
echo $alias_set
}
is_localhost() {
local hostnames=$(hostname -A)
local shortnames=$(hostname -A -s)
local aliasname=$(get_alias)
local nodename=$1
hostnames="$hostnames $shortnames"
hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do
if [ "$name" == "$nodename" ]; then