Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
M #: Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
dann1 committed May 25, 2023
1 parent 3a16490 commit 5f01d1c
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/etc/one-context.d/net-15-hostname
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,10 @@ if [ -n "${name}" ]; then
# split host and domain names
hostname=${name%%.*}
domain=${name#*.}
if [ "x${domain}" = "x${hostname}" ]; then
domain=''
fi

if [ -n "${domain}" ]; then
set_domainname "${domain}"
fi
[ "$domain" = "$hostname" ] && domain=''
[ -n "${domain}" ] && set_domainname "${domain}"

# FreeBSD
if [ "${_kernel}" = 'FreeBSD' ]; then
set_hostname "${name}"
else
Expand All @@ -169,20 +164,17 @@ if [ -n "${name}" ]; then
if [ -n "${DNS_HOSTNAME}" ]; then
host_ip=$first_ip
else
name_ip=$(get_dns_name "${name}")

# If selected hostname resolves on first IP,
# use first IP for local hostname in /etc/hosts.
# Otherwise use loopback IP.
name_ip=$(get_dns_name "${name}")
if [ "x${first_ip}" = "x${name_ip}" ]; then
if [ "$first_ip" = "$name_ip" ]; then
host_ip=$first_ip
elif [ -f /etc/debian_version ]; then
host_ip='127.0.1.1'
else
host_ip='127.0.0.1'
fi
fi

if [ -n "${host_ip}" ]; then
update_hosts "${host_ip}" "${name}" "${hostname}"
fi
[ -n "${host_ip}" ] && update_hosts "${host_ip}" "${name}" "${hostname}"
fi

0 comments on commit 5f01d1c

Please sign in to comment.