public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: claudius.heine.ext@siemens.com
To: isar-users@googlegroups.com
Cc: Claudius Heine <ch@denx.de>
Subject: [PATCH v4 3/8] meta/classes: add image-locales-extension class
Date: Thu, 23 May 2019 16:55:16 +0200	[thread overview]
Message-ID: <20190523145521.23050-4-claudius.heine.ext@siemens.com> (raw)
In-Reply-To: <20190523145521.23050-1-claudius.heine.ext@siemens.com>

From: Claudius Heine <ch@denx.de>

This class allows to configure the locales of the image and also uses
'localepurge' to remove unwanted locales.

The locale can be configured the same way as with the
isar-cfg-localepurge package, via the `LOCALE_GEN` and `LOCALE_DEFAULT`
variables.

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/classes/image-locales-extension.bbclass | 97 ++++++++++++++++++++
 meta/classes/image.bbclass                   |  1 +
 meta/classes/rootfs.bbclass                  |  4 +
 3 files changed, 102 insertions(+)
 create mode 100644 meta/classes/image-locales-extension.bbclass

diff --git a/meta/classes/image-locales-extension.bbclass b/meta/classes/image-locales-extension.bbclass
new file mode 100644
index 0000000..3c0758f
--- /dev/null
+++ b/meta/classes/image-locales-extension.bbclass
@@ -0,0 +1,97 @@
+# This software is a part of ISAR.
+# Copyright (C) Siemens AG, 2019
+#
+# SPDX-License-Identifier: MIT
+#
+# This class extends the image.bbclass for setting locales and purging unneeded
+# ones.
+
+LOCALE_GEN ?= "en_US.UTF-8 UTF-8\n\
+               en_US ISO-8859-1\n"
+LOCALE_DEFAULT ?= "en_US.UTF-8"
+
+def get_locale_gen(d, sep='\n'):
+    locale_gen = d.getVar("LOCALE_GEN", True) or ""
+    return sep.join(sorted(set(i.strip()
+                               for i in locale_gen.split('\\n')
+                               if i.strip())))
+
+def get_nopurge(d):
+    locale_gen = d.getVar("LOCALE_GEN", True) or ""
+    return '\n'.join(sorted(set(i.strip()
+                                for j in locale_gen.split('\\n')
+                                if j.strip()
+                                for i in (j.split()[0].split("_")[0],
+                                          j.split()[0].split(".")[0],
+                                          j.split()[0]))))
+
+ROOTFS_INSTALL_COMMAND_BEFORE_CLEAN += "image_install_localepurge_download"
+image_install_localepurge_download[weight] = "40"
+image_install_localepurge_download() {
+    sudo -E chroot '${ROOTFSDIR}' \
+        /usr/bin/apt-get ${ROOTFS_APT_ARGS} --download-only localepurge
+}
+
+ROOTFS_INSTALL_COMMAND += "image_install_localepurge_install"
+image_install_localepurge_install[weight] = "700"
+image_install_localepurge_install() {
+
+    # Generate locale and localepurge configuration:
+    cat<<__EOF__ > ${WORKDIR}/locale.gen
+${@get_locale_gen(d)}
+__EOF__
+    cat<<__EOF__ > ${WORKDIR}/locale.debconf
+locales     locales/locales_to_be_generated    multiselect ${@get_locale_gen(d, ', ')}
+locales     locales/default_environment_locale select      ${LOCALE_DEFAULT}
+__EOF__
+    cat<<__EOF__ > ${WORKDIR}/locale.default
+LANG=${LOCALE_DEFAULT}
+__EOF__
+    cat<<__EOF__ > ${WORKDIR}/locale.nopurge
+#USE_DPKG
+MANDELETE
+DONTBOTHERNEWLOCALE
+#SHOWFREEDSPACE
+#QUICKNDIRTYCALC
+#VERBOSE
+${@get_nopurge(d)}
+__EOF__
+
+    # Install configuration into image:
+    sudo -E -s <<'EOSUDO'
+        cat '${WORKDIR}/locale.gen' >> '${ROOTFSDIR}/etc/locale.gen'
+        cat '${WORKDIR}/locale.default' > '${ROOTFSDIR}/etc/default/locale'
+        cat '${WORKDIR}/locale.nopurge' > '${ROOTFSDIR}/etc/locale.nopurge'
+        cat '${WORKDIR}/locale.debconf' > '${ROOTFSDIR}/tmp/locale.debconf'
+
+        # Enter image and trigger locales config and localepurge:
+        chroot '${ROOTFSDIR}' /bin/sh <<'EOSH'
+            localepurge_state='i'
+            if dpkg -s localepurge 2>/dev/null >&2
+            then
+                echo 'localepurge was installed (leaving it installed later)'
+            else
+                localepurge_state='p'
+                echo 'localepurge was not installed (removing it later)'
+                apt-get ${ROOTFS_APT_ARGS} localepurge
+            fi
+
+            echo 'running locale debconf-set-selections'
+            debconf-set-selections /tmp/locale.debconf
+            rm -f '/tmp/locale.debconf'
+
+            echo 'reconfigure locales'
+            dpkg-reconfigure -f noninteractive locales
+
+            echo 'running localepurge'
+            localepurge
+
+            if [ "$localepurge_state" = 'p' ]
+            then
+                echo removing localepurge...
+                apt-get purge --yes localepurge 
+                apt-get autoremove --purge --yes
+            fi
+EOSH
+EOSUDO
+}
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 99eea92..dce6638 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -60,6 +60,7 @@ inherit image-sdk-extension
 inherit image-cache-extension
 inherit image-tools-extension
 inherit image-postproc-extension
+inherit image-locales-extension
 
 # Extra space for rootfs in MB
 ROOTFS_EXTRA ?= "64"
diff --git a/meta/classes/rootfs.bbclass b/meta/classes/rootfs.bbclass
index 0fc8ba8..5736eee 100644
--- a/meta/classes/rootfs.bbclass
+++ b/meta/classes/rootfs.bbclass
@@ -99,6 +99,7 @@ rootfs_install_pkgs_update() {
         -o Dir::Etc::sourceparts="-" \
         -o APT::Get::List-Cleanup="0"
 }
+
 ROOTFS_INSTALL_COMMAND += "rootfs_install_resolvconf"
 rootfs_install_resolvconf[weight] = "1"
 rootfs_install_resolvconf() {
@@ -112,6 +113,9 @@ rootfs_install_pkgs_download() {
         /usr/bin/apt-get ${ROOTFS_APT_ARGS} --download-only ${ROOTFS_PACKAGES}
 }
 
+ROOTFS_INSTALL_COMMAND_BEFORE_CLEAN ??= ""
+ROOTFS_INSTALL_COMMAND += "${ROOTFS_INSTALL_COMMAND_BEFORE_CLEAN}"
+
 ROOTFS_INSTALL_COMMAND += "${@ 'rootfs_install_clean_files' if (d.getVar('ROOTFS_CLEAN_FILES') or '').strip() else ''}"
 rootfs_install_clean_files[weight] = "2"
 rootfs_install_clean_files() {
-- 
2.20.1


  parent reply	other threads:[~2019-05-23 14:55 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-23 14:55 [PATCH v4 0/8] pre-processing pipeline and transient package replacement claudius.heine.ext
2019-05-23 14:55 ` [PATCH v4 1/8] meta: remove transient package support claudius.heine.ext
2019-05-23 14:55 ` [PATCH v4 2/8] split up isar-bootstrap helper and implement pre-process pipeline claudius.heine.ext
2019-05-24 12:49   ` Maxim Yu. Osipov
2019-05-27  6:55     ` Claudius Heine
2019-05-27  7:20       ` Maxim Yu. Osipov
2019-05-27  7:36         ` Maxim Yu. Osipov
2019-05-27  8:30           ` Claudius Heine
2019-05-27  9:03         ` Claudius Heine
2019-05-27  9:49           ` Maxim Yu. Osipov
2019-05-27 10:44             ` [PATCH] rootfs.bbclass: add comment about task weights claudius.heine.ext
2019-05-29 12:38               ` Maxim Yu. Osipov
2019-08-14 16:00   ` [PATCH v4 2/8] split up isar-bootstrap helper and implement pre-process pipeline Jan Kiszka
2019-08-19  6:59     ` Claudius Heine
2019-08-19  7:02       ` Jan Kiszka
2019-08-19  7:09         ` Claudius Heine
2019-05-23 14:55 ` claudius.heine.ext [this message]
2019-05-23 14:55 ` [PATCH v4 4/8] meta/classes: add image-account-extension class claudius.heine.ext
2019-05-31  7:29   ` Jan Kiszka
2019-06-03  9:14     ` Claudius Heine
2019-05-23 14:55 ` [PATCH v4 5/8] doc: update description of image customization claudius.heine.ext
2019-05-23 14:55 ` [PATCH v4 6/8] doc: some fixes claudius.heine.ext
2019-05-23 14:55 ` [PATCH v4 7/8] meta-isar: local.conf.sample: update root password and isar user creation claudius.heine.ext
2019-05-23 14:55 ` [PATCH v4 8/8] RECIPE-API-CHANGELOG: update transient package removal + root password claudius.heine.ext
2019-05-24 12:56 ` [PATCH v4 0/8] pre-processing pipeline and transient package replacement Maxim Yu. Osipov
2019-05-27  7:56   ` Claudius Heine
2019-05-27  8:10     ` Maxim Yu. Osipov
2019-05-27  8:24       ` Claudius Heine
2019-05-27  9:28         ` Maxim Yu. Osipov
2019-05-27 15:22 ` Maxim Yu. Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190523145521.23050-4-claudius.heine.ext@siemens.com \
    --to=claudius.heine.ext@siemens.com \
    --cc=ch@denx.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox