skeleton-init-common: improve /etc/hosts generation
authorCarlos Santos <casantos@datacom.com.br>
Fri, 19 Oct 2018 13:58:24 +0000 (10:58 -0300)
committerArnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Mon, 28 Jan 2019 23:12:00 +0000 (00:12 +0100)
If BR2_TARGET_GENERIC_HOSTNAME contains a FQDN, strip the host part and
add it as an alias, e.g.

    127.0.1.1 hostname.example.com hostname

Signed-off-by: Carlos Santos <casantos@datacom.com.br>
Reviewed-by: Matt Weber <matthew.weber@rockwellcollins.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
package/skeleton-init-common/skeleton-init-common.mk

index 7d2c68ada308e20d2afd6d8dc2b889f3d966696a..e429b13d7837e701c3e432f648ac313cbc0a6cdb 100644 (file)
@@ -42,10 +42,15 @@ SKELETON_INIT_COMMON_PASSWD_METHOD = $(call qstrip,$(BR2_TARGET_GENERIC_PASSWD_M
 SKELETON_INIT_COMMON_BIN_SH = $(call qstrip,$(BR2_SYSTEM_BIN_SH))
 
 ifneq ($(SKELETON_INIT_COMMON_HOSTNAME),)
+SKELETON_INIT_COMMON_HOSTS_LINE = $(SKELETON_INIT_COMMON_HOSTNAME)
+SKELETON_INIT_COMMON_SHORT_HOSTNAME = $(firstword $(subst ., ,$(SKELETON_INIT_COMMON_HOSTNAME)))
+ifneq ($(SKELETON_INIT_COMMON_HOSTNAME),$(SKELETON_INIT_COMMON_SHORT_HOSTNAME))
+SKELETON_INIT_COMMON_HOSTS_LINE += $(SKELETON_INIT_COMMON_SHORT_HOSTNAME)
+endif
 define SKELETON_INIT_COMMON_SET_HOSTNAME
        mkdir -p $(TARGET_DIR)/etc
        echo "$(SKELETON_INIT_COMMON_HOSTNAME)" > $(TARGET_DIR)/etc/hostname
-       $(SED) '$$a \127.0.1.1\t$(SKELETON_INIT_COMMON_HOSTNAME)' \
+       $(SED) '$$a \127.0.1.1\t$(SKELETON_INIT_COMMON_HOSTS_LINE)' \
                -e '/^127.0.1.1/d' $(TARGET_DIR)/etc/hosts
 endef
 SKELETON_INIT_COMMON_TARGET_FINALIZE_HOOKS += SKELETON_INIT_COMMON_SET_HOSTNAME