From 2d574cb13fa532e53667888eb19e6dec798b0467 Mon Sep 17 00:00:00 2001
From: Andrei Gherzan <andrei.gherzan@huawei.com>
Date: Tue, 9 Mar 2021 11:06:43 +0000
Subject: [PATCH] ohos-image.bbclass: Introduce class

This class allows to hook a post install function that would mask getty
services enabled by systemd as part of `systemd_preset_all`.

To take advantage of it, an image would:
1. inherit this class
2. define SYSTEMD_MASK_GETTY to point to a list of tty devices that the
   hook will mask the getty service for.

Common use-case: disable running getty on tty1 at boot.

Signed-off-by: Andrei Gherzan <andrei.gherzan@huawei.com>
---
 meta-ohos-core/classes/ohos-image.bbclass | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
 create mode 100644 meta-ohos-core/classes/ohos-image.bbclass

diff --git a/meta-ohos-core/classes/ohos-image.bbclass b/meta-ohos-core/classes/ohos-image.bbclass
new file mode 100644
index 00000000..3db9ed20
--- /dev/null
+++ b/meta-ohos-core/classes/ohos-image.bbclass
@@ -0,0 +1,14 @@
+# OpenHarmony functionality for images
+
+# List of tty to mask getty for
+SYSTEMD_MASK_GETTY ?= ""
+
+systemd_mask_getty () {
+    if [ -e ${IMAGE_ROOTFS}${root_prefix}/lib/systemd/systemd ]; then
+        for i in ${SYSTEMD_MASK_GETTY}; do
+            systemctl --root="${IMAGE_ROOTFS}" mask "getty@${i}.service"
+        done
+    fi
+}
+
+IMAGE_PREPROCESS_COMMAND_append = " ${@ 'systemd_mask_getty;' if bb.utils.contains('DISTRO_FEATURES', 'systemd', True, False, d) and not bb.utils.contains('IMAGE_FEATURES', 'stateless-rootfs', True, False, d) else ''}"
-- 
GitLab