Set default locale in /etc/locale.conf

Message ID 78c228a7-1a11-119d-8fe9-03f62d47c752@siemens.com
State Superseded, archived
Headers show
Series Set default locale in /etc/locale.conf | expand

Commit Message

Tobias Schaffner Oct. 20, 2022, 10:51 a.m. UTC
Debian bookworm introduced systemd-firstboot [1] which asks the user to
configure some basic settings like hostname, timezone or locale if not already
configured.

It asks the user interactively to select a locale on first boot as we do not
have it set in /etc/locale.conf [2].

Create the /etc/locale.conf with the default locale setting to allow booting
bookworm images without user interaction.

[1] https://www.freedesktop.org/software/systemd/man/systemd-firstboot.html
[2] https://man7.org/linux/man-pages/man5/locale.conf.5.html

Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
---
  meta/classes/image-locales-extension.bbclass | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)

      cat<<__EOF__ > ${WORKDIR}/locale.nopurge
@@ -63,7 +63,7 @@ __EOF__
          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'
+        cat '${WORKDIR}/locale.conf' > '${ROOTFSDIR}/etc/locale.conf'

          # Enter image and trigger locales config and localepurge:
          chroot '${ROOTFSDIR}' /bin/sh <<'EOSH'
@@ -78,8 +78,7 @@ __EOF__
              fi

              echo 'running locale debconf-set-selections'
-            debconf-set-selections /tmp/locale.debconf
-            rm -f '/tmp/locale.debconf'
+            debconf-set-selections /etc/locale.conf

              echo 'reconfigure locales'
              dpkg-reconfigure -f noninteractive locales

Comments

Henning Schild Oct. 20, 2022, 11 a.m. UTC | #1
Am Thu, 20 Oct 2022 12:51:57 +0200
schrieb "Schaffner, Tobias (T CED SES-DE)"
<tobias.schaffner@siemens.com>:

> Debian bookworm introduced systemd-firstboot [1] which asks the user
> to configure some basic settings like hostname, timezone or locale if
> not already configured.
> 
> It asks the user interactively to select a locale on first boot as we
> do not have it set in /etc/locale.conf [2].
> 
> Create the /etc/locale.conf with the default locale setting to allow
> booting bookworm images without user interaction.
> 
> [1]
> https://www.freedesktop.org/software/systemd/man/systemd-firstboot.html
> [2] https://man7.org/linux/man-pages/man5/locale.conf.5.html
> 
> Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
> ---
>   meta/classes/image-locales-extension.bbclass | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/meta/classes/image-locales-extension.bbclass 
> b/meta/classes/image-locales-extension.bbclass
> index 25af540..964793a 100644
> --- a/meta/classes/image-locales-extension.bbclass
> +++ b/meta/classes/image-locales-extension.bbclass

For all changes in that file we need to switch-case old vs new, not
support only new.

So some sort of if systemd and systemd version >= 0815

Henning

> @@ -44,7 +44,7 @@ __EOF__
>   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
> +    cat<<__EOF__ > ${WORKDIR}/locale.conf
>   LANG=${LOCALE_DEFAULT}
>   __EOF__
>       cat<<__EOF__ > ${WORKDIR}/locale.nopurge
> @@ -63,7 +63,7 @@ __EOF__
>           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'
> +        cat '${WORKDIR}/locale.conf' > '${ROOTFSDIR}/etc/locale.conf'
> 
>           # Enter image and trigger locales config and localepurge:
>           chroot '${ROOTFSDIR}' /bin/sh <<'EOSH'
> @@ -78,8 +78,7 @@ __EOF__
>               fi
> 
>               echo 'running locale debconf-set-selections'
> -            debconf-set-selections /tmp/locale.debconf
> -            rm -f '/tmp/locale.debconf'
> +            debconf-set-selections /etc/locale.conf
> 
>               echo 'reconfigure locales'
>               dpkg-reconfigure -f noninteractive locales
Uladzimir Bely Oct. 20, 2022, 12:12 p.m. UTC | #2
In mail from четверг, 20 октября 2022 г. 13:51:57 +03 user Schaffner, Tobias 
wrote:

Hello. 
I've just tried your changes with both 'bullseye' and 'bookworm' under qemu 
and it they both booted properly (before, bookworm boot too, much more time 
and resulted in some kind of error).

Just a question: How did you send this patch? Because both 'mbox'-es, one 
generated by our patchwork ( https://patchwork.isar-build.org/project/isar/
patch/78c228a7-1a11-119d-8fe9-03f62d47c752@siemens.com/ ) and another I saved 
in the mail client, couldn't be applied. So, I had to apply this changes 
manually, line by line.

Probably, the patch was sent from some client that broke lines?

> Debian bookworm introduced systemd-firstboot [1] which asks the user to
> configure some basic settings like hostname, timezone or locale if not
> already configured.
> 
> It asks the user interactively to select a locale on first boot as we do not
> have it set in /etc/locale.conf [2].
> 
> Create the /etc/locale.conf with the default locale setting to allow booting
> bookworm images without user interaction.
> 
> [1] https://www.freedesktop.org/software/systemd/man/systemd-firstboot.html
> [2] https://man7.org/linux/man-pages/man5/locale.conf.5.html
> 
> Signed-off-by: Tobias Schaffner <tobias.schaffner@siemens.com>
> ---
>   meta/classes/image-locales-extension.bbclass | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/meta/classes/image-locales-extension.bbclass
> b/meta/classes/image-locales-extension.bbclass
> index 25af540..964793a 100644
> --- a/meta/classes/image-locales-extension.bbclass
> +++ b/meta/classes/image-locales-extension.bbclass
> @@ -44,7 +44,7 @@ __EOF__
>   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
> +    cat<<__EOF__ > ${WORKDIR}/locale.conf
>   LANG=${LOCALE_DEFAULT}
>   __EOF__
>       cat<<__EOF__ > ${WORKDIR}/locale.nopurge
> @@ -63,7 +63,7 @@ __EOF__
>           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' +        cat '${WORKDIR}/locale.conf' >
> '${ROOTFSDIR}/etc/locale.conf'
> 
>           # Enter image and trigger locales config and localepurge:
>           chroot '${ROOTFSDIR}' /bin/sh <<'EOSH'
> @@ -78,8 +78,7 @@ __EOF__
>               fi
> 
>               echo 'running locale debconf-set-selections'
> -            debconf-set-selections /tmp/locale.debconf
> -            rm -f '/tmp/locale.debconf'
> +            debconf-set-selections /etc/locale.conf
> 
>               echo 'reconfigure locales'
>               dpkg-reconfigure -f noninteractive locales
Tobias Schaffner Oct. 24, 2022, 8:08 a.m. UTC | #3
On 20.10.22 14:12, Uladzimir Bely wrote:
> In mail from четверг, 20 октября 2022 г. 13:51:57 +03 user Schaffner, Tobias
> wrote:
> 
> Hello.
> I've just tried your changes with both 'bullseye' and 'bookworm' under qemu
> and it they both booted properly (before, bookworm boot too, much more time
> and resulted in some kind of error).

Hello Uladzimir,

thanks for testing. I will send a v2 that removes the conf file for older 
systemd versions.

> Just a question: How did you send this patch? Because both 'mbox'-es, one
> generated by our patchwork ( https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.isar-build.org%2Fproject%2Fisar%2F&amp;data=05%7C01%7Ctobias.schaffner%40siemens.com%7C4dd8f14b423943ca93c908dab2946d89%7C38ae3bcd95794fd4addab42e1495d55a%7C1%7C0%7C638018647803542876%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=APsJwt9XO0LTShE6xR5UB%2Fz2SWefuxfNxx2egkXebvk%3D&amp;reserved=0
> patch/78c228a7-1a11-119d-8fe9-03f62d47c752@siemens.com/ ) and another I saved
> in the mail client, couldn't be applied. So, I had to apply this changes
> manually, line by line.
> 
> Probably, the patch was sent from some client that broke lines?

I temporarily hat not access to smtp and tried to copy everything together in 
thunderbird. Looks like it added some newlines. I will send the next version 
with git directly.

All the best
Jan Kiszka Oct. 24, 2022, 12:04 p.m. UTC | #4
On 24.10.22 10:08, Schaffner, Tobias wrote:
> On 20.10.22 14:12, Uladzimir Bely wrote:
>> In mail from четверг, 20 октября 2022 г. 13:51:57 +03 user Schaffner, Tobias
>> wrote:
>>
>> Hello.
>> I've just tried your changes with both 'bullseye' and 'bookworm' under qemu
>> and it they both booted properly (before, bookworm boot too, much more time
>> and resulted in some kind of error).
> 
> Hello Uladzimir,
> 
> thanks for testing. I will send a v2 that removes the conf file for older 
> systemd versions.
> 
>> Just a question: How did you send this patch? Because both 'mbox'-es, one
>> generated by our patchwork ( https://patchwork.isar-build.org/project/isar/
>> patch/78c228a7-1a11-119d-8fe9-03f62d47c752@siemens.com/ ) and another I saved
>> in the mail client, couldn't be applied. So, I had to apply this changes
>> manually, line by line.
>>
>> Probably, the patch was sent from some client that broke lines?
> 
> I temporarily hat not access to smtp and tried to copy everything together in 
> thunderbird. Looks like it added some newlines. I will send the next version 
> with git directly.

If you do that in TB, you want https://addons.thunderbird.net/de/thunderbird/addon/toggle-line-wrap :D

Jan

Patch

diff --git a/meta/classes/image-locales-extension.bbclass 
b/meta/classes/image-locales-extension.bbclass
index 25af540..964793a 100644
--- a/meta/classes/image-locales-extension.bbclass
+++ b/meta/classes/image-locales-extension.bbclass
@@ -44,7 +44,7 @@  __EOF__
  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
+    cat<<__EOF__ > ${WORKDIR}/locale.conf
  LANG=${LOCALE_DEFAULT}
  __EOF__