[2/3] hostname-customization: add initial customization package

Message ID 20250311210939.4090-3-chris.larson@siemens.com
State Accepted, archived
Headers show
Series Add 'customization' package support | expand

Commit Message

chris.larson March 11, 2025, 9:09 p.m. UTC
From: Christopher Larson <chris.larson@siemens.com>

This package provides a simple customization package that allows the hostname to
be set in the image. As this value is set from the `HOSTNAME` metadata variable,
it must be set in the metadata.

Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
 .../customizations/hostname-customization.bb          | 11 +++++++++++
 .../hostname-customization/postinst.tmpl              |  5 +++++
 2 files changed, 16 insertions(+)
 create mode 100644 meta/recipes-support/customizations/hostname-customization.bb
 create mode 100644 meta/recipes-support/customizations/hostname-customization/postinst.tmpl

Patch

diff --git a/meta/recipes-support/customizations/hostname-customization.bb b/meta/recipes-support/customizations/hostname-customization.bb
new file mode 100644
index 00000000..ba37c973
--- /dev/null
+++ b/meta/recipes-support/customizations/hostname-customization.bb
@@ -0,0 +1,11 @@ 
+inherit dpkg-customization
+
+DESCRIPTION      = "Amend the system hostname"
+LICENSE          = "gpl-2.0"
+LIC_FILES_CHKSUM = "file://${LAYERDIR_core}/licenses/COPYING.GPLv2;md5=751419260aa954499f7abaabaa882bbe"
+MAINTAINER       = "isar-users <isar-users@googlegroups.com>"
+DEBIAN_DEPENDS   = "netbase"
+PV               = "0.3"
+SRC_URI          = "file://postinst.tmpl"
+TEMPLATE_FILES   = "postinst.tmpl"
+TEMPLATE_VARS    = "HOSTNAME"
diff --git a/meta/recipes-support/customizations/hostname-customization/postinst.tmpl b/meta/recipes-support/customizations/hostname-customization/postinst.tmpl
new file mode 100644
index 00000000..db9475df
--- /dev/null
+++ b/meta/recipes-support/customizations/hostname-customization/postinst.tmpl
@@ -0,0 +1,5 @@ 
+#!/bin/sh
+
+echo "${HOSTNAME}" > /etc/hostname
+echo "127.0.1.1	${HOSTNAME}" >> /etc/hosts
+sed -i  -e 's/^127.0.0.1[[:space:]]\+localhost$/& localhost.localdomain/' /etc/hosts