[v2] skeleton-init-common: improve /etc/hosts generation

Message ID 20181019135824.981-1-casantos@datacom.com.br
State New
Headers show
Series
  • [v2] skeleton-init-common: improve /etc/hosts generation
Related show

Commit Message

Carlos Santos Oct. 19, 2018, 1:58 p.m.
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>
---
Changes v1->v2: remove stray "else"
---
 package/skeleton-init-common/skeleton-init-common.mk | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Matthew Weber Oct. 19, 2018, 2:01 p.m. | #1
Carlos,

On Fri, Oct 19, 2018 at 8:58 AM Carlos Santos <casantos@datacom.com.br>
wrote:
>
> 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>

> ---
> Changes v1->v2: remove stray "else"
> ---
>  package/skeleton-init-common/skeleton-init-common.mk | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/package/skeleton-init-common/skeleton-init-common.mk
b/package/skeleton-init-common/skeleton-init-common.mk
> index e8a0522052..02f86df359 100644
> --- a/package/skeleton-init-common/skeleton-init-common.mk
> +++ b/package/skeleton-init-common/skeleton-init-common.mk
> @@ -41,10 +41,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
> --
> 2.14.4
>
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot

Patch

diff --git a/package/skeleton-init-common/skeleton-init-common.mk b/package/skeleton-init-common/skeleton-init-common.mk
index e8a0522052..02f86df359 100644
--- a/package/skeleton-init-common/skeleton-init-common.mk
+++ b/package/skeleton-init-common/skeleton-init-common.mk
@@ -41,10 +41,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