From bee36aec4290daeb46ffd5e8cdc070299554a2a7 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 21 Jun 2023 18:00:09 +0200 Subject: [dhcpc-busybox] More DHCP hostname shenanigans --- .../data/opt/openslx/scripts/udhcpc-openslx | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'core/modules/dhcpc-busybox') diff --git a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx index 99e8b0dd..0e64643e 100755 --- a/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx +++ b/core/modules/dhcpc-busybox/data/opt/openslx/scripts/udhcpc-openslx @@ -202,25 +202,26 @@ case "$1" in echo "SLX_NET_WINS='$wins'" >> /opt/openslx/config fi - if [ -z "$dns_fqdn" ] && [ -n "$domain" ] && [ -n "$hostname" ]; then - # fallback to what the dhcp told us - dns_fqdn="${hostname}.${domain}" - fi - if [ -z "$dns_fqdn" ]; then - dns_fqdn="$( hostname -f )" - fi - if [ -z "$dns_fqdn" ]; then - if [ -s "/etc/hostname" ]; then - dns_fqdn="$( head -n 1 /etc/hostname )" - else - dns_fqdn="noname-${ip//./-}.invalid" - fi - fi - # Only update hostname if network is not ready yet # later on this might cause issues if ! [ -e "$flag" ]; then - # Update hostname + # Fallback for hostname + if [ -z "$dns_fqdn" ] && [ -n "$domain" ] && [ -n "$hostname" ]; then + # fallback to what the dhcp told us + dns_fqdn="${hostname}.${domain}" + fi + if [ -z "$dns_fqdn" ]; then + # Try currently set fqdn + dns_fqdn="$( hostname -f )" + fi + if [ -z "$dns_fqdn" ]; then + if [ -s "/etc/hostname" ]; then + dns_fqdn="$( head -n 1 /etc/hostname )" + else + # Final fallback, nothing valid found + dns_fqdn="noname-${ip//./-}.invalid" + fi + fi # finally, if dns_fqdn was set to anything, apply it if [ -n "$dns_fqdn" ]; then dns_short="${dns_fqdn%%.*}" @@ -237,7 +238,13 @@ case "$1" in # Update /etc/issue for proper spacing /opt/openslx/scripts/openslx-create_issue touch "$flag" - fi # end "network not ready yet" + # end "network not ready yet" + else + # Network already going, make sure we don't change the primary hostname in /etc/hosts + hostname= + domain= + dns_fqdn= + fi # Remove any stray addresses; we expect the primary interface to only have one # address supplied via DHCP. We do this after adding the new one, obviously. rem_list=$( ip -o addr show "$interface" | awk '{ for (i=1;i