All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dracut: add support for custom locale definitions
@ 2016-04-15 22:07 Guido Trentalancia
       [not found] ` <1460758050.3211.2.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-15 22:07 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc. The
resulting locale definitions archive contains at most two different locale
definitions, therefore its size is relatively small.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/module-setup.sh |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- dracut-044/modules.d/10i18n/module-setup.sh	2016-04-15 23:34:44.011398268 +0200
+++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-15 23:32:05.292860621 +0200
@@ -219,6 +219,16 @@ install() {
             print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
         fi
 
+        [[ $LC_ALL || $LANG ]] && inst_dir /usr/lib/locale
+
+        # Generate locale definitions for LC_ALL
+        [ $LC_ALL ] && LC_ALL_LOCALE=`echo $LC_ALL | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo $LC_ALL | awk -F. '{ print $2 }'`
+        [[ $LC_ALL && $LC_ALL_LOCALE && $LC_ALL_CHARMAP ]] && localedef --prefix="${initdir}" -i $LC_ALL_LOCALE -f $LC_ALL_CHARMAP $LC_ALL
+
+        # Generate locale definitions for LANG
+        [ $LANG ] && LANG_LOCALE=`echo $LANG | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo $LANG | awk -F. '{ print $2 }'`
+        [[ $LANG && $LANG_LOCALE && $LANG_CHARMAP ]] && localedef --prefix="${initdir}" -i $LANG_LOCALE -f $LANG_CHARMAP $LANG
+
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
             inst_simple ${VCONFIG_CONF}
         else

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH] dracut: add support for custom locale definitions
       [not found] ` <1460758050.3211.2.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-16  6:00   ` Andrei Borzenkov
       [not found]     ` <5711D4E7.9070705-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Andrei Borzenkov @ 2016-04-16  6:00 UTC (permalink / raw)
  To: Guido Trentalancia, initramfs-u79uwXL29TY76Z2rM5mHXA

16.04.2016 01:07, Guido Trentalancia пишет:
> Compile and install locale definitions using localedef from GNU libc. The
> resulting locale definitions archive contains at most two different locale
> definitions, therefore its size is relatively small.
> 

On many distributions sources for locale definitions are in separate
packages that are not installed by default. You need at least error
checks and some alternative way to gather the same information.

> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> ---
>  modules.d/10i18n/module-setup.sh |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> --- dracut-044/modules.d/10i18n/module-setup.sh	2016-04-15 23:34:44.011398268 +0200
> +++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-15 23:32:05.292860621 +0200
> @@ -219,6 +219,16 @@ install() {
>              print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
>          fi
>  
> +        [[ $LC_ALL || $LANG ]] && inst_dir /usr/lib/locale
> +
> +        # Generate locale definitions for LC_ALL
> +        [ $LC_ALL ] && LC_ALL_LOCALE=`echo $LC_ALL | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo $LC_ALL | awk -F. '{ print $2 }'`
> +        [[ $LC_ALL && $LC_ALL_LOCALE && $LC_ALL_CHARMAP ]] && localedef --prefix="${initdir}" -i $LC_ALL_LOCALE -f $LC_ALL_CHARMAP $LC_ALL
> +
> +        # Generate locale definitions for LANG
> +        [ $LANG ] && LANG_LOCALE=`echo $LANG | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo $LANG | awk -F. '{ print $2 }'`
> +        [[ $LANG && $LANG_LOCALE && $LANG_CHARMAP ]] && localedef --prefix="${initdir}" -i $LANG_LOCALE -f $LANG_CHARMAP $LANG
> +
>          if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
>              inst_simple ${VCONFIG_CONF}
>          else
> --
> To unsubscribe from this list: send the line "unsubscribe initramfs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v2] dracut: 10i18n: add support for custom locale definitions
       [not found]     ` <5711D4E7.9070705-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-04-16 14:12       ` Guido Trentalancia
       [not found]         ` <1460815966.4296.13.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-16 14:12 UTC (permalink / raw)
  To: Andrei Borzenkov, initramfs-u79uwXL29TY76Z2rM5mHXA

Hello Andrei.

Thanks very for much for reviewing the patch...

On Sat, 16/04/2016 at 09.00 +0300, Andrei Borzenkov wrote:
> 16.04.2016 01:07, Guido Trentalancia пишет:
> > Compile and install locale definitions using localedef from GNU
> > libc. The
> > resulting locale definitions archive contains at most two different
> > locale
> > definitions, therefore its size is relatively small.
> > 
> 
> On many distributions sources for locale definitions are in separate
> packages that are not installed by default. You need at least error
> checks and some alternative way to gather the same information.

Good point, I have now included a check to make sure that the localedef
executable is available on the system (please see the new patch version
reported below)...

I don't know exactly what you mean by "some alternative way to gather
the same information", however if you mean copying the locale archive
from the one installed on the system, I am against that, as it is
usually very large, while the one we generate here is rather small and
should be usually compatible with the initram filesystem size
constraint.

/usr/lib/locale-archive (system-wide): 101,997,312 bytes
average locale-archive generated ad-hoc by localedef for initramfs:
1,629,568

... there is a size factor of about 63 !
---
Compile and install locale definitions using localedef from GNU libc. The
resulting locale definitions archive contains at most two different locale
definitions, therefore its size is relatively small.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/module-setup.sh |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- dracut-git/modules.d/10i18n/module-setup.sh	2016-04-12 15:59:43.174765608 +0200
+++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-16 15:59:51.254099707 +0200
@@ -212,6 +219,16 @@ install() {
             print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
         fi
 
+        [[ $LC_ALL || $LANG ]] && inst_dir /usr/lib/locale
+
+        # Generate locale definitions for LC_ALL
+        [ $LC_ALL ] && LC_ALL_LOCALE=`echo $LC_ALL | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo $LC_ALL | awk -F. '{ print $2 }'`
+        [[ $LC_ALL && $LC_ALL_LOCALE && $LC_ALL_CHARMAP ]] && command -v localedef > /dev/null && localedef --prefix="${initdir}" -i $LC_ALL_LOCALE -f $LC_ALL_CHARMAP $LC_ALL
+
+        # Generate locale definitions for LANG
+        [ $LANG ] && LANG_LOCALE=`echo $LANG | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo $LANG | awk -F. '{ print $2 }'`
+        [[ $LANG && $LANG_LOCALE && $LANG_CHARMAP ]] && command -v localedef > /dev/null && localedef --prefix="${initdir}" -i $LANG_LOCALE -f $LANG_CHARMAP $LANG
+
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
             inst_simple ${VCONFIG_CONF}
         else


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v2] dracut: 10i18n: add support for custom locale definitions
       [not found]         ` <1460815966.4296.13.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-16 17:52           ` Andrei Borzenkov
       [not found]             ` <57127BC9.70103-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Andrei Borzenkov @ 2016-04-16 17:52 UTC (permalink / raw)
  To: Guido Trentalancia, initramfs-u79uwXL29TY76Z2rM5mHXA

16.04.2016 17:12, Guido Trentalancia пишет:
> Hello Andrei.
> 
> Thanks very for much for reviewing the patch...
> 
> On Sat, 16/04/2016 at 09.00 +0300, Andrei Borzenkov wrote:
>> 16.04.2016 01:07, Guido Trentalancia пишет:
>>> Compile and install locale definitions using localedef from GNU
>>> libc. The
>>> resulting locale definitions archive contains at most two different
>>> locale
>>> definitions, therefore its size is relatively small.
>>>
>>
>> On many distributions sources for locale definitions are in separate
>> packages that are not installed by default. You need at least error
>> checks and some alternative way to gather the same information.
> 
> Good point, I have now included a check to make sure that the localedef
> executable is available on the system (please see the new patch version
> reported below)...
> 

It is not about localedef itself (which is likely to be present) but
about sources for locale definitions that you assume to be always available.

> I don't know exactly what you mean by "some alternative way to gather
> the same information", however if you mean copying the locale archive
> from the one installed on the system, I am against that, as it is
> usually very large, while the one we generate here is rather small and
> should be usually compatible with the initram filesystem size
> constraint.
> 

Locale archive is not used universally. Other systems use split
definitions in /usr/lib/locale/$LOCALE. Just copy them directly if present.

> /usr/lib/locale-archive (system-wide): 101,997,312 bytes
> average locale-archive generated ad-hoc by localedef for initramfs:
> 1,629,568
> 
> ... there is a size factor of about 63 !
> ---
> Compile and install locale definitions using localedef from GNU libc. The
> resulting locale definitions archive contains at most two different locale
> definitions, therefore its size is relatively small.
> 
> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> ---
>  modules.d/10i18n/module-setup.sh |   10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> --- dracut-git/modules.d/10i18n/module-setup.sh	2016-04-12 15:59:43.174765608 +0200
> +++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-16 15:59:51.254099707 +0200
> @@ -212,6 +219,16 @@ install() {
>              print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
>          fi
>  
> +        [[ $LC_ALL || $LANG ]] && inst_dir /usr/lib/locale
> +
> +        # Generate locale definitions for LC_ALL
> +        [ $LC_ALL ] && LC_ALL_LOCALE=`echo $LC_ALL | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo $LC_ALL | awk -F. '{ print $2 }'`
> +        [[ $LC_ALL && $LC_ALL_LOCALE && $LC_ALL_CHARMAP ]] && command -v localedef > /dev/null && localedef --prefix="${initdir}" -i $LC_ALL_LOCALE -f $LC_ALL_CHARMAP $LC_ALL
> +
> +        # Generate locale definitions for LANG
> +        [ $LANG ] && LANG_LOCALE=`echo $LANG | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo $LANG | awk -F. '{ print $2 }'`
> +        [[ $LANG && $LANG_LOCALE && $LANG_CHARMAP ]] && command -v localedef > /dev/null && localedef --prefix="${initdir}" -i $LANG_LOCALE -f $LANG_CHARMAP $LANG
> +
>          if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
>              inst_simple ${VCONFIG_CONF}
>          else
> 
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v3] dracut: 10i18n: add support for custom locale definitions
       [not found]             ` <57127BC9.70103-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-04-16 19:32               ` Guido Trentalancia
       [not found]                 ` <1460835143.3201.10.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-16 19:32 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc. The
resulting locale definitions archive contains at most two different locale
definitions, therefore its size is relatively small.

This revised version fixes several issues in the initial patch. Thanks to
Andrei Borzenkov for reviewing it.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/module-setup.sh |   24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

--- dracut-044-orig/modules.d/10i18n/module-setup.sh	2015-11-25 14:22:28.000000000 +0100
+++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-16 21:21:53.059812954 +0200
@@ -212,6 +219,23 @@ install() {
             print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
         fi
 
+        [[ ${LC_ALL} || ${LANG} ]] && inst_dir /usr/lib/locale
+
+        command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
+
+        # Generate locale definitions for LC_ALL
+        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{ print $2 }'`
+        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]] && [ $HAS_LOCALEDEF == true ] && localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+
+        # Generate locale definitions for LANG
+        [ ${LANG} ] && [ ${LANG} != ${LC_ALL} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2 }'`
+        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [ ${HAS_LOCALEDEF} == true ] && localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+
+        # If localedef is not available, but compiled split definitions are,
+        # then copy them over
+        [ ${LC_ALL} ] && [ ${HAS_LOCALEDEF} == false ] && [ -d /usr/lib/locale/${LC_ALL} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+        [ ${LANG} ] && [ ${LANG} != ${LC_ALL} ] && [ ${HAS_LOCALEDEF} == false ] && [ -d /usr/lib/locale/${LANG} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
             inst_simple ${VCONFIG_CONF}
         else

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v4] dracut: 10i18n: add support for custom locale definitions
       [not found]                 ` <1460835143.3201.10.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-16 20:13                   ` Guido Trentalancia
       [not found]                     ` <1460837622.3201.14.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-16 20:13 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc or,
if locale definitions cannot be compiled but are available on the system
as split definitions, just install them.

The resulting locale definitions archive contains at most two different
locale definitions, therefore its size is relatively small.

This revised version fixes several issues in the initial patch (including
the possibility to build locale definitions). Thanks to Andrei Borzenkov
for reviewing the initial patch and providing useful suggestions.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/module-setup.sh |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--- dracut-044-orig/modules.d/10i18n/module-setup.sh	2015-11-25 14:22:28.000000000 +0100
+++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-16 22:09:43.667941277 +0200
@@ -212,6 +219,26 @@ install() {
             print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
         fi
 
+        [[ ${LC_ALL} || ${LANG} ]] && inst_dir /usr/lib/locale
+
+        # Check if we can compile locale definitions
+        command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
+        [[ -e /usr/share/i18n/locales/${LC_ALL} || -e /usr/share/i18n/locales/${LANG} ]] && HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
+        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
+
+        # Generate locale definitions for LC_ALL
+        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{ print $2 }'`
+        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_ALL} ] && localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+
+        # Generate locale definitions for LANG
+        [ ${LANG} ] && [ ${LANG} != ${LC_ALL} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2 }'`
+        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LANG} ] && localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+
+        # If locale definitions cannot be built, but compiled split definitions are
+        # available, then copy them over
+        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_ALL} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+        [ ${LANG} ] && [ ${LANG} != ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LANG} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
             inst_simple ${VCONFIG_CONF}
         else

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v5] dracut: 10i18n: add support for custom locale definitions
       [not found]                     ` <1460837622.3201.14.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-16 20:24                       ` Guido Trentalancia
       [not found]                         ` <1460838269.3201.18.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-16 20:24 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc or,
if locale definitions cannot be compiled but are available on the system
as split definitions, just install them.

The resulting locale definitions archive contains at most two different
locale definitions, therefore its size is relatively small.

This revised version fixes several issues in the initial patch (including
the possibility to build locale definitions). Thanks to Andrei Borzenkov
for reviewing the initial patch and providing useful suggestions.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/module-setup.sh |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

--- dracut-044-orig/modules.d/10i18n/module-setup.sh	2015-11-25 14:22:28.000000000 +0100
+++ dracut-044-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-16 22:20:41.175221254 +0200
@@ -212,6 +219,26 @@ install() {
             print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
         fi
 
+        [[ ${LC_ALL} || ${LANG} ]] && inst_dir /usr/lib/locale
+
+        # Check if we can compile locale definitions
+        command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
+        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{ print $2 }'`
+        [ ${LANG} ] && [ ${LANG} != ${LC_ALL} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2 }'`
+        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e /usr/share/i18n/locales/${LANG_LOCALE} ]] && HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
+        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
+
+        # Generate locale definitions for LC_ALL
+        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+
+        # Generate locale definitions for LANG
+        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+
+        # If locale definitions cannot be built, but compiled split definitions are
+        # available, then copy them over
+        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_ALL} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+        [ ${LANG} ] && [ ${LANG} != ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LANG} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
             inst_simple ${VCONFIG_CONF}
         else

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v6] dracut: add support for custom locale definitions
       [not found]                         ` <1460838269.3201.18.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-19  0:36                           ` Guido Trentalancia
       [not found]                             ` <1461026208.2262.1.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-19  0:36 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc or,
if locale definitions cannot be compiled but are available on the system
as split definitions, just install them.

The resulting locale definitions archive contains at most two different
locale definitions, therefore its size is relatively small.

Add support for localised messages from core packages (LC_MESSAGES).

Add support for non-latin fonts using Unicode (Asian ones needs testing).

This revised version fixes several issues in the initial patch (including
the possibility to build locale definitions). Thanks to Andrei Borzenkov
for reviewing the initial patch and providing useful suggestions.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/README          |    1
 modules.d/10i18n/console_init.sh |    2 +
 modules.d/10i18n/module-setup.sh |   69 +++++++++++++++++++++++++++++++++++++--
 modules.d/10i18n/parse-i18n.sh   |    8 ++--
 modules.d/99base/init.sh         |   27 ++++++++++++++-
 modules.d/99base/module-setup.sh |    4 ++
 6 files changed, 104 insertions(+), 7 deletions(-)

diff -pru dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/console_init.sh
--- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-19 02:19:10.657042489 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/console_init.sh	2016-04-19 02:26:46.616644174 +0200
@@ -89,5 +89,7 @@ set_terminal ${dev}
 set_font ${dev}
 set_keymap
 
+reset
+
 dev_close
 
diff -pru dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh
--- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-19 02:19:10.657042489 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-19 02:27:40.408336513 +0200
@@ -4,7 +4,7 @@
 check() {
     [[ "$mount_needs" ]] && return 1
 
-    require_binaries setfont loadkeys kbd_mode || return 1
+    require_binaries setfont loadkeys kbd_mode unicode_start stty tty tset reset || return 1
 
     return 0
 }
@@ -26,6 +26,7 @@ install() {
     DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
     I18N_CONF="/etc/locale.conf"
     VCONFIG_CONF="/etc/vconsole.conf"
+    CORE_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd"
 
     # This is from 10redhat-i18n.
     findkeymap () {
@@ -93,7 +94,7 @@ install() {
     }
 
     install_base() {
-        inst_multiple setfont loadkeys kbd_mode stty
+        inst_multiple setfont loadkeys kbd_mode unicode_start stty tty tset reset
 
         if ! dracut_module_included "systemd"; then
             inst ${moddir}/console_init.sh /lib/udev/console_init
@@ -205,11 +206,73 @@ install() {
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
         fi
 
+        [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
+
+        # Check if we can compile locale definitions
+        command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
+        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{ print $2 }'`
+        [ ${LANG} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2 }'`
+        [ ${LC_MESSAGES} ] && LC_MESSAGES_LOCALE=`echo ${LC_MESSAGES} | awk -F. '{ print $1 }'` && LC_MESSAGES_CHARMAP=`echo ${LC_MESSAGES} | awk -F. '{ print $2 }'`
+        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e /usr/share/i18n/locales/${LANG_LOCALE} || -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]] && HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
+        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
+
+        # Generate locale definitions for LC_ALL
+        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+
+        # Generate locale definitions for LANG
+        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+
+        # Generate locale definitions for LC_MESSAGES
+        [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
+
+        # If locale definitions cannot be built, but compiled split definitions are
+        # available, then install them
+        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_ALL} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+        [ ${LANG} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LANG} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+        [ ${LC_MESSAGES} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_MESSAGES} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
+
+        # Install individual localisation files for core packages
+        [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
+        [ ${LC_ALL_LOCALE} ] && inst_dir /usr/share/locale/${LC_ALL_LOCALE}
+        [ ${LANG_LOCALE} ] && inst_dir /usr/share/locale/${LANG_LOCALE}
+        [ ${LC_MESSAGES_LOCALE} ] && inst_dir /usr/share/locale/${LC_MESSAGES_LOCALE}
+        [ ${LC_ALL_LOCALE} ] && LC_ALL_LOCALE_SHORT=`echo ${LC_ALL_LOCALE} | awk -F_ '{ print $1 }'`
+        [ ${LANG_LOCALE} ] && LANG_LOCALE_SHORT=`echo ${LANG_LOCALE} | awk -F_ '{ print $1 }'`
+        [ ${LC_MESSAGES_LOCALE} ] && LC_MESSAGES_LOCALE_SHORT=`echo ${LC_MESSAGES_LOCALE} | awk -F_ '{ print $1 }'`
+        [ ${LC_ALL_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LC_ALL_LOCALE_SHORT}
+        [ ${LANG_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LANG_LOCALE_SHORT}
+        [ ${LC_MESSAGES_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}
+
+        locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
+        for dir in ${locale_dirs}; do
+            [ -d /usr/share/locale/${dir} ] && for pkg in ${CORE_PACKAGES}; do
+                for file in `find /usr/share/locale/${dir} -type f -name "${pkg}.mo"`; do
+                    cp -pfL --parents -t "${initdir}/" ${file};
+                done
+            done
+        done
+
+        # Install some of the GNU libc charmap modules
+        [ -e "${initdir}/lib/ld-linux.so.*" ] && LIBDIR=lib || LIBDIR=lib64
+        inst_simple /usr/${LIBDIR}/gconv/ISO8859-*.so
+        [ ${UNICODE} == 1 ] && inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so
+        [ ${UNICODE} == 1 ] && inst_simple /usr/${LIBDIR}/gconv/UNICODE.so
+        command -v iconvconfig > /dev/null && HAS_ICONVCONFIG=true || HAS_ICONVCONFIG=false
+        [ ${HAS_ICONVCONFIG} == true ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^alias" | grep ISO8859- > /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^alias" | grep UTF- >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^alias" | grep UNICODE >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^module" | grep ISO8859- | grep INTERNAL >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^module" | grep UTF- | grep INTERNAL >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^module" | grep UNICODE | grep INTERNAL >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ -e /tmp/gconv-modules ] && inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && iconvconfig --prefix="${initdir}"
+        [ ${HAS_ICONVCONFIG} == false ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ] && inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache
+
         if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
             inst_simple ${I18N_CONF}
         else
             mksubdirs ${initdir}${I18N_CONF}
-            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
+            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
         fi
 
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
diff -pru dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/parse-i18n.sh
--- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:19:10.657042489 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
@@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
 inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
 inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
 
-inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
-inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
-
+inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
+inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
+inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
+ 
 if [ -f /etc/locale.conf ]; then
     . /etc/locale.conf
     export LANG
     export LC_ALL
+    export LC_MESSAGES
 fi
diff -pru dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/README
--- dracut-git-orig/modules.d/10i18n/README	2016-04-19 02:19:10.657042489 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
@@ -65,6 +65,7 @@ I'm leaving it in case...  The following
 
     LANG
     LC_ALL
+    LC_MESSAGES
 
 If UNICODE variable is not provided, script indicates if UTF-8 should be
 used on the basis of LANG value (if it ends with ".utf8" or similar).
diff -pru dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/init.sh
--- dracut-git-orig/modules.d/99base/init.sh	2016-04-19 02:19:10.702043068 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/init.sh	2016-04-19 02:26:46.618644199 +0200
@@ -8,6 +8,31 @@
 
 export -p > /tmp/export.orig
 
+[ -f /etc/locale.conf ] && . /etc/locale.conf
+[ -f /etc/vconsole.conf ] && . /etc/vconsole.conf
+
+shopt -q -s nocasematch
+if [[ ${UNICODE} ]]
+then
+    if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
+    then
+        UNICODE=1
+    elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
+    then
+        UNICODE=0
+    else
+        UNICODE=''
+    fi
+fi
+if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
+then
+    UNICODE=1
+fi
+shopt -q -u nocasematch
+
+[[ ${UNICODE} == 1 && ${FONT} && ! ${FONT_MAP} ]] && [ -x /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
+[[ ${UNICODE} == 1 && ${FONT} && ${FONT_MAP} ]] && [ -x /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT} ${FONT_MAP}
+
 NEWROOT="/sysroot"
 [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
 
@@ -323,7 +348,7 @@ for i in $(export -p); do
     i=${i%%=*}
     [ -z "$i" ] && continue
     case $i in
-        root|PATH|HOME|TERM|PS4|RD_*)
+        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
             :;;
         *)
             unset "$i";;
diff -pru dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/module-setup.sh
--- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-19 02:19:10.702043068 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/module-setup.sh	2016-04-19 02:26:46.619644212 +0200
@@ -26,6 +26,10 @@ install() {
         (ln -s bash "${initdir}/bin/sh" || :)
     fi
 
+    if dracut_module_included "i18n"; then
+       inst ${moddir}/bashrc /etc/bashrc
+    fi
+
     #add common users in /etc/passwd, it will be used by nfs/ssh currently
     grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
     grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v7] dracut: add support for custom locale definitions
       [not found]                             ` <1461026208.2262.1.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-20 13:04                               ` Guido Trentalancia
       [not found]                                 ` <1461157491.11229.3.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-20 13:04 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc or,
if locale definitions cannot be compiled but are available on the system
as split definitions, just install them.

The resulting locale definitions archive contains at most two different
locale definitions, therefore its size is relatively small.

Add support for localised messages from core packages (LC_MESSAGES).

Add support for non-latin fonts using Unicode (tested successfully with
Greek, Hebrew and Cyrillic).

This revised version fixes several issues in the initial patch (including
the possibility to build locale definitions). Thanks to Andrei Borzenkov
for reviewing the initial patch and providing useful suggestions.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 modules.d/10i18n/README          |    1
 modules.d/10i18n/console_init.sh |   24 +++++++++++
 modules.d/10i18n/module-setup.sh |   82 +++++++++++++++++++++++++++++++++++++--
 modules.d/10i18n/parse-i18n.sh   |    8 ++-
 modules.d/99base/bashrc          |    9 ++++
 modules.d/99base/init.sh         |    4 +
 modules.d/99base/module-setup.sh |    4 +
 7 files changed, 125 insertions(+), 7 deletions(-)

diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/console_init.sh
--- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-20 14:11:02.824944921 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/console_init.sh	2016-04-20 14:01:51.452010155 +0200
@@ -74,6 +74,28 @@ devname=${dev#/dev/}
     exit 1
 }
 
+shopt -q -s nocasematch
+if [[ ${UNICODE} ]]
+then
+    if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
+    then
+        UNICODE=1
+    elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
+    then
+        UNICODE=0
+    else
+        UNICODE=''
+    fi
+fi
+if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
+then
+    UNICODE=1
+fi
+shopt -q -u nocasematch
+
+[[ ${UNICODE} == 1 && ${FONT} && ! ${FONT_MAP} ]] && [ -x /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
+[[ ${UNICODE} == 1 && ${FONT} && ${FONT_MAP} ]] && [ -x /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT} ${FONT_MAP}
+
 dev_open ${dev}
 
 for fd in 6 7; do
@@ -89,5 +111,7 @@ set_terminal ${dev}
 set_font ${dev}
 set_keymap
 
+reset
+
 dev_close
 
diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh
--- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-20 14:11:02.825944933 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-20 14:44:39.610119250 +0200
@@ -1,10 +1,15 @@
 #!/bin/bash
 
+# Updated: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
+#
+#  Added full localisation support (including message-based
+#  program localisation and support for non-latin charsets)
+
 # called by dracut
 check() {
     [[ "$mount_needs" ]] && return 1
 
-    require_binaries setfont loadkeys kbd_mode || return 1
+    require_binaries setfont loadkeys kbd_mode unicode_start stty tty tset reset || return 1
 
     return 0
 }
@@ -26,6 +31,15 @@ install() {
     DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
     I18N_CONF="/etc/locale.conf"
     VCONFIG_CONF="/etc/vconsole.conf"
+    LOCALISED_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd cryptsetup"
+
+    if dracut_module_included "crypt"; then
+       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} cryptsetup"
+    fi
+
+    if dracut_module_included "crypt-gpg"; then
+       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} gnupg"
+    fi
 
     # This is from 10redhat-i18n.
     findkeymap () {
@@ -93,7 +107,7 @@ install() {
     }
 
     install_base() {
-        inst_multiple setfont loadkeys kbd_mode stty
+        inst_multiple setfont loadkeys kbd_mode unicode_start stty tty tset reset
 
         if ! dracut_module_included "systemd"; then
             inst ${moddir}/console_init.sh /lib/udev/console_init
@@ -205,11 +219,73 @@ install() {
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
         fi
 
+        [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
+
+        # Check if we can compile locale definitions
+        command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
+        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{ print $2 }'`
+        [ ${LANG} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2 }'`
+        [ ${LC_MESSAGES} ] && LC_MESSAGES_LOCALE=`echo ${LC_MESSAGES} | awk -F. '{ print $1 }'` && LC_MESSAGES_CHARMAP=`echo ${LC_MESSAGES} | awk -F. '{ print $2 }'`
+        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e /usr/share/i18n/locales/${LANG_LOCALE} || -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]] && HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
+        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
+
+        # Generate locale definitions for LC_ALL
+        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+
+        # Generate locale definitions for LANG
+        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+
+        # Generate locale definitions for LC_MESSAGES
+        [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
+
+        # If locale definitions cannot be built, but compiled split definitions are
+        # available, then install them
+        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_ALL} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+        [ ${LANG} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LANG} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+        [ ${LC_MESSAGES} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_MESSAGES} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
+
+        # Install individual localisation files for core packages
+        [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
+        [ ${LC_ALL_LOCALE} ] && inst_dir /usr/share/locale/${LC_ALL_LOCALE}
+        [ ${LANG_LOCALE} ] && inst_dir /usr/share/locale/${LANG_LOCALE}
+        [ ${LC_MESSAGES_LOCALE} ] && inst_dir /usr/share/locale/${LC_MESSAGES_LOCALE}
+        [ ${LC_ALL_LOCALE} ] && LC_ALL_LOCALE_SHORT=`echo ${LC_ALL_LOCALE} | awk -F_ '{ print $1 }'`
+        [ ${LANG_LOCALE} ] && LANG_LOCALE_SHORT=`echo ${LANG_LOCALE} | awk -F_ '{ print $1 }'`
+        [ ${LC_MESSAGES_LOCALE} ] && LC_MESSAGES_LOCALE_SHORT=`echo ${LC_MESSAGES_LOCALE} | awk -F_ '{ print $1 }'`
+        [ ${LC_ALL_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LC_ALL_LOCALE_SHORT}
+        [ ${LANG_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LANG_LOCALE_SHORT}
+        [ ${LC_MESSAGES_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}
+
+        locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
+        for dir in ${locale_dirs}; do
+            [ -d /usr/share/locale/${dir} ] && for pkg in ${LOCALISED_PACKAGES}; do
+                for file in `find /usr/share/locale/${dir} -type f -name "${pkg}.mo"`; do
+                    cp -pfL --parents -t "${initdir}/" ${file};
+                done
+            done
+        done
+
+        # Install some of the GNU libc charmap modules
+        [ -e "${initdir}/lib/ld-linux.so.*" ] && LIBDIR=lib || LIBDIR=lib64
+        inst_simple /usr/${LIBDIR}/gconv/ISO8859-*.so
+        [ ${UNICODE} == 1 ] && inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so
+        [ ${UNICODE} == 1 ] && inst_simple /usr/${LIBDIR}/gconv/UNICODE.so
+        command -v iconvconfig > /dev/null && HAS_ICONVCONFIG=true || HAS_ICONVCONFIG=false
+        [ ${HAS_ICONVCONFIG} == true ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep ISO8859- > /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep UTF- >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep UNICODE >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep ISO8859- | grep INTERNAL >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep UTF- | grep INTERNAL >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep UNICODE | grep INTERNAL >> /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && [ -e /tmp/gconv-modules ] && inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
+        [ ${HAS_ICONVCONFIG} == true ] && iconvconfig --prefix="${initdir}"
+        [ ${HAS_ICONVCONFIG} == false ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ] && inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache
+
         if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
             inst_simple ${I18N_CONF}
         else
             mksubdirs ${initdir}${I18N_CONF}
-            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
+            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
         fi
 
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/parse-i18n.sh
--- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-20 14:11:02.825944933 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
@@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
 inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
 inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
 
-inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
-inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
-
+inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
+inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
+inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
+ 
 if [ -f /etc/locale.conf ]; then
     . /etc/locale.conf
     export LANG
     export LC_ALL
+    export LC_MESSAGES
 fi
diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/README
--- dracut-git-orig/modules.d/10i18n/README	2016-04-20 14:11:02.826944946 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
@@ -65,6 +65,7 @@ I'm leaving it in case...  The following
 
     LANG
     LC_ALL
+    LC_MESSAGES
 
 If UNICODE variable is not provided, script indicates if UTF-8 should be
 used on the basis of LANG value (if it ends with ".utf8" or similar).
diff -pruN dracut-git-orig/modules.d/99base/bashrc dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/bashrc
--- dracut-git-orig/modules.d/99base/bashrc	1970-01-01 01:00:00.000000000 +0100
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/bashrc	2016-04-20 14:22:39.804711030 +0200
@@ -0,0 +1,9 @@
+# /etc/bashrc
+
+# Load locale settings
+if [ -f /etc/locale.conf ]; then
+  . /etc/locale.conf
+  [ -n "${LANG}" ] && export LANG || unset LANG
+  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
+  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset LC_MESSAGES
+fi
diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/init.sh
--- dracut-git-orig/modules.d/99base/init.sh	2016-04-20 14:11:02.826944946 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/init.sh	2016-04-20 14:02:01.578137511 +0200
@@ -8,6 +8,8 @@
 
 export -p > /tmp/export.orig
 
+[ -f /etc/locale.conf ] && . /etc/locale.conf
+
 NEWROOT="/sysroot"
 [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
 
@@ -323,7 +325,7 @@ for i in $(export -p); do
     i=${i%%=*}
     [ -z "$i" ] && continue
     case $i in
-        root|PATH|HOME|TERM|PS4|RD_*)
+        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
             :;;
         *)
             unset "$i";;
diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/module-setup.sh
--- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-20 14:11:02.827944958 +0200
+++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/module-setup.sh	2016-04-19 02:26:46.619644212 +0200
@@ -26,6 +26,10 @@ install() {
         (ln -s bash "${initdir}/bin/sh" || :)
     fi
 
+    if dracut_module_included "i18n"; then
+       inst ${moddir}/bashrc /etc/bashrc
+    fi
+
     #add common users in /etc/passwd, it will be used by nfs/ssh currently
     grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
     grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                 ` <1461157491.11229.3.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-21 10:24                                   ` Harald Hoyer
       [not found]                                     ` <5718AA77.8090600-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Harald Hoyer @ 2016-04-21 10:24 UTC (permalink / raw)
  To: Guido Trentalancia, initramfs-u79uwXL29TY76Z2rM5mHXA

On 20.04.2016 15:04, Guido Trentalancia wrote:
> Compile and install locale definitions using localedef from GNU libc or,
> if locale definitions cannot be compiled but are available on the system
> as split definitions, just install them.
> 
> The resulting locale definitions archive contains at most two different
> locale definitions, therefore its size is relatively small.
> 
> Add support for localised messages from core packages (LC_MESSAGES).

Do we really need this in the initramfs?

> 
> Add support for non-latin fonts using Unicode (tested successfully with
> Greek, Hebrew and Cyrillic).
> 
> This revised version fixes several issues in the initial patch (including
> the possibility to build locale definitions). Thanks to Andrei Borzenkov
> for reviewing the initial patch and providing useful suggestions.
> 
> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> ---
>  modules.d/10i18n/README          |    1
>  modules.d/10i18n/console_init.sh |   24 +++++++++++
>  modules.d/10i18n/module-setup.sh |   82 +++++++++++++++++++++++++++++++++++++--
>  modules.d/10i18n/parse-i18n.sh   |    8 ++-
>  modules.d/99base/bashrc          |    9 ++++
>  modules.d/99base/init.sh         |    4 +
>  modules.d/99base/module-setup.sh |    4 +
>  7 files changed, 125 insertions(+), 7 deletions(-)
> 
> diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/console_init.sh
> --- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-20 14:11:02.824944921 +0200
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/console_init.sh	2016-04-20 14:01:51.452010155 +0200
> @@ -74,6 +74,28 @@ devname=${dev#/dev/}
>      exit 1
>  }
>  
> +shopt -q -s nocasematch
> +if [[ ${UNICODE} ]]
> +then
> +    if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
> +    then
> +        UNICODE=1
> +    elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
> +    then
> +        UNICODE=0
> +    else
> +        UNICODE=''
> +    fi
> +fi
> +if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
> +then
> +    UNICODE=1
> +fi
> +shopt -q -u nocasematch
> +
> +[[ ${UNICODE} == 1 && ${FONT} && ! ${FONT_MAP} ]] && [ -x /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
> +[[ ${UNICODE} == 1 && ${FONT} && ${FONT_MAP} ]] && [ -x /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT} ${FONT_MAP}
> +
>  dev_open ${dev}
>  
>  for fd in 6 7; do
> @@ -89,5 +111,7 @@ set_terminal ${dev}
>  set_font ${dev}
>  set_keymap
>  
> +reset
> +
>  dev_close

Please don't use bashisms in initramfs scripts which are not explicitly marked with "#!/bin/bash".
To test it:
- install "dash"
- run "make syncheck"
- activate the "00dash" dracut module and boot with it

>  
> diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh
> --- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-20 14:11:02.825944933 +0200
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/module-setup.sh	2016-04-20 14:44:39.610119250 +0200
> @@ -1,10 +1,15 @@
>  #!/bin/bash
>  
> +# Updated: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> +#
> +#  Added full localisation support (including message-based
> +#  program localisation and support for non-latin charsets)

git history should be enough, we don't mention it in the individual files

> +
>  # called by dracut
>  check() {
>      [[ "$mount_needs" ]] && return 1
>  
> -    require_binaries setfont loadkeys kbd_mode || return 1
> +    require_binaries setfont loadkeys kbd_mode unicode_start stty tty tset reset || return 1
>  
>      return 0
>  }
> @@ -26,6 +31,15 @@ install() {
>      DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
>      I18N_CONF="/etc/locale.conf"
>      VCONFIG_CONF="/etc/vconsole.conf"
> +    LOCALISED_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd cryptsetup"
> +
> +    if dracut_module_included "crypt"; then
> +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} cryptsetup"
> +    fi
> +
> +    if dracut_module_included "crypt-gpg"; then
> +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} gnupg"
> +    fi

I would create a function like "inst_i18n <prog>" which should be called by the individual dracut modules in their install()
section, rather than hardcoding it here.

>  
>      # This is from 10redhat-i18n.
>      findkeymap () {
> @@ -93,7 +107,7 @@ install() {
>      }
>  
>      install_base() {
> -        inst_multiple setfont loadkeys kbd_mode stty
> +        inst_multiple setfont loadkeys kbd_mode unicode_start stty tty tset reset
>  
>          if ! dracut_module_included "systemd"; then
>              inst ${moddir}/console_init.sh /lib/udev/console_init
> @@ -205,11 +219,73 @@ install() {
>              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
>          fi
>  
> +        [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
> +
> +        # Check if we can compile locale definitions
> +        command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
> +        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F. '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{ print $2 }'`

awk free version :)

$ read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ }); echo $LC_ALL_LOCALE; echo $LC_ALL_CHARMAP
de_DE
UTF-8


> +        [ ${LANG} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{ print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2 }'`
> +        [ ${LC_MESSAGES} ] && LC_MESSAGES_LOCALE=`echo ${LC_MESSAGES} | awk -F. '{ print $1 }'` && LC_MESSAGES_CHARMAP=`echo ${LC_MESSAGES} | awk -F. '{ print $2 }'`
> +        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e /usr/share/i18n/locales/${LANG_LOCALE} || -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]] && HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
> +        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
> +
> +        # Generate locale definitions for LC_ALL
> +        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
> +
> +        # Generate locale definitions for LANG
> +        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
> +
> +        # Generate locale definitions for LC_MESSAGES
> +        [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [ -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ] && localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
> +
> +        # If locale definitions cannot be built, but compiled split definitions are
> +        # available, then install them
> +        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_ALL} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
> +        [ ${LANG} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LANG} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
> +        [ ${LC_MESSAGES} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d /usr/lib/locale/${LC_MESSAGES} ] && cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}

you really don't like "if ; then; else" :)

> +
> +        # Install individual localisation files for core packages
> +        [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
> +        [ ${LC_ALL_LOCALE} ] && inst_dir /usr/share/locale/${LC_ALL_LOCALE}
> +        [ ${LANG_LOCALE} ] && inst_dir /usr/share/locale/${LANG_LOCALE}
> +        [ ${LC_MESSAGES_LOCALE} ] && inst_dir /usr/share/locale/${LC_MESSAGES_LOCALE}
> +        [ ${LC_ALL_LOCALE} ] && LC_ALL_LOCALE_SHORT=`echo ${LC_ALL_LOCALE} | awk -F_ '{ print $1 }'`
> +        [ ${LANG_LOCALE} ] && LANG_LOCALE_SHORT=`echo ${LANG_LOCALE} | awk -F_ '{ print $1 }'`
> +        [ ${LC_MESSAGES_LOCALE} ] && LC_MESSAGES_LOCALE_SHORT=`echo ${LC_MESSAGES_LOCALE} | awk -F_ '{ print $1 }'`

please don't use backticks... use $() every time

> +        [ ${LC_ALL_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LC_ALL_LOCALE_SHORT}
> +        [ ${LANG_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LANG_LOCALE_SHORT}
> +        [ ${LC_MESSAGES_LOCALE_SHORT} ] && inst_dir /usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}
> +
> +        locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
> +        for dir in ${locale_dirs}; do
> +            [ -d /usr/share/locale/${dir} ] && for pkg in ${LOCALISED_PACKAGES}; do
> +                for file in `find /usr/share/locale/${dir} -type f -name "${pkg}.mo"`; do

not expected, but this fails for files with spaces in the name

> +                    cp -pfL --parents -t "${initdir}/" ${file};

what's wrong with "inst_simple" ?

> +                done
> +            done
> +        done
> +
> +        # Install some of the GNU libc charmap modules
> +        [ -e "${initdir}/lib/ld-linux.so.*" ] && LIBDIR=lib || LIBDIR=lib64
> +        inst_simple /usr/${LIBDIR}/gconv/ISO8859-*.so
> +        [ ${UNICODE} == 1 ] && inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so
> +        [ ${UNICODE} == 1 ] && inst_simple /usr/${LIBDIR}/gconv/UNICODE.so

inst_simple would not install any library deps. better add it to the above line
[ ${UNICODE} == 1 ] && inst_multiple /usr/${LIBDIR}/gconv/UNICODE.so /usr/${LIBDIR}/gconv/UTF-*.so


> +        command -v iconvconfig > /dev/null && HAS_ICONVCONFIG=true || HAS_ICONVCONFIG=false
> +        [ ${HAS_ICONVCONFIG} == true ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep ISO8859- > /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep UTF- >> /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep UNICODE >> /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep ISO8859- | grep INTERNAL >> /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep UTF- | grep INTERNAL >> /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep UNICODE | grep INTERNAL >> /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && [ -e /tmp/gconv-modules ] && inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
> +        [ ${HAS_ICONVCONFIG} == true ] && iconvconfig --prefix="${initdir}"
> +        [ ${HAS_ICONVCONFIG} == false ] && [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ] && inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache

why no "if command -v iconvconfig >/dev/null; then ... else ... fi" ??

no need for " cat <file> | grep <pattern> " use "grep <pattern> <file>" directly

why grep | grep ?? why not:

grep -E "^[[:space:]]*alias.*ISO8859-" /usr/${LIBDIR}/gconv/gconv-modules


> +
>          if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
>              inst_simple ${I18N_CONF}
>          else
>              mksubdirs ${initdir}${I18N_CONF}
> -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
> +            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
>          fi
>  
>          if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
> diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/parse-i18n.sh
> --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-20 14:11:02.825944933 +0200
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
> @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
>  inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
>  inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
>  
> -inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
> -inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
> -
> +inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
> +inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
> +inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
> + 
>  if [ -f /etc/locale.conf ]; then
>      . /etc/locale.conf
>      export LANG
>      export LC_ALL
> +    export LC_MESSAGES
>  fi
> diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/README
> --- dracut-git-orig/modules.d/10i18n/README	2016-04-20 14:11:02.826944946 +0200
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
> @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
>  
>      LANG
>      LC_ALL
> +    LC_MESSAGES
>  
>  If UNICODE variable is not provided, script indicates if UTF-8 should be
>  used on the basis of LANG value (if it ends with ".utf8" or similar).
> diff -pruN dracut-git-orig/modules.d/99base/bashrc dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/bashrc
> --- dracut-git-orig/modules.d/99base/bashrc	1970-01-01 01:00:00.000000000 +0100
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/bashrc	2016-04-20 14:22:39.804711030 +0200
> @@ -0,0 +1,9 @@
> +# /etc/bashrc
> +
> +# Load locale settings
> +if [ -f /etc/locale.conf ]; then
> +  . /etc/locale.conf
> +  [ -n "${LANG}" ] && export LANG || unset LANG
> +  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
> +  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset LC_MESSAGES
> +fi
> diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/init.sh
> --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20 14:11:02.826944946 +0200
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/init.sh	2016-04-20 14:02:01.578137511 +0200
> @@ -8,6 +8,8 @@
>  
>  export -p > /tmp/export.orig
>  
> +[ -f /etc/locale.conf ] && . /etc/locale.conf
> +
>  NEWROOT="/sysroot"
>  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
>  
> @@ -323,7 +325,7 @@ for i in $(export -p); do
>      i=${i%%=*}
>      [ -z "$i" ] && continue
>      case $i in
> -        root|PATH|HOME|TERM|PS4|RD_*)
> +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
>              :;;
>          *)
>              unset "$i";;
> diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/module-setup.sh
> --- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-20 14:11:02.827944958 +0200
> +++ dracut-git-10i18n-add-support-for-custom-locale-definitions/modules.d/99base/module-setup.sh	2016-04-19 02:26:46.619644212 +0200
> @@ -26,6 +26,10 @@ install() {
>          (ln -s bash "${initdir}/bin/sh" || :)
>      fi
>  
> +    if dracut_module_included "i18n"; then
> +       inst ${moddir}/bashrc /etc/bashrc
> +    fi
> +

maybe only check if bash installed and maybe use /etc/profile to be shell agnostic

>      #add common users in /etc/passwd, it will be used by nfs/ssh currently
>      grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
>      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
> --

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                     ` <5718AA77.8090600-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
@ 2016-04-21 12:30                                       ` Guido Trentalancia
       [not found]                                         ` <1461241841.10934.12.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  2016-04-22 16:13                                       ` [PATCH v8] " Guido Trentalancia
  1 sibling, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-21 12:30 UTC (permalink / raw)
  To: Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

Hello Harald !

On Thu, 21/04/2016 Guido Trentalancia wrote:
> > Compile and install locale definitions using localedef from GNU
> > libc or,
> > if locale definitions cannot be compiled but are available on the
> > system
> > as split definitions, just install them.
> > 
> > The resulting locale definitions archive contains at most two
> > different
> > locale definitions, therefore its size is relatively small.
> > 
> > Add support for localised messages from core packages
> > (LC_MESSAGES).
> 
> Do we really need this in the initramfs?

It's a killer functionality !!! And it requires very little extra disk
space compared to the actual initramfs. You know, we tend not to use
the floppy disk anymore nowadays !...

If you agree with me, I will be glad to keep working on it so that the
change you propose are introduced. There are not few changes proposed
and they need testing, I will only carry them out if you are then
really going to commit the whole work.

Please confirm and I'll be glad to help.

Regards,

Guido

> > Add support for non-latin fonts using Unicode (tested successfully
> > with
> > Greek, Hebrew and Cyrillic).
> > 
> > This revised version fixes several issues in the initial patch
> > (including
> > the possibility to build locale definitions). Thanks to Andrei
> > Borzenkov
> > for reviewing the initial patch and providing useful suggestions.
> > 
> > Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> > ---
> >  modules.d/10i18n/README          |    1
> >  modules.d/10i18n/console_init.sh |   24 +++++++++++
> >  modules.d/10i18n/module-setup.sh |   82
> > +++++++++++++++++++++++++++++++++++++--
> >  modules.d/10i18n/parse-i18n.sh   |    8 ++-
> >  modules.d/99base/bashrc          |    9 ++++
> >  modules.d/99base/init.sh         |    4 +
> >  modules.d/99base/module-setup.sh |    4 +
> >  7 files changed, 125 insertions(+), 7 deletions(-)
> > 
> > diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh dracut-
> > git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/console_init.sh
> > --- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-
> > 04-20 14:11:02.824944921 +0200
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/console_init.sh	2016-04-20
> > 14:01:51.452010155 +0200
> > @@ -74,6 +74,28 @@ devname=${dev#/dev/}
> >      exit 1
> >  }
> >  
> > +shopt -q -s nocasematch
> > +if [[ ${UNICODE} ]]
> > +then
> > +    if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
> > +    then
> > +        UNICODE=1
> > +    elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
> > +    then
> > +        UNICODE=0
> > +    else
> > +        UNICODE=''
> > +    fi
> > +fi
> > +if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
> > +then
> > +    UNICODE=1
> > +fi
> > +shopt -q -u nocasematch
> > +
> > +[[ ${UNICODE} == 1 && ${FONT} && ! ${FONT_MAP} ]] && [ -x
> > /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
> > +[[ ${UNICODE} == 1 && ${FONT} && ${FONT_MAP} ]] && [ -x
> > /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
> > ${FONT_MAP}
> > +
> >  dev_open ${dev}
> >  
> >  for fd in 6 7; do
> > @@ -89,5 +111,7 @@ set_terminal ${dev}
> >  set_font ${dev}
> >  set_keymap
> >  
> > +reset
> > +
> >  dev_close
> 
> Please don't use bashisms in initramfs scripts which are not
> explicitly marked with "#!/bin/bash".
> To test it:
> - install "dash"
> - run "make syncheck"
> - activate the "00dash" dracut module and boot with it
> 
> >  
> > diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-
> > git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/module-setup.sh
> > --- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-
> > 04-20 14:11:02.825944933 +0200
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/module-setup.sh	2016-04-20
> > 14:44:39.610119250 +0200
> > @@ -1,10 +1,15 @@
> >  #!/bin/bash
> >  
> > +# Updated: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> > +#
> > +#  Added full localisation support (including message-based
> > +#  program localisation and support for non-latin charsets)
> 
> git history should be enough, we don't mention it in the individual
> files
> 
> > +
> >  # called by dracut
> >  check() {
> >      [[ "$mount_needs" ]] && return 1
> >  
> > -    require_binaries setfont loadkeys kbd_mode || return 1
> > +    require_binaries setfont loadkeys kbd_mode unicode_start stty
> > tty tset reset || return 1
> >  
> >      return 0
> >  }
> > @@ -26,6 +31,15 @@ install() {
> >      DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
> >      I18N_CONF="/etc/locale.conf"
> >      VCONFIG_CONF="/etc/vconsole.conf"
> > +    LOCALISED_PACKAGES="libc bash coreutils util-linux e2fsprogs
> > grep sed kbd cryptsetup"
> > +
> > +    if dracut_module_included "crypt"; then
> > +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} cryptsetup"
> > +    fi
> > +
> > +    if dracut_module_included "crypt-gpg"; then
> > +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} gnupg"
> > +    fi
> 
> I would create a function like "inst_i18n <prog>" which should be
> called by the individual dracut modules in their install()
> section, rather than hardcoding it here.
> 
> >  
> >      # This is from 10redhat-i18n.
> >      findkeymap () {
> > @@ -93,7 +107,7 @@ install() {
> >      }
> >  
> >      install_base() {
> > -        inst_multiple setfont loadkeys kbd_mode stty
> > +        inst_multiple setfont loadkeys kbd_mode unicode_start stty
> > tty tset reset
> >  
> >          if ! dracut_module_included "systemd"; then
> >              inst ${moddir}/console_init.sh /lib/udev/console_init
> > @@ -205,11 +219,73 @@ install() {
> >              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
> >          fi
> >  
> > +        [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir
> > /usr/lib/locale
> > +
> > +        # Check if we can compile locale definitions
> > +        command -v localedef > /dev/null && HAS_LOCALEDEF=true ||
> > HAS_LOCALEDEF=false
> > +        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F.
> > '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{
> > print $2 }'`
> 
> awk free version :)
> 
> $ read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ }); echo
> $LC_ALL_LOCALE; echo $LC_ALL_CHARMAP
> de_DE
> UTF-8
> 
> 
> > +        [ ${LANG} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{
> > print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2
> > }'`
> > +        [ ${LC_MESSAGES} ] && LC_MESSAGES_LOCALE=`echo
> > ${LC_MESSAGES} | awk -F. '{ print $1 }'` &&
> > LC_MESSAGES_CHARMAP=`echo ${LC_MESSAGES} | awk -F. '{ print $2 }'`
> > +        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e
> > /usr/share/i18n/locales/${LANG_LOCALE} || -e
> > /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]] &&
> > HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
> > +        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} ==
> > true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
> > +
> > +        # Generate locale definitions for LC_ALL
> > +        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]]
> > && [ ${CAN_BUILD_LOCALE} == true ] && [ -e
> > /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --
> > prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP}
> > ${LC_ALL}
> > +
> > +        # Generate locale definitions for LANG
> > +        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [
> > ${CAN_BUILD_LOCALE} == true ] && [ -e
> > /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --
> > prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
> > +
> > +        # Generate locale definitions for LC_MESSAGES
> > +        [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} &&
> > ${LC_MESSAGES_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [
> > -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ] && localedef --
> > prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f
> > ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
> > +
> > +        # If locale definitions cannot be built, but compiled
> > split definitions are
> > +        # available, then install them
> > +        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d
> > /usr/lib/locale/${LC_ALL} ] && cp -prfL -t
> > "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
> > +        [ ${LANG} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d
> > /usr/lib/locale/${LANG} ] && cp -prfL -t
> > "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
> > +        [ ${LC_MESSAGES} ] && [ ${CAN_BUILD_LOCALE} == false ] &&
> > [ -d /usr/lib/locale/${LC_MESSAGES} ] && cp -prfL -t
> > "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
> 
> you really don't like "if ; then; else" :)
> 
> > +
> > +        # Install individual localisation files for core packages
> > +        [ -e /usr/share/locale/locale.alias ] && inst_simple
> > /usr/share/locale/locale.alias
> > +        [ ${LC_ALL_LOCALE} ] && inst_dir
> > /usr/share/locale/${LC_ALL_LOCALE}
> > +        [ ${LANG_LOCALE} ] && inst_dir
> > /usr/share/locale/${LANG_LOCALE}
> > +        [ ${LC_MESSAGES_LOCALE} ] && inst_dir
> > /usr/share/locale/${LC_MESSAGES_LOCALE}
> > +        [ ${LC_ALL_LOCALE} ] && LC_ALL_LOCALE_SHORT=`echo
> > ${LC_ALL_LOCALE} | awk -F_ '{ print $1 }'`
> > +        [ ${LANG_LOCALE} ] && LANG_LOCALE_SHORT=`echo
> > ${LANG_LOCALE} | awk -F_ '{ print $1 }'`
> > +        [ ${LC_MESSAGES_LOCALE} ] &&
> > LC_MESSAGES_LOCALE_SHORT=`echo ${LC_MESSAGES_LOCALE} | awk -F_ '{
> > print $1 }'`
> 
> please don't use backticks... use $() every time
> 
> > +        [ ${LC_ALL_LOCALE_SHORT} ] && inst_dir
> > /usr/share/locale/${LC_ALL_LOCALE_SHORT}
> > +        [ ${LANG_LOCALE_SHORT} ] && inst_dir
> > /usr/share/locale/${LANG_LOCALE_SHORT}
> > +        [ ${LC_MESSAGES_LOCALE_SHORT} ] && inst_dir
> > /usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}
> > +
> > +        locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE}
> > ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT}
> > {LC_MESSAGES_LOCALE_SHORT}"
> > +        for dir in ${locale_dirs}; do
> > +            [ -d /usr/share/locale/${dir} ] && for pkg in
> > ${LOCALISED_PACKAGES}; do
> > +                for file in `find /usr/share/locale/${dir} -type f
> > -name "${pkg}.mo"`; do
> 
> not expected, but this fails for files with spaces in the name
> 
> > +                    cp -pfL --parents -t "${initdir}/" ${file};
> 
> what's wrong with "inst_simple" ?
> 
> > +                done
> > +            done
> > +        done
> > +
> > +        # Install some of the GNU libc charmap modules
> > +        [ -e "${initdir}/lib/ld-linux.so.*" ] && LIBDIR=lib ||
> > LIBDIR=lib64
> > +        inst_simple /usr/${LIBDIR}/gconv/ISO8859-*.so
> > +        [ ${UNICODE} == 1 ] && inst_multiple
> > /usr/${LIBDIR}/gconv/UTF-*.so
> > +        [ ${UNICODE} == 1 ] && inst_simple
> > /usr/${LIBDIR}/gconv/UNICODE.so
> 
> inst_simple would not install any library deps. better add it to the
> above line
> [ ${UNICODE} == 1 ] && inst_multiple /usr/${LIBDIR}/gconv/UNICODE.so
> /usr/${LIBDIR}/gconv/UTF-*.so
> 
> 
> > +        command -v iconvconfig > /dev/null && HAS_ICONVCONFIG=true
> > || HAS_ICONVCONFIG=false
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ -e
> > /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep
> > ISO8859- > /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
> > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep
> > UTF- >> /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
> > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep
> > UNICODE >> /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ -e
> > /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep
> > ISO8859- | grep INTERNAL >> /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
> > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep
> > UTF- | grep INTERNAL >> /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
> > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep
> > UNICODE | grep INTERNAL >> /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && [ -e /tmp/gconv-modules
> > ] && inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules &&
> > rm -f /tmp/gconv-modules
> > +        [ ${HAS_ICONVCONFIG} == true ] && iconvconfig --
> > prefix="${initdir}"
> > +        [ ${HAS_ICONVCONFIG} == false ] && [ -e
> > /usr/${LIBDIR}/gconv/gconv-modules.cache ] && inst_simple
> > /usr/${LIBDIR}/gconv/gconv-modules.cache
> 
> why no "if command -v iconvconfig >/dev/null; then ... else ... fi"
> ??
> 
> no need for " cat <file> | grep <pattern> " use "grep <pattern>
> <file>" directly
> 
> why grep | grep ?? why not:
> 
> grep -E "^[[:space:]]*alias.*ISO8859-" /usr/${LIBDIR}/gconv/gconv-
> modules
> 
> 
> > +
> >          if dracut_module_included "systemd" && [[ -f ${I18N_CONF}
> > ]]; then
> >              inst_simple ${I18N_CONF}
> >          else
> >              mksubdirs ${initdir}${I18N_CONF}
> > -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
> > +            print_vars LANG LC_ALL LC_MESSAGES >>
> > ${initdir}${I18N_CONF}
> >          fi
> >  
> >          if dracut_module_included "systemd" && [[ -f
> > ${VCONFIG_CONF} ]]; then
> > diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-
> > git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/parse-i18n.sh
> > --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-
> > 20 14:11:02.825944933 +0200
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/parse-i18n.sh	2016-04-19
> > 02:26:46.617644187 +0200
> > @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
> >  inst_key_val /etc/vconsole.conf UNICODE      1
> > rd.vconsole.font.unicode UNICODE vconsole.unicode
> >  inst_key_val /etc/vconsole.conf EXT_KEYMAP  ''
> > rd.vconsole.keymap.ext   EXT_KEYMAP
> >  
> > -inst_key_val /etc/locale.conf   LANG        ''
> > rd.locale.LANG           LANG
> > -inst_key_val /etc/locale.conf   LC_ALL      ''
> > rd.locale.LC_ALL         LC_ALL
> > -
> > +inst_key_val /etc/locale.conf   LANG              ''
> > rd.locale.LANG               LANG
> > +inst_key_val /etc/locale.conf   LC_ALL            ''
> > rd.locale.LC_ALL             LC_ALL
> > +inst_key_val /etc/locale.conf   LC_MESSAGES       ''
> > rd.locale.LC_MESSAGES        LC_MESSAGES
> > + 
> >  if [ -f /etc/locale.conf ]; then
> >      . /etc/locale.conf
> >      export LANG
> >      export LC_ALL
> > +    export LC_MESSAGES
> >  fi
> > diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-
> > 10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/README
> > --- dracut-git-orig/modules.d/10i18n/README	2016-04-20
> > 14:11:02.826944946 +0200
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/10i18n/README	2016-04-19
> > 02:26:46.617644187 +0200
> > @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
> >  
> >      LANG
> >      LC_ALL
> > +    LC_MESSAGES
> >  
> >  If UNICODE variable is not provided, script indicates if UTF-8
> > should be
> >  used on the basis of LANG value (if it ends with ".utf8" or
> > similar).
> > diff -pruN dracut-git-orig/modules.d/99base/bashrc dracut-git-
> > 10i18n-add-support-for-custom-locale-
> > definitions/modules.d/99base/bashrc
> > --- dracut-git-orig/modules.d/99base/bashrc	1970-01-01
> > 01:00:00.000000000 +0100
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/99base/bashrc	2016-04-20
> > 14:22:39.804711030 +0200
> > @@ -0,0 +1,9 @@
> > +# /etc/bashrc
> > +
> > +# Load locale settings
> > +if [ -f /etc/locale.conf ]; then
> > +  . /etc/locale.conf
> > +  [ -n "${LANG}" ] && export LANG || unset LANG
> > +  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
> > +  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset
> > LC_MESSAGES
> > +fi
> > diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-
> > 10i18n-add-support-for-custom-locale-
> > definitions/modules.d/99base/init.sh
> > --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20
> > 14:11:02.826944946 +0200
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/99base/init.sh	2016-04-20
> > 14:02:01.578137511 +0200
> > @@ -8,6 +8,8 @@
> >  
> >  export -p > /tmp/export.orig
> >  
> > +[ -f /etc/locale.conf ] && . /etc/locale.conf
> > +
> >  NEWROOT="/sysroot"
> >  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
> >  
> > @@ -323,7 +325,7 @@ for i in $(export -p); do
> >      i=${i%%=*}
> >      [ -z "$i" ] && continue
> >      case $i in
> > -        root|PATH|HOME|TERM|PS4|RD_*)
> > +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
> >              :;;
> >          *)
> >              unset "$i";;
> > diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh dracut-
> > git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/99base/module-setup.sh
> > --- dracut-git-orig/modules.d/99base/module-setup.sh	2016-
> > 04-20 14:11:02.827944958 +0200
> > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > definitions/modules.d/99base/module-setup.sh	2016-04-19
> > 02:26:46.619644212 +0200
> > @@ -26,6 +26,10 @@ install() {
> >          (ln -s bash "${initdir}/bin/sh" || :)
> >      fi
> >  
> > +    if dracut_module_included "i18n"; then
> > +       inst ${moddir}/bashrc /etc/bashrc
> > +    fi
> > +
> 
> maybe only check if bash installed and maybe use /etc/profile to be
> shell agnostic
> 
> >      #add common users in /etc/passwd, it will be used by nfs/ssh
> > currently
> >      grep '^root:' "$initdir/etc/passwd" 2>/dev/null ||
> > echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
> >      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
> > --
-- 
This message contains confidential information intended only for the use
of the addressee(s). If you are not the intended recipient, please
contact the sender by return e-mail and destroy all copies of the
original message.

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                         ` <1461241841.10934.12.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-21 12:41                                           ` Andrei Borzenkov
       [not found]                                             ` <CAA91j0U0XaJBaWNzBmRE3hs0zV7UKMEvO-6nBx_jaxkwhEHckg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2016-04-21 13:07                                           ` Harald Hoyer
  2016-05-17 10:12                                           ` Thomas Renninger
  2 siblings, 1 reply; 24+ messages in thread
From: Andrei Borzenkov @ 2016-04-21 12:41 UTC (permalink / raw)
  To: Guido Trentalancia; +Cc: Harald Hoyer, initramfs

On Thu, Apr 21, 2016 at 3:30 PM, Guido Trentalancia
<guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org> wrote:
> Hello Harald !
>
> On Thu, 21/04/2016 Guido Trentalancia wrote:
>> > Compile and install locale definitions using localedef from GNU
>> > libc or,
>> > if locale definitions cannot be compiled but are available on the
>> > system
>> > as split definitions, just install them.
>> >
>> > The resulting locale definitions archive contains at most two
>> > different
>> > locale definitions, therefore its size is relatively small.
>> >
>> > Add support for localised messages from core packages
>> > (LC_MESSAGES).
>>
>> Do we really need this in the initramfs?
>
> It's a killer functionality !!! And it requires very little extra disk
> space compared to the actual initramfs. You know, we tend not to use
> the floppy disk anymore nowadays !...
>

Hmm ... how do you determine which message catalogs need to be
included? It obviously depends on modules and there is no 1-to-1
correspondence between programs and message catalogs.

Do you have actual results how much space message catalogs for all
components in typical initrd consume?

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                             ` <CAA91j0U0XaJBaWNzBmRE3hs0zV7UKMEvO-6nBx_jaxkwhEHckg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2016-04-21 12:57                                               ` Guido Trentalancia
  0 siblings, 0 replies; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-21 12:57 UTC (permalink / raw)
  To: Andrei Borzenkov; +Cc: Harald Hoyer, initramfs

Hello Andrei !

On Thu, 21/04/2016 at 15.41 +0300, Andrei Borzenkov wrote:
> > On Thu, 21/04/2016 Guido Trentalancia wrote:

[...]

> > > > Add support for localised messages from core packages
> > > > (LC_MESSAGES).
> > > 
> > > Do we really need this in the initramfs?
> > 
> > It's a killer functionality !!! And it requires very little extra
> > disk
> > space compared to the actual initramfs. You know, we tend not to
> > use
> > the floppy disk anymore nowadays !...
> > 
> 
> Hmm ... how do you determine which message catalogs need to be
> included? It obviously depends on modules and there is no 1-to-1
> correspondence between programs and message catalogs.

A variable first defines the core packages to include (the very
minimum, such as e2fsprogs, coreutils and so on). Consider that's very
important information and not everybody speaks English. So you don't
really want to put at risk of corruption someone else filesystem or
similar things.

The above does not depend on installed modules, as core packages are
always present.

What do you mean exactly for 1-to-1 match between programs and message
catalogs ? Of course, a dracut module doesn't install all programs from
a given package, then you still need to install the message-based
localisation for the whole package. But we are talking about kilobytes:
e.g. 181522 /usr/share/locale/it/LC_MESSAGES/coreutils.mo

> Do you have actual results how much space message catalogs for all
> components in typical initrd consume?


For the italian locale, I have the following figures:

initramfs with full locale support: 32668248
initramfs with only the keyboard support (virtually useless to non-
English speaking users): 29624027

The difference is 3 Megabytes. Nothing compared to today's removable
mass storage capabilities.

Regards,

Guido

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                         ` <1461241841.10934.12.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  2016-04-21 12:41                                           ` Andrei Borzenkov
@ 2016-04-21 13:07                                           ` Harald Hoyer
       [not found]                                             ` <5718D074.70507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2016-05-17 10:12                                           ` Thomas Renninger
  2 siblings, 1 reply; 24+ messages in thread
From: Harald Hoyer @ 2016-04-21 13:07 UTC (permalink / raw)
  To: Guido Trentalancia, Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

On 21.04.2016 14:30, Guido Trentalancia wrote:
> Hello Harald !
> 
> On Thu, 21/04/2016 Guido Trentalancia wrote:
>>> Compile and install locale definitions using localedef from GNU
>>> libc or,
>>> if locale definitions cannot be compiled but are available on the
>>> system
>>> as split definitions, just install them.
>>>
>>> The resulting locale definitions archive contains at most two
>>> different
>>> locale definitions, therefore its size is relatively small.
>>>
>>> Add support for localised messages from core packages
>>> (LC_MESSAGES).
>>
>> Do we really need this in the initramfs?
> 
> It's a killer functionality !!! And it requires very little extra disk
> space compared to the actual initramfs. You know, we tend not to use
> the floppy disk anymore nowadays !...
> 
> If you agree with me, I will be glad to keep working on it so that the
> change you propose are introduced. There are not few changes proposed
> and they need testing, I will only carry them out if you are then
> really going to commit the whole work.
> 
> Please confirm and I'll be glad to help.

Confirmed, if you add an option to turn the installing of the message catalogs off.
Also see my other comments in the original reply.

> 
> Regards,
> 
> Guido
> 
>>> Add support for non-latin fonts using Unicode (tested successfully
>>> with
>>> Greek, Hebrew and Cyrillic).
>>>
>>> This revised version fixes several issues in the initial patch
>>> (including
>>> the possibility to build locale definitions). Thanks to Andrei
>>> Borzenkov
>>> for reviewing the initial patch and providing useful suggestions.
>>>
>>> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
>>> ---
>>>  modules.d/10i18n/README          |    1
>>>  modules.d/10i18n/console_init.sh |   24 +++++++++++
>>>  modules.d/10i18n/module-setup.sh |   82
>>> +++++++++++++++++++++++++++++++++++++--
>>>  modules.d/10i18n/parse-i18n.sh   |    8 ++-
>>>  modules.d/99base/bashrc          |    9 ++++
>>>  modules.d/99base/init.sh         |    4 +
>>>  modules.d/99base/module-setup.sh |    4 +
>>>  7 files changed, 125 insertions(+), 7 deletions(-)
>>>
>>> diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh dracut-
>>> git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/console_init.sh
>>> --- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-
>>> 04-20 14:11:02.824944921 +0200
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/console_init.sh	2016-04-20
>>> 14:01:51.452010155 +0200
>>> @@ -74,6 +74,28 @@ devname=${dev#/dev/}
>>>      exit 1
>>>  }
>>>  
>>> +shopt -q -s nocasematch
>>> +if [[ ${UNICODE} ]]
>>> +then
>>> +    if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
>>> +    then
>>> +        UNICODE=1
>>> +    elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
>>> +    then
>>> +        UNICODE=0
>>> +    else
>>> +        UNICODE=''
>>> +    fi
>>> +fi
>>> +if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
>>> +then
>>> +    UNICODE=1
>>> +fi
>>> +shopt -q -u nocasematch
>>> +
>>> +[[ ${UNICODE} == 1 && ${FONT} && ! ${FONT_MAP} ]] && [ -x
>>> /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
>>> +[[ ${UNICODE} == 1 && ${FONT} && ${FONT_MAP} ]] && [ -x
>>> /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
>>> ${FONT_MAP}
>>> +
>>>  dev_open ${dev}
>>>  
>>>  for fd in 6 7; do
>>> @@ -89,5 +111,7 @@ set_terminal ${dev}
>>>  set_font ${dev}
>>>  set_keymap
>>>  
>>> +reset
>>> +
>>>  dev_close
>>
>> Please don't use bashisms in initramfs scripts which are not
>> explicitly marked with "#!/bin/bash".
>> To test it:
>> - install "dash"
>> - run "make syncheck"
>> - activate the "00dash" dracut module and boot with it
>>
>>>  
>>> diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-
>>> git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/module-setup.sh
>>> --- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-
>>> 04-20 14:11:02.825944933 +0200
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/module-setup.sh	2016-04-20
>>> 14:44:39.610119250 +0200
>>> @@ -1,10 +1,15 @@
>>>  #!/bin/bash
>>>  
>>> +# Updated: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
>>> +#
>>> +#  Added full localisation support (including message-based
>>> +#  program localisation and support for non-latin charsets)
>>
>> git history should be enough, we don't mention it in the individual
>> files
>>
>>> +
>>>  # called by dracut
>>>  check() {
>>>      [[ "$mount_needs" ]] && return 1
>>>  
>>> -    require_binaries setfont loadkeys kbd_mode || return 1
>>> +    require_binaries setfont loadkeys kbd_mode unicode_start stty
>>> tty tset reset || return 1
>>>  
>>>      return 0
>>>  }
>>> @@ -26,6 +31,15 @@ install() {
>>>      DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
>>>      I18N_CONF="/etc/locale.conf"
>>>      VCONFIG_CONF="/etc/vconsole.conf"
>>> +    LOCALISED_PACKAGES="libc bash coreutils util-linux e2fsprogs
>>> grep sed kbd cryptsetup"
>>> +
>>> +    if dracut_module_included "crypt"; then
>>> +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} cryptsetup"
>>> +    fi
>>> +
>>> +    if dracut_module_included "crypt-gpg"; then
>>> +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} gnupg"
>>> +    fi
>>
>> I would create a function like "inst_i18n <prog>" which should be
>> called by the individual dracut modules in their install()
>> section, rather than hardcoding it here.
>>
>>>  
>>>      # This is from 10redhat-i18n.
>>>      findkeymap () {
>>> @@ -93,7 +107,7 @@ install() {
>>>      }
>>>  
>>>      install_base() {
>>> -        inst_multiple setfont loadkeys kbd_mode stty
>>> +        inst_multiple setfont loadkeys kbd_mode unicode_start stty
>>> tty tset reset
>>>  
>>>          if ! dracut_module_included "systemd"; then
>>>              inst ${moddir}/console_init.sh /lib/udev/console_init
>>> @@ -205,11 +219,73 @@ install() {
>>>              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
>>>          fi
>>>  
>>> +        [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir
>>> /usr/lib/locale
>>> +
>>> +        # Check if we can compile locale definitions
>>> +        command -v localedef > /dev/null && HAS_LOCALEDEF=true ||
>>> HAS_LOCALEDEF=false
>>> +        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk -F.
>>> '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{
>>> print $2 }'`
>>
>> awk free version :)
>>
>> $ read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ }); echo
>> $LC_ALL_LOCALE; echo $LC_ALL_CHARMAP
>> de_DE
>> UTF-8
>>
>>
>>> +        [ ${LANG} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{
>>> print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print $2
>>> }'`
>>> +        [ ${LC_MESSAGES} ] && LC_MESSAGES_LOCALE=`echo
>>> ${LC_MESSAGES} | awk -F. '{ print $1 }'` &&
>>> LC_MESSAGES_CHARMAP=`echo ${LC_MESSAGES} | awk -F. '{ print $2 }'`
>>> +        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e
>>> /usr/share/i18n/locales/${LANG_LOCALE} || -e
>>> /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]] &&
>>> HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
>>> +        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} ==
>>> true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
>>> +
>>> +        # Generate locale definitions for LC_ALL
>>> +        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]]
>>> && [ ${CAN_BUILD_LOCALE} == true ] && [ -e
>>> /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --
>>> prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP}
>>> ${LC_ALL}
>>> +
>>> +        # Generate locale definitions for LANG
>>> +        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] && [
>>> ${CAN_BUILD_LOCALE} == true ] && [ -e
>>> /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --
>>> prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
>>> +
>>> +        # Generate locale definitions for LC_MESSAGES
>>> +        [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} &&
>>> ${LC_MESSAGES_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] && [
>>> -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ] && localedef --
>>> prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f
>>> ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
>>> +
>>> +        # If locale definitions cannot be built, but compiled
>>> split definitions are
>>> +        # available, then install them
>>> +        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d
>>> /usr/lib/locale/${LC_ALL} ] && cp -prfL -t
>>> "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
>>> +        [ ${LANG} ] && [ ${CAN_BUILD_LOCALE} == false ] && [ -d
>>> /usr/lib/locale/${LANG} ] && cp -prfL -t
>>> "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
>>> +        [ ${LC_MESSAGES} ] && [ ${CAN_BUILD_LOCALE} == false ] &&
>>> [ -d /usr/lib/locale/${LC_MESSAGES} ] && cp -prfL -t
>>> "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
>>
>> you really don't like "if ; then; else" :)
>>
>>> +
>>> +        # Install individual localisation files for core packages
>>> +        [ -e /usr/share/locale/locale.alias ] && inst_simple
>>> /usr/share/locale/locale.alias
>>> +        [ ${LC_ALL_LOCALE} ] && inst_dir
>>> /usr/share/locale/${LC_ALL_LOCALE}
>>> +        [ ${LANG_LOCALE} ] && inst_dir
>>> /usr/share/locale/${LANG_LOCALE}
>>> +        [ ${LC_MESSAGES_LOCALE} ] && inst_dir
>>> /usr/share/locale/${LC_MESSAGES_LOCALE}
>>> +        [ ${LC_ALL_LOCALE} ] && LC_ALL_LOCALE_SHORT=`echo
>>> ${LC_ALL_LOCALE} | awk -F_ '{ print $1 }'`
>>> +        [ ${LANG_LOCALE} ] && LANG_LOCALE_SHORT=`echo
>>> ${LANG_LOCALE} | awk -F_ '{ print $1 }'`
>>> +        [ ${LC_MESSAGES_LOCALE} ] &&
>>> LC_MESSAGES_LOCALE_SHORT=`echo ${LC_MESSAGES_LOCALE} | awk -F_ '{
>>> print $1 }'`
>>
>> please don't use backticks... use $() every time
>>
>>> +        [ ${LC_ALL_LOCALE_SHORT} ] && inst_dir
>>> /usr/share/locale/${LC_ALL_LOCALE_SHORT}
>>> +        [ ${LANG_LOCALE_SHORT} ] && inst_dir
>>> /usr/share/locale/${LANG_LOCALE_SHORT}
>>> +        [ ${LC_MESSAGES_LOCALE_SHORT} ] && inst_dir
>>> /usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}
>>> +
>>> +        locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE}
>>> ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT}
>>> {LC_MESSAGES_LOCALE_SHORT}"
>>> +        for dir in ${locale_dirs}; do
>>> +            [ -d /usr/share/locale/${dir} ] && for pkg in
>>> ${LOCALISED_PACKAGES}; do
>>> +                for file in `find /usr/share/locale/${dir} -type f
>>> -name "${pkg}.mo"`; do
>>
>> not expected, but this fails for files with spaces in the name
>>
>>> +                    cp -pfL --parents -t "${initdir}/" ${file};
>>
>> what's wrong with "inst_simple" ?
>>
>>> +                done
>>> +            done
>>> +        done
>>> +
>>> +        # Install some of the GNU libc charmap modules
>>> +        [ -e "${initdir}/lib/ld-linux.so.*" ] && LIBDIR=lib ||
>>> LIBDIR=lib64
>>> +        inst_simple /usr/${LIBDIR}/gconv/ISO8859-*.so
>>> +        [ ${UNICODE} == 1 ] && inst_multiple
>>> /usr/${LIBDIR}/gconv/UTF-*.so
>>> +        [ ${UNICODE} == 1 ] && inst_simple
>>> /usr/${LIBDIR}/gconv/UNICODE.so
>>
>> inst_simple would not install any library deps. better add it to the
>> above line
>> [ ${UNICODE} == 1 ] && inst_multiple /usr/${LIBDIR}/gconv/UNICODE.so
>> /usr/${LIBDIR}/gconv/UTF-*.so
>>
>>
>>> +        command -v iconvconfig > /dev/null && HAS_ICONVCONFIG=true
>>> || HAS_ICONVCONFIG=false
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ -e
>>> /usr/${LIBDIR}/gconv/gconv-modules ] && cat
>>> /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep
>>> ISO8859- > /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
>>> -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
>>> /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep
>>> UTF- >> /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
>>> -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
>>> /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" | grep
>>> UNICODE >> /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ -e
>>> /usr/${LIBDIR}/gconv/gconv-modules ] && cat
>>> /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep
>>> ISO8859- | grep INTERNAL >> /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
>>> -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
>>> /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep
>>> UTF- | grep INTERNAL >> /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ] && [
>>> -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
>>> /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" | grep
>>> UNICODE | grep INTERNAL >> /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && [ -e /tmp/gconv-modules
>>> ] && inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules &&
>>> rm -f /tmp/gconv-modules
>>> +        [ ${HAS_ICONVCONFIG} == true ] && iconvconfig --
>>> prefix="${initdir}"
>>> +        [ ${HAS_ICONVCONFIG} == false ] && [ -e
>>> /usr/${LIBDIR}/gconv/gconv-modules.cache ] && inst_simple
>>> /usr/${LIBDIR}/gconv/gconv-modules.cache
>>
>> why no "if command -v iconvconfig >/dev/null; then ... else ... fi"
>> ??
>>
>> no need for " cat <file> | grep <pattern> " use "grep <pattern>
>> <file>" directly
>>
>> why grep | grep ?? why not:
>>
>> grep -E "^[[:space:]]*alias.*ISO8859-" /usr/${LIBDIR}/gconv/gconv-
>> modules
>>
>>
>>> +
>>>          if dracut_module_included "systemd" && [[ -f ${I18N_CONF}
>>> ]]; then
>>>              inst_simple ${I18N_CONF}
>>>          else
>>>              mksubdirs ${initdir}${I18N_CONF}
>>> -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
>>> +            print_vars LANG LC_ALL LC_MESSAGES >>
>>> ${initdir}${I18N_CONF}
>>>          fi
>>>  
>>>          if dracut_module_included "systemd" && [[ -f
>>> ${VCONFIG_CONF} ]]; then
>>> diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-
>>> git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/parse-i18n.sh
>>> --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-
>>> 20 14:11:02.825944933 +0200
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/parse-i18n.sh	2016-04-19
>>> 02:26:46.617644187 +0200
>>> @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
>>>  inst_key_val /etc/vconsole.conf UNICODE      1
>>> rd.vconsole.font.unicode UNICODE vconsole.unicode
>>>  inst_key_val /etc/vconsole.conf EXT_KEYMAP  ''
>>> rd.vconsole.keymap.ext   EXT_KEYMAP
>>>  
>>> -inst_key_val /etc/locale.conf   LANG        ''
>>> rd.locale.LANG           LANG
>>> -inst_key_val /etc/locale.conf   LC_ALL      ''
>>> rd.locale.LC_ALL         LC_ALL
>>> -
>>> +inst_key_val /etc/locale.conf   LANG              ''
>>> rd.locale.LANG               LANG
>>> +inst_key_val /etc/locale.conf   LC_ALL            ''
>>> rd.locale.LC_ALL             LC_ALL
>>> +inst_key_val /etc/locale.conf   LC_MESSAGES       ''
>>> rd.locale.LC_MESSAGES        LC_MESSAGES
>>> + 
>>>  if [ -f /etc/locale.conf ]; then
>>>      . /etc/locale.conf
>>>      export LANG
>>>      export LC_ALL
>>> +    export LC_MESSAGES
>>>  fi
>>> diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-
>>> 10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/README
>>> --- dracut-git-orig/modules.d/10i18n/README	2016-04-20
>>> 14:11:02.826944946 +0200
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/10i18n/README	2016-04-19
>>> 02:26:46.617644187 +0200
>>> @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
>>>  
>>>      LANG
>>>      LC_ALL
>>> +    LC_MESSAGES
>>>  
>>>  If UNICODE variable is not provided, script indicates if UTF-8
>>> should be
>>>  used on the basis of LANG value (if it ends with ".utf8" or
>>> similar).
>>> diff -pruN dracut-git-orig/modules.d/99base/bashrc dracut-git-
>>> 10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/99base/bashrc
>>> --- dracut-git-orig/modules.d/99base/bashrc	1970-01-01
>>> 01:00:00.000000000 +0100
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/99base/bashrc	2016-04-20
>>> 14:22:39.804711030 +0200
>>> @@ -0,0 +1,9 @@
>>> +# /etc/bashrc
>>> +
>>> +# Load locale settings
>>> +if [ -f /etc/locale.conf ]; then
>>> +  . /etc/locale.conf
>>> +  [ -n "${LANG}" ] && export LANG || unset LANG
>>> +  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
>>> +  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset
>>> LC_MESSAGES
>>> +fi
>>> diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-
>>> 10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/99base/init.sh
>>> --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20
>>> 14:11:02.826944946 +0200
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/99base/init.sh	2016-04-20
>>> 14:02:01.578137511 +0200
>>> @@ -8,6 +8,8 @@
>>>  
>>>  export -p > /tmp/export.orig
>>>  
>>> +[ -f /etc/locale.conf ] && . /etc/locale.conf
>>> +
>>>  NEWROOT="/sysroot"
>>>  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
>>>  
>>> @@ -323,7 +325,7 @@ for i in $(export -p); do
>>>      i=${i%%=*}
>>>      [ -z "$i" ] && continue
>>>      case $i in
>>> -        root|PATH|HOME|TERM|PS4|RD_*)
>>> +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
>>>              :;;
>>>          *)
>>>              unset "$i";;
>>> diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh dracut-
>>> git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/99base/module-setup.sh
>>> --- dracut-git-orig/modules.d/99base/module-setup.sh	2016-
>>> 04-20 14:11:02.827944958 +0200
>>> +++ dracut-git-10i18n-add-support-for-custom-locale-
>>> definitions/modules.d/99base/module-setup.sh	2016-04-19
>>> 02:26:46.619644212 +0200
>>> @@ -26,6 +26,10 @@ install() {
>>>          (ln -s bash "${initdir}/bin/sh" || :)
>>>      fi
>>>  
>>> +    if dracut_module_included "i18n"; then
>>> +       inst ${moddir}/bashrc /etc/bashrc
>>> +    fi
>>> +
>>
>> maybe only check if bash installed and maybe use /etc/profile to be
>> shell agnostic
>>
>>>      #add common users in /etc/passwd, it will be used by nfs/ssh
>>> currently
>>>      grep '^root:' "$initdir/etc/passwd" 2>/dev/null ||
>>> echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
>>>      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
>>> --

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                             ` <5718D074.70507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-04-21 13:48                                               ` Guido Trentalancia
  2016-04-21 15:03                                               ` Guido Trentalancia
  1 sibling, 0 replies; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-21 13:48 UTC (permalink / raw)
  To: Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

Hello Harald,

thanks for promptly getting back on this.

On Thu, 21/04/2016 at 15.07 +0200, Harald Hoyer wrote:
> On 21.04.2016 14:30, Guido Trentalancia wrote:
> > Hello Harald !
> > 
> > On Thu, 21/04/2016 Guido Trentalancia wrote:
> > > > Compile and install locale definitions using localedef from GNU
> > > > libc or,
> > > > if locale definitions cannot be compiled but are available on
> > > > the
> > > > system
> > > > as split definitions, just install them.
> > > > 
> > > > The resulting locale definitions archive contains at most two
> > > > different
> > > > locale definitions, therefore its size is relatively small.
> > > > 
> > > > Add support for localised messages from core packages
> > > > (LC_MESSAGES).

[...]

> Confirmed, if you add an option to turn the installing of the message
> catalogs off.

Why not ? I was actually thinking the same thing and not just today. I
suppose you mean an option to the main dracut script...

> Also see my other comments in the original reply.

Of course...!

> > > > Add support for non-latin fonts using Unicode (tested
> > > > successfully
> > > > with
> > > > Greek, Hebrew and Cyrillic).
> > > > 
> > > > This revised version fixes several issues in the initial patch
> > > > (including
> > > > the possibility to build locale definitions). Thanks to Andrei
> > > > Borzenkov
> > > > for reviewing the initial patch and providing useful
> > > > suggestions.
> > > > 
> > > > Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> > > > ---
> > > >  modules.d/10i18n/README          |    1
> > > >  modules.d/10i18n/console_init.sh |   24 +++++++++++
> > > >  modules.d/10i18n/module-setup.sh |   82
> > > > +++++++++++++++++++++++++++++++++++++--
> > > >  modules.d/10i18n/parse-i18n.sh   |    8 ++-
> > > >  modules.d/99base/bashrc          |    9 ++++
> > > >  modules.d/99base/init.sh         |    4 +
> > > >  modules.d/99base/module-setup.sh |    4 +
> > > >  7 files changed, 125 insertions(+), 7 deletions(-)
> > > > 
> > > > diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh
> > > > dracut-
> > > > git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/console_init.sh
> > > > --- dracut-git-orig/modules.d/10i18n/console_init.sh	201
> > > > 6-
> > > > 04-20 14:11:02.824944921 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/console_init.sh	2016-04-20
> > > > 14:01:51.452010155 +0200
> > > > @@ -74,6 +74,28 @@ devname=${dev#/dev/}
> > > >      exit 1
> > > >  }
> > > >  
> > > > +shopt -q -s nocasematch
> > > > +if [[ ${UNICODE} ]]
> > > > +then
> > > > +    if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
> > > > +    then
> > > > +        UNICODE=1
> > > > +    elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
> > > > +    then
> > > > +        UNICODE=0
> > > > +    else
> > > > +        UNICODE=''
> > > > +    fi
> > > > +fi
> > > > +if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
> > > > +then
> > > > +    UNICODE=1
> > > > +fi
> > > > +shopt -q -u nocasematch
> > > > +
> > > > +[[ ${UNICODE} == 1 && ${FONT} && ! ${FONT_MAP} ]] && [ -x
> > > > /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
> > > > +[[ ${UNICODE} == 1 && ${FONT} && ${FONT_MAP} ]] && [ -x
> > > > /usr/bin/unicode_start ] && /usr/bin/unicode_start ${FONT}
> > > > ${FONT_MAP}
> > > > +
> > > >  dev_open ${dev}
> > > >  
> > > >  for fd in 6 7; do
> > > > @@ -89,5 +111,7 @@ set_terminal ${dev}
> > > >  set_font ${dev}
> > > >  set_keymap
> > > >  
> > > > +reset
> > > > +

Remark: this reset is needed because of a bug in the font rendering
(triggered by non latin characters) when switching the video resolution
or graphical mode (both standard mode and plymouth/gensplash mode).

I would be very glad to remove this once the underlying bug is removed.
Unfortunately, I cannot even understand what package exactly introduces
this bug... Might be something in the kernel (DRM drivers or some other
graphic card driver).

> > > >  dev_close
> > > 
> > > Please don't use bashisms in initramfs scripts which are not
> > > explicitly marked with "#!/bin/bash".

Fair play.

> > > To test it:
> > > - install "dash"
> > > - run "make syncheck"
> > > - activate the "00dash" dracut module and boot with it

Will do.
 
> > > > diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh
> > > > dracut-
> > > > git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/module-setup.sh
> > > > --- dracut-git-orig/modules.d/10i18n/module-setup.sh	201
> > > > 6-
> > > > 04-20 14:11:02.825944933 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/module-setup.sh	2016-04-20
> > > > 14:44:39.610119250 +0200
> > > > @@ -1,10 +1,15 @@
> > > >  #!/bin/bash
> > > >  
> > > > +# Updated: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> > > > +#
> > > > +#  Added full localisation support (including message-based
> > > > +#  program localisation and support for non-latin charsets)
> > > 
> > > git history should be enough, we don't mention it in the
> > > individual
> > > files

Will remove the comments.

> > > > +
> > > >  # called by dracut
> > > >  check() {
> > > >      [[ "$mount_needs" ]] && return 1
> > > >  
> > > > -    require_binaries setfont loadkeys kbd_mode || return 1
> > > > +    require_binaries setfont loadkeys kbd_mode unicode_start
> > > > stty
> > > > tty tset reset || return 1
> > > >  
> > > >      return 0
> > > >  }
> > > > @@ -26,6 +31,15 @@ install() {
> > > >      DEFAULT_FONT="${i18n_default_font:-LatArCyrHeb-16}"
> > > >      I18N_CONF="/etc/locale.conf"
> > > >      VCONFIG_CONF="/etc/vconsole.conf"
> > > > +    LOCALISED_PACKAGES="libc bash coreutils util-linux
> > > > e2fsprogs
> > > > grep sed kbd cryptsetup"
> > > > +
> > > > +    if dracut_module_included "crypt"; then
> > > > +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} cryptsetup"
> > > > +    fi
> > > > +
> > > > +    if dracut_module_included "crypt-gpg"; then
> > > > +       LOCALISED_PACKAGES="${LOCALISED_PACKAGES} gnupg"
> > > > +    fi
> > > 
> > > I would create a function like "inst_i18n <prog>" which should be
> > > called by the individual dracut modules in their install()
> > > section, rather than hardcoding it here.

I will try to do that too. So, you want the individual modules to
install their own message-based localisation files, instead of having
the installation centralised in i18n...

My original idea, was not to install message-based localisation files
for all modules. So, that's why I decided to tune the thing from there.

But, I agree with you, the suggested approach better respects the
"environment".

> > > >      # This is from 10redhat-i18n.
> > > >      findkeymap () {
> > > > @@ -93,7 +107,7 @@ install() {
> > > >      }
> > > >  
> > > >      install_base() {
> > > > -        inst_multiple setfont loadkeys kbd_mode stty
> > > > +        inst_multiple setfont loadkeys kbd_mode unicode_start
> > > > stty
> > > > tty tset reset
> > > >  
> > > >          if ! dracut_module_included "systemd"; then
> > > >              inst ${moddir}/console_init.sh
> > > > /lib/udev/console_init
> > > > @@ -205,11 +219,73 @@ install() {
> > > >              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
> > > >          fi
> > > >  
> > > > +        [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] &&
> > > > inst_dir
> > > > /usr/lib/locale
> > > > +
> > > > +        # Check if we can compile locale definitions
> > > > +        command -v localedef > /dev/null && HAS_LOCALEDEF=true
> > > > ||
> > > > HAS_LOCALEDEF=false
> > > > +        [ ${LC_ALL} ] && LC_ALL_LOCALE=`echo ${LC_ALL} | awk
> > > > -F.
> > > > '{ print $1 }'` && LC_ALL_CHARMAP=`echo ${LC_ALL} | awk -F. '{
> > > > print $2 }'`
> > > 
> > > awk free version :)
> > > 
> > > $ read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ });
> > > echo
> > > $LC_ALL_LOCALE; echo $LC_ALL_CHARMAP
> > > de_DE
> > > UTF-8

Will test and amend as suggested.

> > > > +        [ ${LANG} ] && LANG_LOCALE=`echo ${LANG} | awk -F. '{
> > > > print $1 }'` && LANG_CHARMAP=`echo ${LANG} | awk -F. '{ print
> > > > $2
> > > > }'`
> > > > +        [ ${LC_MESSAGES} ] && LC_MESSAGES_LOCALE=`echo
> > > > ${LC_MESSAGES} | awk -F. '{ print $1 }'` &&
> > > > LC_MESSAGES_CHARMAP=`echo ${LC_MESSAGES} | awk -F. '{ print $2
> > > > }'`
> > > > +        [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e
> > > > /usr/share/i18n/locales/${LANG_LOCALE} || -e
> > > > /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]] &&
> > > > HAS_LOCALE_SOURCES=true || HAS_LOCALE_SOURCES=false
> > > > +        [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES}
> > > > ==
> > > > true ]] && CAN_BUILD_LOCALE=true || CAN_BUILD_LOCALE=false
> > > > +
> > > > +        # Generate locale definitions for LC_ALL
> > > > +        [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP}
> > > > ]]
> > > > && [ ${CAN_BUILD_LOCALE} == true ] && [ -e
> > > > /usr/share/i18n/locales/${LC_ALL_LOCALE} ] && localedef --
> > > > prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP}
> > > > ${LC_ALL}
> > > > +
> > > > +        # Generate locale definitions for LANG
> > > > +        [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]] &&
> > > > [
> > > > ${CAN_BUILD_LOCALE} == true ] && [ -e
> > > > /usr/share/i18n/locales/${LANG_LOCALE} ] && localedef --
> > > > prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP}
> > > > ${LANG}
> > > > +
> > > > +        # Generate locale definitions for LC_MESSAGES
> > > > +        [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} &&
> > > > ${LC_MESSAGES_CHARMAP} ]] && [ ${CAN_BUILD_LOCALE} == true ] &&
> > > > [
> > > > -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ] && localedef
> > > > --
> > > > prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f
> > > > ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
> > > > +
> > > > +        # If locale definitions cannot be built, but compiled
> > > > split definitions are
> > > > +        # available, then install them
> > > > +        [ ${LC_ALL} ] && [ ${CAN_BUILD_LOCALE} == false ] && [
> > > > -d
> > > > /usr/lib/locale/${LC_ALL} ] && cp -prfL -t
> > > > "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
> > > > +        [ ${LANG} ] && [ ${CAN_BUILD_LOCALE} == false ] && [
> > > > -d
> > > > /usr/lib/locale/${LANG} ] && cp -prfL -t
> > > > "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
> > > > +        [ ${LC_MESSAGES} ] && [ ${CAN_BUILD_LOCALE} == false ]
> > > > &&
> > > > [ -d /usr/lib/locale/${LC_MESSAGES} ] && cp -prfL -t
> > > > "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
> > > 
> > > you really don't like "if ; then; else" :)

I will amend that as well. It was just to save some time, typing it. I
agree if ; then ; else" reads better.

> > > > +
> > > > +        # Install individual localisation files for core
> > > > packages
> > > > +        [ -e /usr/share/locale/locale.alias ] && inst_simple
> > > > /usr/share/locale/locale.alias
> > > > +        [ ${LC_ALL_LOCALE} ] && inst_dir
> > > > /usr/share/locale/${LC_ALL_LOCALE}
> > > > +        [ ${LANG_LOCALE} ] && inst_dir
> > > > /usr/share/locale/${LANG_LOCALE}
> > > > +        [ ${LC_MESSAGES_LOCALE} ] && inst_dir
> > > > /usr/share/locale/${LC_MESSAGES_LOCALE}
> > > > +        [ ${LC_ALL_LOCALE} ] && LC_ALL_LOCALE_SHORT=`echo
> > > > ${LC_ALL_LOCALE} | awk -F_ '{ print $1 }'`
> > > > +        [ ${LANG_LOCALE} ] && LANG_LOCALE_SHORT=`echo
> > > > ${LANG_LOCALE} | awk -F_ '{ print $1 }'`
> > > > +        [ ${LC_MESSAGES_LOCALE} ] &&
> > > > LC_MESSAGES_LOCALE_SHORT=`echo ${LC_MESSAGES_LOCALE} | awk -F_
> > > > '{
> > > > print $1 }'`
> > > 
> > > please don't use backticks... use $() every time

If I can made to work properly without using backticks, I will do that.

> > > > +        [ ${LC_ALL_LOCALE_SHORT} ] && inst_dir
> > > > /usr/share/locale/${LC_ALL_LOCALE_SHORT}
> > > > +        [ ${LANG_LOCALE_SHORT} ] && inst_dir
> > > > /usr/share/locale/${LANG_LOCALE_SHORT}
> > > > +        [ ${LC_MESSAGES_LOCALE_SHORT} ] && inst_dir
> > > > /usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}
> > > > +
> > > > +        locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE}
> > > > ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT}
> > > > ${LANG_LOCALE_SHORT}
> > > > {LC_MESSAGES_LOCALE_SHORT}"
> > > > +        for dir in ${locale_dirs}; do
> > > > +            [ -d /usr/share/locale/${dir} ] && for pkg in
> > > > ${LOCALISED_PACKAGES}; do
> > > > +                for file in `find /usr/share/locale/${dir}
> > > > -type f
> > > > -name "${pkg}.mo"`; do
> > > 
> > > not expected, but this fails for files with spaces in the name

Better safe than sorry, will add double-quotes.

> > > > +                    cp -pfL --parents -t "${initdir}/"
> > > > ${file};
> > > 
> > > what's wrong with "inst_simple" ?

Will amend that.

> > > > +                done
> > > > +            done
> > > > +        done
> > > > +
> > > > +        # Install some of the GNU libc charmap modules
> > > > +        [ -e "${initdir}/lib/ld-linux.so.*" ] && LIBDIR=lib ||
> > > > LIBDIR=lib64
> > > > +        inst_simple /usr/${LIBDIR}/gconv/ISO8859-*.so
> > > > +        [ ${UNICODE} == 1 ] && inst_multiple
> > > > /usr/${LIBDIR}/gconv/UTF-*.so
> > > > +        [ ${UNICODE} == 1 ] && inst_simple
> > > > /usr/${LIBDIR}/gconv/UNICODE.so
> > > 
> > > inst_simple would not install any library deps. better add it to
> > > the
> > > above line
> > > [ ${UNICODE} == 1 ] && inst_multiple
> > > /usr/${LIBDIR}/gconv/UNICODE.so
> > > /usr/${LIBDIR}/gconv/UTF-*.so

Ok, will do.

> > > > +        command -v iconvconfig > /dev/null &&
> > > > HAS_ICONVCONFIG=true
> > > > > > HAS_ICONVCONFIG=false
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ -e
> > > > /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > > > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" |
> > > > grep
> > > > ISO8859- > /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ]
> > > > && [
> > > > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > > > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" |
> > > > grep
> > > > UTF- >> /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ]
> > > > && [
> > > > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > > > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*alias" |
> > > > grep
> > > > UNICODE >> /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ -e
> > > > /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > > > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" |
> > > > grep
> > > > ISO8859- | grep INTERNAL >> /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ]
> > > > && [
> > > > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > > > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" |
> > > > grep
> > > > UTF- | grep INTERNAL >> /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ ${UNICODE} == 1 ]
> > > > && [
> > > > -e /usr/${LIBDIR}/gconv/gconv-modules ] && cat
> > > > /usr/${LIBDIR}/gconv/gconv-modules | grep "^[\t\ ]*module" |
> > > > grep
> > > > UNICODE | grep INTERNAL >> /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && [ -e /tmp/gconv-
> > > > modules
> > > > ] && inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules 
> > > > &&
> > > > rm -f /tmp/gconv-modules
> > > > +        [ ${HAS_ICONVCONFIG} == true ] && iconvconfig --
> > > > prefix="${initdir}"
> > > > +        [ ${HAS_ICONVCONFIG} == false ] && [ -e
> > > > /usr/${LIBDIR}/gconv/gconv-modules.cache ] && inst_simple
> > > > /usr/${LIBDIR}/gconv/gconv-modules.cache
> > > 
> > > why no "if command -v iconvconfig >/dev/null; then ... else ...
> > > fi"
> > > ??

I can do that if you suggest so.

> > > no need for " cat <file> | grep <pattern> " use "grep <pattern>
> > > <file>" directly

Ok.

> > > why grep | grep ?? why not:
> > > 
> > > grep -E "^[[:space:]]*alias.*ISO8859-"
> > > /usr/${LIBDIR}/gconv/gconv-
> > > modules

Yes, sure.

> > > > +
> > > >          if dracut_module_included "systemd" && [[ -f
> > > > ${I18N_CONF}
> > > > ]]; then
> > > >              inst_simple ${I18N_CONF}
> > > >          else
> > > >              mksubdirs ${initdir}${I18N_CONF}
> > > > -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
> > > > +            print_vars LANG LC_ALL LC_MESSAGES >>
> > > > ${initdir}${I18N_CONF}
> > > >          fi
> > > >  
> > > >          if dracut_module_included "systemd" && [[ -f
> > > > ${VCONFIG_CONF} ]]; then
> > > > diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh
> > > > dracut-
> > > > git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/parse-i18n.sh
> > > > --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-
> > > > 04-
> > > > 20 14:11:02.825944933 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/parse-i18n.sh	2016-04-19
> > > > 02:26:46.617644187 +0200
> > > > @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
> > > >  inst_key_val /etc/vconsole.conf UNICODE      1
> > > > rd.vconsole.font.unicode UNICODE vconsole.unicode
> > > >  inst_key_val /etc/vconsole.conf EXT_KEYMAP  ''
> > > > rd.vconsole.keymap.ext   EXT_KEYMAP
> > > >  
> > > > -inst_key_val /etc/locale.conf   LANG        ''
> > > > rd.locale.LANG           LANG
> > > > -inst_key_val /etc/locale.conf   LC_ALL      ''
> > > > rd.locale.LC_ALL         LC_ALL
> > > > -
> > > > +inst_key_val /etc/locale.conf   LANG              ''
> > > > rd.locale.LANG               LANG
> > > > +inst_key_val /etc/locale.conf   LC_ALL            ''
> > > > rd.locale.LC_ALL             LC_ALL
> > > > +inst_key_val /etc/locale.conf   LC_MESSAGES       ''
> > > > rd.locale.LC_MESSAGES        LC_MESSAGES
> > > > + 
> > > >  if [ -f /etc/locale.conf ]; then
> > > >      . /etc/locale.conf
> > > >      export LANG
> > > >      export LC_ALL
> > > > +    export LC_MESSAGES
> > > >  fi
> > > > diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-
> > > > 10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/README
> > > > --- dracut-git-orig/modules.d/10i18n/README	2016-04-20
> > > > 14:11:02.826944946 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/README	2016-04-19
> > > > 02:26:46.617644187 +0200
> > > > @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
> > > >  
> > > >      LANG
> > > >      LC_ALL
> > > > +    LC_MESSAGES
> > > >  
> > > >  If UNICODE variable is not provided, script indicates if UTF-8
> > > > should be
> > > >  used on the basis of LANG value (if it ends with ".utf8" or
> > > > similar).
> > > > diff -pruN dracut-git-orig/modules.d/99base/bashrc dracut-git-
> > > > 10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/99base/bashrc
> > > > --- dracut-git-orig/modules.d/99base/bashrc	1970-01-01
> > > > 01:00:00.000000000 +0100
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/99base/bashrc	2016-04-20
> > > > 14:22:39.804711030 +0200
> > > > @@ -0,0 +1,9 @@
> > > > +# /etc/bashrc
> > > > +
> > > > +# Load locale settings
> > > > +if [ -f /etc/locale.conf ]; then
> > > > +  . /etc/locale.conf
> > > > +  [ -n "${LANG}" ] && export LANG || unset LANG
> > > > +  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
> > > > +  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset
> > > > LC_MESSAGES
> > > > +fi
> > > > diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-
> > > > 10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/99base/init.sh
> > > > --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20
> > > > 14:11:02.826944946 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/99base/init.sh	2016-04-20
> > > > 14:02:01.578137511 +0200
> > > > @@ -8,6 +8,8 @@
> > > >  
> > > >  export -p > /tmp/export.orig
> > > >  
> > > > +[ -f /etc/locale.conf ] && . /etc/locale.conf
> > > > +
> > > >  NEWROOT="/sysroot"
> > > >  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
> > > >  
> > > > @@ -323,7 +325,7 @@ for i in $(export -p); do
> > > >      i=${i%%=*}
> > > >      [ -z "$i" ] && continue
> > > >      case $i in
> > > > -        root|PATH|HOME|TERM|PS4|RD_*)
> > > > +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
> > > >              :;;
> > > >          *)
> > > >              unset "$i";;
> > > > diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh
> > > > dracut-
> > > > git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/99base/module-setup.sh
> > > > --- dracut-git-orig/modules.d/99base/module-setup.sh	201
> > > > 6-
> > > > 04-20 14:11:02.827944958 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/99base/module-setup.sh	2016-04-19
> > > > 02:26:46.619644212 +0200
> > > > @@ -26,6 +26,10 @@ install() {
> > > >          (ln -s bash "${initdir}/bin/sh" || :)
> > > >      fi
> > > >  
> > > > +    if dracut_module_included "i18n"; then
> > > > +       inst ${moddir}/bashrc /etc/bashrc
> > > > +    fi
> > > > +
> > > 
> > > maybe only check if bash installed and maybe use /etc/profile to
> > > be
> > > shell agnostic

Good idea to be shell-agnostic ! But why do you want to skip the check
on the i18n module and use a check on bash ??

I would just change as:

    if dracut_module_included "i18n"; then
       inst ${moddir}/profile /etc/profile
    fi

So that we are shell-agnostic and that's it. Am I missing something ?

> > > >      #add common users in /etc/passwd, it will be used by
> > > > nfs/ssh
> > > > currently
> > > >      grep '^root:' "$initdir/etc/passwd" 2>/dev/null ||
> > > > echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
> > > >      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
> > > > --


Thanks very for the review ! I am going to start working on it shortly...

Regards,

Guido

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                             ` <5718D074.70507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2016-04-21 13:48                                               ` Guido Trentalancia
@ 2016-04-21 15:03                                               ` Guido Trentalancia
  1 sibling, 0 replies; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-21 15:03 UTC (permalink / raw)
  To: Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

On Thu, 21/04/2016 at 15.07 +0200, Harald Hoyer wrote:
> On 21.04.2016 14:30, Guido Trentalancia wrote:
> > Hello Harald !
> > 
> > On Thu, 21/04/2016 Guido Trentalancia wrote:
> > > > Compile and install locale definitions using localedef from GNU
> > > > libc or,
> > > > if locale definitions cannot be compiled but are available on
> > > > the
> > > > system
> > > > as split definitions, just install them.

[...]

> > > > diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh
> > > > dracut-
> > > > git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/module-setup.sh
> > > > --- dracut-git-orig/modules.d/10i18n/module-setup.sh	201
> > > > 6-
> > > > 04-20 14:11:02.825944933 +0200
> > > > +++ dracut-git-10i18n-add-support-for-custom-locale-
> > > > definitions/modules.d/10i18n/module-setup.sh	2016-04-20
> > > > 14:44:39.610119250 +0200
> > > > @@ -1,10 +1,15 @@
> > > >  #!/bin/bash
> > > >  
> > > > +# Updated: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> > > > +#
> > > > +#  Added full localisation support (including message-based
> > > > +#  program localisation and support for non-latin charsets)
> > > 
> > > git history should be enough, we don't mention it in the
> > > individual
> > > files

I just realised this goes in NEWS...

Regards,

Guido

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v8] dracut: add support for custom locale definitions
       [not found]                                     ` <5718AA77.8090600-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
  2016-04-21 12:30                                       ` Guido Trentalancia
@ 2016-04-22 16:13                                       ` Guido Trentalancia
       [not found]                                         ` <1461341618.21231.0.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  1 sibling, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-22 16:13 UTC (permalink / raw)
  To: Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc or,
if locale definitions cannot be compiled but are available on the system
as split definitions, just install them.

The resulting locale definitions archive contains at most two different
locale definitions, therefore its size is relatively small.

Add support for localised messages from core packages (LC_MESSAGES).

Add support for non-latin fonts using Unicode (tested successfully with
Greek, Hebrew and Cyrillic).

This revised version fixes several issues in the initial patch (including
the possibility to build locale definitions). Thanks to Andrei Borzenkov
for reviewing the initial patch and providing useful suggestions.

Thanks for Harald Hoyer for the full style review and other useful
suggestions.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 NEWS                                  |    4
 dracut-bash-completion.sh             |   11 +-
 dracut-init.sh                        |   37 ++++++++
 dracut.8.asc                          |    8 +
 dracut.conf.5.asc                     |   14 ++-
 dracut.sh                             |   20 +++-
 modules.d/10i18n/README               |    1
 modules.d/10i18n/console_init.sh      |   58 +++++++++-----
 modules.d/10i18n/module-setup.sh      |  140 +++++++++++++++++++++++++++++++++-
 modules.d/10i18n/parse-i18n.sh        |    8 +
 modules.d/90crypt/module-setup.sh     |    4
 modules.d/91crypt-gpg/module-setup.sh |    4
 modules.d/99base/init.sh              |    4
 modules.d/99base/module-setup.sh      |    4
 14 files changed, 279 insertions(+), 38 deletions(-)

diff -pru dracut-git-orig/dracut.8.asc dracut-git-10i18n-full-support-for-localisation/dracut.8.asc
--- dracut-git-orig/dracut.8.asc	2016-04-19 02:19:10.650042399 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut.8.asc	2016-04-21 17:13:53.043188284 +0200
@@ -358,6 +358,14 @@ provide a valid _/etc/fstab_.
     LVM or an encrypted partition.
     [NB --device can be used for compatibility with earlier releases]
 
+**--msg-localisation**::
+    Include full localisation support for the i18n module (slightly increases
+    the initramfs size).
+
+**--no-msg-localisation**::
+    Do not include full localisation support for the i18n module (to save
+    storage space or force the default locale).
+
 **-i, --include** _<SOURCE>_ _<TARGET>_::
     include the files in the SOURCE directory into the
     TARGET directory in the final initramfs. If SOURCE is a file, it will be
diff -pru dracut-git-orig/dracut-bash-completion.sh dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh
--- dracut-git-orig/dracut-bash-completion.sh	2016-04-19 02:19:10.648042373 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh	2016-04-21 17:16:41.148400079 +0200
@@ -28,11 +28,12 @@ _dracut() {
                               --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
                               --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
                               --lvmconf --nolvmconf --debug --profile --verbose --quiet
-                              --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
-                              --xz --no-compress --gzip --list-modules --show-modules --keep
-                              --printsize --regenerate-all --noimageifnotneeded --early-microcode
-                              --no-early-microcode --print-cmdline --prelink --noprelink --reproducible
-                              --uefi
+                              --local --hostonly --no-hostonly --fstab --msg-localisation
+                              --no-msg-localisation --help --bzip2 --lzma --xz --no-compress
+                              --gzip --list-modules --show-modules --keep --printsize
+                              --regenerate-all --noimageifnotneeded --early-microcode
+                              --no-early-microcode --print-cmdline --prelink --noprelink
+                              --reproducible --uefi
                               '
 
                        [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
diff -pru dracut-git-orig/dracut.conf.5.asc dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc
--- dracut-git-orig/dracut.conf.5.asc	2016-04-19 02:19:10.650042399 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc	2016-04-21 17:21:57.576555027 +0200
@@ -99,9 +99,6 @@ Configuration files must have the extens
 *hostonly_cmdline=*"__{yes|no}__"::
     If set, store the kernel command line arguments needed in the initramfs
 
-*i18n_install_all=*"__{yes|no}__"::
-    If set to yes, install all available fonts and keyboard files.
-
 *persistent_policy=*"__<policy>__"::
     Use _<policy>_ to address disks and partitions.
     _<policy>_ can be any directory name found in /dev/disk.
@@ -196,7 +193,16 @@ provide a valid _/etc/fstab_.
     Default is "LatArCyrHeb-16".
 
 *i18n_install_all=*"__{yes|no}__"::
-    Install everything regardless of generic or hostonly mode.
+    Install all available fonts and keyboard files regardless of generic
+    or hostonly mode.
+
+*msg-localisation=*"__{yes|no}__"::
+    Add full localisation support (includes message-based localisation
+    and non latin font support).
+
+*no-msg-localisation=*"__{yes|no}__"::
+    Do not add full localisation support (only keyboard localisation
+    is added): saves some storage space.
 
 *reproducible=*"__{yes|no}__"::
     Create reproducible images.
diff -pru dracut-git-orig/dracut-init.sh dracut-git-10i18n-full-support-for-localisation/dracut-init.sh
--- dracut-git-orig/dracut-init.sh	2016-04-19 02:19:10.649042386 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut-init.sh	2016-04-22 18:05:08.033519479 +0200
@@ -214,6 +214,43 @@ inst_multiple() {
     return $_ret
 }
 
+# Install package translations (message-based localisations)
+inst_i18n() {
+    local _locale_dirs_dup
+    local _locale_dirs
+    local _tmppath
+    [[ $1 ]] || return 1  # no package name
+    [ -f /etc/locale.conf ] && . /etc/locale.conf
+    if [ ${LC_ALL} ]; then
+        read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
+    fi
+    if [ ${LANG} ]; then
+        read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
+    fi
+    if [ ${LC_MESSAGES} ]; then
+        read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
+    fi
+    [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
+    [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
+    [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
+    _locale_dirs_dup="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} ${LC_MESSAGES_LOCALE_SHORT}"
+    _tmppath=
+    _locale_dirs=
+    for dir in ${_locale_dirs_dup}
+    do
+        case $_tmppath in
+            *\ ${dir}) ;;
+            *) _locale_dirs="${_tmppath} ${dir}";;
+        esac
+        _tmppath=${_locale_dirs}
+    done
+    for dir in ${_locale_dirs}; do
+        [[ -d "/usr/share/locale/${dir}" ]] && for file in `find "/usr/share/locale/${dir}" -type f -name "$1.mo"`; do
+            inst_simple "${file}"
+        done
+    done
+}
+
 dracut_install() {
     inst_multiple "$@"
 }
diff -pru dracut-git-orig/dracut.sh dracut-git-10i18n-full-support-for-localisation/dracut.sh
--- dracut-git-orig/dracut.sh	2016-04-19 02:19:10.652042425 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut.sh	2016-04-21 23:06:34.022740183 +0200
@@ -163,6 +163,10 @@ Creates initial ramdisk images for prelo
   --mount "[MP]"	Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
 			determined by looking at the current mounts.
   --add-device "[DEV]"  Bring up [DEV] in initramfs
+  --msg-localisation    Add full localisation support rather than only
+                        the minimal keyboard support (default)
+  --no-msg-localisation Do not add full localisation support, but only
+                        minimal keyboard support
   -i, --include [SOURCE] [TARGET]
                         Include the files in the SOURCE directory into the
                          Target directory in the final initramfs.
@@ -344,6 +348,8 @@ rearrange_params()
         --long no-hostonly-cmdline \
         --long persistent-policy: \
         --long fstab \
+        --long msg-localisation \
+        --long no-msg-localisation \
         --long help \
         --long bzip2 \
         --long lzma \
@@ -538,6 +544,10 @@ while :; do
         --persistent-policy)
                        persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
         --fstab)       use_fstab_l="yes" ;;
+        --msg-localisation)
+                       msg_localisation_l="yes" ;;
+        --no-msg-localisation)
+                       msg_localisation_l="no" ;;
         -h|--help)     long_usage; exit 1 ;;
         -i|--include)  include_src+=("$2");          PARMS_TO_STORE+=" '$2'";
                        shift;;
@@ -730,6 +740,8 @@ stdloglvl=$((stdloglvl + verbosity_mod_l
 [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
+[[ $msg_localisation_l ]] && msg_localisation=$msg_localisation_l
+[[ $msg_localisation_l ]] || msg_localisation="yes"
 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
@@ -1269,10 +1281,10 @@ export initdir dracutbasedir \
     mods_to_load \
     fw_dir drivers_dir debug no_kernel kernel_only \
     omit_drivers mdadmconf lvmconf root_dev \
-    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
-    stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
-    debug host_fs_types host_devs swap_devs sshkey add_fstab \
-    DRACUT_VERSION udevdir prefix filesystems drivers \
+    use_fstab fstab_lines msg_localisation libdirs fscks \
+    nofscks ro_mnt stdloglvl sysloglvl fileloglvl kmsgloglvl \
+    logile debug host_fs_types host_devs swap_devs sshkey \
+    add_fstab DRACUT_VERSION udevdir prefix filesystems drivers \
     systemdutildir systemdsystemunitdir systemdsystemconfdir \
     hostonly_cmdline loginstall \
     tmpfilesdir
diff -pru dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh
--- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-20 14:11:02.824944921 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh	2016-04-22 17:54:50.913345284 +0200
@@ -6,6 +6,7 @@ if [ -x $systemdutildir/systemd-vconsole
     $systemdutildir/systemd-vconsole-setup "$@"
 fi
 
+[ -e /etc/locale.conf ] && . /etc/locale.conf
 [ -e /etc/vconsole.conf ] && . /etc/vconsole.conf
 
 DEFAULT_FONT=LatArCyrHeb-16
@@ -19,14 +20,14 @@ set_keyboard() {
 }
 
 set_terminal() {
-    local dev=$1
-
     if [ "${UNICODE}" = 1 ]; then
-        printf '\033%%G' >&7
-        stty -F ${dev} iutf8
+        if [ "${FONT}" -a ! "${FONT_MAP}" ]; then
+            /usr/bin/unicode_start "${FONT}"
+        elif [ "${FONT}" -a "${FONT_MAP}" ]; then
+            /usr/bin/unicode_start "${FONT}" "${FONT_MAP}"
+        fi
     else
-        printf '\033%%@' >&7
-        stty -F ${dev} -iutf8
+        /usr/bin/unicode_stop
     fi
 }
 
@@ -44,16 +45,6 @@ set_keymap() {
     loadkeys -q ${utf_switch} ${KEYMAP} ${EXT_KEYMAPS}
 }
 
-set_font() {
-    local dev=$1; local trans=''; local uni=''
-
-    [ -z "${FONT}" ] && FONT=${DEFAULT_FONT}
-    [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}"
-    [ -n "${FONT_UNIMAP}" ] && uni="-u ${FONT_UNIMAP}"
-
-    setfont ${FONT} -C ${dev} ${trans} ${uni}
-}
-
 dev_close() {
     exec 6>&-
     exec 7>&-
@@ -74,6 +65,27 @@ devname=${dev#/dev/}
     exit 1
 }
 
+if [ "${UNICODE}" ]; then
+    if [ "${UNICODE}" = YES -o "${UNICODE}" = yes -o "${UNICODE}" = 1 ]; then
+        UNICODE=1
+    elif [ "${UNICODE}" = NO -o "${UNICODE}" = no -o "${UNICODE}" = 0 ]; then
+        UNICODE=0
+    else
+        UNICODE=''
+    fi
+fi
+if [ ! "${UNICODE}" ]; then
+    IFS=.
+    set -- $LANG
+    tail=$2
+    IFS=-
+    set -- $tail
+    type=$1
+    if [ "${type}" = "UTF" ]; then
+        UNICODE=1
+    fi
+fi
+
 dev_open ${dev}
 
 for fd in 6 7; do
@@ -84,9 +96,19 @@ for fd in 6 7; do
     fi
 done
 
+# Immediately after booting up, the
+# display driver needs to settle,
+# otherwise the Unicode mode cannot
+# be enabled and the non latin
+# characters do not render properly.
+if [ -d /usr/share/locale ]; then
+    if [ ! -e /tmp/dracut-vga-init-complete ]; then
+        sleep 2 && :> /tmp/dracut-vga-init-complete
+    fi
+fi
+
 set_keyboard
-set_terminal ${dev}
-set_font ${dev}
+set_terminal
 set_keymap
 
 dev_close
diff -pru dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh
--- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-22 14:25:26.949983919 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh	2016-04-22 15:42:18.988741282 +0200
@@ -4,7 +4,11 @@
 check() {
     [[ "$mount_needs" ]] && return 1
 
-    require_binaries setfont loadkeys kbd_mode || return 1
+    if [[ $msg_localisation == "yes" ]]; then
+        require_binaries setfont loadkeys kbd_mode unicode_start unicode_stop stty tty tset reset sleep || return 1
+    else
+        require_binaries setfont loadkeys kbd_mode unicode_start unicode_stop || return 1
+    fi
 
     return 0
 }
@@ -27,6 +31,11 @@ install() {
     I18N_CONF="/etc/locale.conf"
     VCONFIG_CONF="/etc/vconsole.conf"
 
+    # Core packages: always install the message-based localisation
+    if [[ $msg_localisation == "yes" ]]; then
+        CORE_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd"
+    fi
+
     # This is from 10redhat-i18n.
     findkeymap () {
         local MAP=$1
@@ -93,7 +102,11 @@ install() {
     }
 
     install_base() {
-        inst_multiple setfont loadkeys kbd_mode stty
+        if [[ $msg_localisation == "yes" ]]; then
+            inst_multiple setfont loadkeys kbd_mode unicode_start unicode_stop stty tty tset reset sleep
+        else
+            inst_multiple setfont loadkeys kbd_mode unicode_start unicode_stop
+        fi
 
         if ! dracut_module_included "systemd"; then
             inst ${moddir}/console_init.sh /lib/udev/console_init
@@ -212,11 +225,132 @@ install() {
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
         fi
 
+        if [[ $msg_localisation == "yes" ]]; then
+            [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
+
+            # Check if we can compile locale definitions
+            command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
+            if [ ${LC_ALL} ]; then
+                read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
+            fi
+            if [ ${LANG} ]; then
+                read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
+            fi
+            if [ ${LC_MESSAGES} ]; then
+                read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
+            fi
+            if [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e /usr/share/i18n/locales/${LANG_LOCALE} || -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]]; then
+                HAS_LOCALE_SOURCES=true
+            else
+                HAS_LOCALE_SOURCES=false
+            fi
+            if [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]]; then
+                CAN_BUILD_LOCALE=true
+            else
+                CAN_BUILD_LOCALE=false
+            fi
+
+            # Generate locale definitions for LC_ALL
+            if [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]]; then
+                if [ ${CAN_BUILD_LOCALE} == true ]; then
+                    if [ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ]; then
+                        localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+                    fi
+                fi
+            fi
+
+            # Generate locale definitions for LANG
+            if [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]]; then
+                if [ ${CAN_BUILD_LOCALE} == true ]; then
+                    if [ -e /usr/share/i18n/locales/${LANG_LOCALE} ]; then
+                        localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+                    fi
+                fi
+            fi
+
+            # Generate locale definitions for LC_MESSAGES
+            if [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]]; then
+                if [ ${CAN_BUILD_LOCALE} == true ]; then
+                    if [ -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]; then
+                        localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
+                    fi
+                fi
+            fi
+
+            # If locale definitions cannot be built, but compiled split definitions are
+            # available, then install them
+            if [ ${CAN_BUILD_LOCALE} == false ]; then
+                if [[ ${LC_ALL} && -d /usr/lib/locale/${LC_ALL} ]]; then
+                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+                fi
+                if [[ ${LANG} && -d /usr/lib/locale/${LANG} ]]; then
+                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+                fi
+                if [[ ${LC_MESSAGES} && -d /usr/lib/locale/${LC_MESSAGES} ]]; then
+                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
+                fi
+            fi
+
+            # Install individual localisation files for core packages
+            [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
+            [[ ${LC_ALL_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE}"
+            [[ ${LANG_LOCALE} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE}"
+            [[ ${LC_MESSAGES_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE}"
+            [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
+            [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
+            [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
+            [[ ${LC_ALL_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE_SHORT}"
+            [[ ${LANG_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE_SHORT}"
+            [[ ${LC_MESSAGES_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}"
+
+            locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
+            for dir in ${locale_dirs}; do
+                [ -d "/usr/share/locale/${dir}" ] && for pkg in ${CORE_PACKAGES}; do
+                    for file in `find "/usr/share/locale/${dir}" -type f -name "${pkg}.mo"`; do
+                        inst_simple "${file}"
+                    done
+                done
+            done
+
+            # Install ISO-8859 and Unicode charmap modules from GNU libc
+            if [ -e "${initdir}/lib/ld-linux.so.*" ]; then
+                LIBDIR=lib
+            else
+                LIBDIR=lib64
+            fi
+            inst_multiple /usr/${LIBDIR}/gconv/ISO8859-*.so
+            if [ ${UNICODE} == 1 ]; then
+                inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so /usr/${LIBDIR}/gconv/UNICODE.so
+            fi
+            if command -v iconvconfig > /dev/null; then
+                if [ -e /usr/${LIBDIR}/gconv/gconv-modules ]; then
+                    grep -E "^[[:space:]]*alias[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules > /tmp/gconv-modules
+                    if [ ${UNICODE} == 1 ]; then
+                        grep -E "^[[:space:]]*alias.*UTF-" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
+                        grep -E "^[[:space:]]*alias.*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
+                    fi
+                    grep -E "^[[:space:]]*module[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
+                    if [ ${UNICODE} == 1 ]; then
+                        grep -E "^[[:space:]]*module[[:space:]]*UTF-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
+                        grep -E "^[[:space:]]*module[[:space:]]*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
+                    fi
+                    if [ -e /tmp/gconv-modules ]; then
+                        inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
+                    fi
+                fi
+                iconvconfig --prefix="${initdir}"
+            else
+                if [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ]; then
+                    inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache
+                fi
+            fi
+        fi
+
         if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
             inst_simple ${I18N_CONF}
         else
             mksubdirs ${initdir}${I18N_CONF}
-            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
+            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
         fi
 
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
diff -pru dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh
--- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-20 14:11:02.825944933 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
@@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
 inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
 inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
 
-inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
-inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
-
+inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
+inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
+inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
+ 
 if [ -f /etc/locale.conf ]; then
     . /etc/locale.conf
     export LANG
     export LC_ALL
+    export LC_MESSAGES
 fi
diff -pru dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README
--- dracut-git-orig/modules.d/10i18n/README	2016-04-20 14:11:02.826944946 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
@@ -65,6 +65,7 @@ I'm leaving it in case...  The following
 
     LANG
     LC_ALL
+    LC_MESSAGES
 
 If UNICODE variable is not provided, script indicates if UTF-8 should be
 used on the basis of LANG value (if it ends with ".utf8" or similar).
diff -pru dracut-git-orig/modules.d/90crypt/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh
--- dracut-git-orig/modules.d/90crypt/module-setup.sh	2016-04-19 02:19:10.662042554 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh	2016-04-21 22:26:38.113859320 +0200
@@ -88,6 +88,10 @@ install() {
 
     inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh"
 
+    if [[ $msg_localisation == "yes" ]]; then
+        inst_i18n cryptsetup
+    fi
+
     if dracut_module_included "systemd"; then
         inst_multiple -o \
                       $systemdutildir/system-generators/systemd-cryptsetup-generator \
diff -pru dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh
--- dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh	2016-04-19 02:19:10.667042618 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh	2016-04-22 18:06:54.504926340 +0200
@@ -17,4 +17,8 @@ depends() {
 install() {
     inst_multiple gpg
     inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
+
+    if [[ $msg_localisation == "yes" ]]; then
+        inst_i18n gnupg
+    fi
 }
diff -pru dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh
--- dracut-git-orig/modules.d/99base/init.sh	2016-04-20 14:11:02.826944946 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh	2016-04-20 14:02:01.578137511 +0200
@@ -8,6 +8,8 @@
 
 export -p > /tmp/export.orig
 
+[ -f /etc/locale.conf ] && . /etc/locale.conf
+
 NEWROOT="/sysroot"
 [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
 
@@ -323,7 +325,7 @@ for i in $(export -p); do
     i=${i%%=*}
     [ -z "$i" ] && continue
     case $i in
-        root|PATH|HOME|TERM|PS4|RD_*)
+        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
             :;;
         *)
             unset "$i";;
diff -pru dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh
--- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-20 14:11:02.827944958 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh	2016-04-21 20:01:54.611592039 +0200
@@ -26,6 +26,10 @@ install() {
         (ln -s bash "${initdir}/bin/sh" || :)
     fi
 
+    if dracut_module_included "i18n"; then
+       inst ${moddir}/profile /etc/profile
+    fi
+
     #add common users in /etc/passwd, it will be used by nfs/ssh currently
     grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
     grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
Μόνο στο dracut-git-10i18n-full-support-for-localisation/modules.d/99base: profile
diff -pru dracut-git-orig/NEWS dracut-git-10i18n-full-support-for-localisation/NEWS
--- dracut-git-orig/NEWS	2016-04-19 02:19:10.648042373 +0200
+++ dracut-git-10i18n-full-support-for-localisation/NEWS	2016-04-21 17:00:46.436792093 +0200
@@ -6,6 +6,7 @@ dracut now requires libkmod for the drac
 dracut.sh:
 - restorecon final image file
 - fail hard, if we find modules and modules.dep is missing
+- add an option to disable the new full localisation support
 
 dracut-functions.sh:
 - fix check_vol_slaves() volume group name stripping
@@ -34,6 +35,9 @@ general initramfs fixes:
 - call dracut-cmdline-ask.service, if /etc/cmdline.d/*.conf exists
 - break at switch_root only for bare rd.break
 
+i18n:
+- add full localisation support (includes message-based localisation)
+
 dmsquash-live:
 - fixed livenet-generator execution flag
   and include only, if systemd is used

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v8] dracut: add support for custom locale definitions
       [not found]                                         ` <1461341618.21231.0.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-04-23  7:50                                           ` Andrei Borzenkov
       [not found]                                             ` <571B2950.5060209-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2016-04-23 16:50                                           ` [PATCH v9] " Guido Trentalancia
  1 sibling, 1 reply; 24+ messages in thread
From: Andrei Borzenkov @ 2016-04-23  7:50 UTC (permalink / raw)
  To: Guido Trentalancia, Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

22.04.2016 19:13, Guido Trentalancia пишет:
> Compile and install locale definitions using localedef from GNU libc or,
> if locale definitions cannot be compiled but are available on the system
> as split definitions, just install them.
> 
> The resulting locale definitions archive contains at most two different
> locale definitions, therefore its size is relatively small.
> 
> Add support for localised messages from core packages (LC_MESSAGES).
> 
> Add support for non-latin fonts using Unicode (tested successfully with
> Greek, Hebrew and Cyrillic).
> 
> This revised version fixes several issues in the initial patch (including
> the possibility to build locale definitions). Thanks to Andrei Borzenkov
> for reviewing the initial patch and providing useful suggestions.
> 
> Thanks for Harald Hoyer for the full style review and other useful
> suggestions.
> 
> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> ---
>  NEWS                                  |    4
>  dracut-bash-completion.sh             |   11 +-
>  dracut-init.sh                        |   37 ++++++++
>  dracut.8.asc                          |    8 +
>  dracut.conf.5.asc                     |   14 ++-
>  dracut.sh                             |   20 +++-
>  modules.d/10i18n/README               |    1
>  modules.d/10i18n/console_init.sh      |   58 +++++++++-----
>  modules.d/10i18n/module-setup.sh      |  140 +++++++++++++++++++++++++++++++++-
>  modules.d/10i18n/parse-i18n.sh        |    8 +
>  modules.d/90crypt/module-setup.sh     |    4
>  modules.d/91crypt-gpg/module-setup.sh |    4
>  modules.d/99base/init.sh              |    4
>  modules.d/99base/module-setup.sh      |    4
>  14 files changed, 279 insertions(+), 38 deletions(-)
> 
> diff -pru dracut-git-orig/dracut.8.asc dracut-git-10i18n-full-support-for-localisation/dracut.8.asc
> --- dracut-git-orig/dracut.8.asc	2016-04-19 02:19:10.650042399 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut.8.asc	2016-04-21 17:13:53.043188284 +0200
> @@ -358,6 +358,14 @@ provide a valid _/etc/fstab_.
>      LVM or an encrypted partition.
>      [NB --device can be used for compatibility with earlier releases]
>  
> +**--msg-localisation**::
> +    Include full localisation support for the i18n module (slightly increases
> +    the initramfs size).
> +

It is not "full" in any case. You only install message catalogs for
selected compnents.

> +**--no-msg-localisation**::
> +    Do not include full localisation support for the i18n module (to save
> +    storage space or force the default locale).
> +
>  **-i, --include** _<SOURCE>_ _<TARGET>_::
>      include the files in the SOURCE directory into the
>      TARGET directory in the final initramfs. If SOURCE is a file, it will be
> diff -pru dracut-git-orig/dracut-bash-completion.sh dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh
> --- dracut-git-orig/dracut-bash-completion.sh	2016-04-19 02:19:10.648042373 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh	2016-04-21 17:16:41.148400079 +0200
> @@ -28,11 +28,12 @@ _dracut() {
>                                --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
>                                --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
>                                --lvmconf --nolvmconf --debug --profile --verbose --quiet
> -                              --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
> -                              --xz --no-compress --gzip --list-modules --show-modules --keep
> -                              --printsize --regenerate-all --noimageifnotneeded --early-microcode
> -                              --no-early-microcode --print-cmdline --prelink --noprelink --reproducible
> -                              --uefi
> +                              --local --hostonly --no-hostonly --fstab --msg-localisation
> +                              --no-msg-localisation --help --bzip2 --lzma --xz --no-compress
> +                              --gzip --list-modules --show-modules --keep --printsize
> +                              --regenerate-all --noimageifnotneeded --early-microcode
> +                              --no-early-microcode --print-cmdline --prelink --noprelink
> +                              --reproducible --uefi
>                                '
>  
>                         [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
> diff -pru dracut-git-orig/dracut.conf.5.asc dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc
> --- dracut-git-orig/dracut.conf.5.asc	2016-04-19 02:19:10.650042399 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc	2016-04-21 17:21:57.576555027 +0200
> @@ -99,9 +99,6 @@ Configuration files must have the extens
>  *hostonly_cmdline=*"__{yes|no}__"::
>      If set, store the kernel command line arguments needed in the initramfs
>  
> -*i18n_install_all=*"__{yes|no}__"::
> -    If set to yes, install all available fonts and keyboard files.
> -
>  *persistent_policy=*"__<policy>__"::
>      Use _<policy>_ to address disks and partitions.
>      _<policy>_ can be any directory name found in /dev/disk.
> @@ -196,7 +193,16 @@ provide a valid _/etc/fstab_.
>      Default is "LatArCyrHeb-16".
>  
>  *i18n_install_all=*"__{yes|no}__"::
> -    Install everything regardless of generic or hostonly mode.
> +    Install all available fonts and keyboard files regardless of generic
> +    or hostonly mode.
> +
> +*msg-localisation=*"__{yes|no}__"::
> +    Add full localisation support (includes message-based localisation
> +    and non latin font support).
> +

Are not fonts always installed? I do not see any dependency on this
setings for fonts installation.

> +*no-msg-localisation=*"__{yes|no}__"::
> +    Do not add full localisation support (only keyboard localisation
> +    is added): saves some storage space.
>  
>  *reproducible=*"__{yes|no}__"::
>      Create reproducible images.
> diff -pru dracut-git-orig/dracut-init.sh dracut-git-10i18n-full-support-for-localisation/dracut-init.sh
> --- dracut-git-orig/dracut-init.sh	2016-04-19 02:19:10.649042386 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut-init.sh	2016-04-22 18:05:08.033519479 +0200
> @@ -214,6 +214,43 @@ inst_multiple() {
>      return $_ret
>  }
>  
> +# Install package translations (message-based localisations)
> +inst_i18n() {

l10n is more common abbreviation for message translations. i18n usually
refers to ability to process non-ASCII characters.

> +    local _locale_dirs_dup
> +    local _locale_dirs
> +    local _tmppath
> +    [[ $1 ]] || return 1  # no package name
> +    [ -f /etc/locale.conf ] && . /etc/locale.conf
> +    if [ ${LC_ALL} ]; then
> +        read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
> +    fi
> +    if [ ${LANG} ]; then
> +        read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
> +    fi
> +    if [ ${LC_MESSAGES} ]; then
> +        read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
> +    fi
> +    [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
> +    [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
> +    [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
> +    _locale_dirs_dup="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} ${LC_MESSAGES_LOCALE_SHORT}"
> +    _tmppath=
> +    _locale_dirs=
> +    for dir in ${_locale_dirs_dup}
> +    do
> +        case $_tmppath in
> +            *\ ${dir}) ;;
> +            *) _locale_dirs="${_tmppath} ${dir}";;
> +        esac
> +        _tmppath=${_locale_dirs}
> +    done
> +    for dir in ${_locale_dirs}; do
> +        [[ -d "/usr/share/locale/${dir}" ]] && for file in `find "/usr/share/locale/${dir}" -type f -name "$1.mo"`; do
> +            inst_simple "${file}"
> +        done
> +    done
> +}
> +
>  dracut_install() {
>      inst_multiple "$@"
>  }
> diff -pru dracut-git-orig/dracut.sh dracut-git-10i18n-full-support-for-localisation/dracut.sh
> --- dracut-git-orig/dracut.sh	2016-04-19 02:19:10.652042425 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut.sh	2016-04-21 23:06:34.022740183 +0200
> @@ -163,6 +163,10 @@ Creates initial ramdisk images for prelo
>    --mount "[MP]"	Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
>  			determined by looking at the current mounts.
>    --add-device "[DEV]"  Bring up [DEV] in initramfs
> +  --msg-localisation    Add full localisation support rather than only
> +                        the minimal keyboard support (default)
> +  --no-msg-localisation Do not add full localisation support, but only
> +                        minimal keyboard support
>    -i, --include [SOURCE] [TARGET]
>                          Include the files in the SOURCE directory into the
>                           Target directory in the final initramfs.
> @@ -344,6 +348,8 @@ rearrange_params()
>          --long no-hostonly-cmdline \
>          --long persistent-policy: \
>          --long fstab \
> +        --long msg-localisation \
> +        --long no-msg-localisation \
>          --long help \
>          --long bzip2 \
>          --long lzma \
> @@ -538,6 +544,10 @@ while :; do
>          --persistent-policy)
>                         persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
>          --fstab)       use_fstab_l="yes" ;;
> +        --msg-localisation)
> +                       msg_localisation_l="yes" ;;
> +        --no-msg-localisation)
> +                       msg_localisation_l="no" ;;
>          -h|--help)     long_usage; exit 1 ;;
>          -i|--include)  include_src+=("$2");          PARMS_TO_STORE+=" '$2'";
>                         shift;;
> @@ -730,6 +740,8 @@ stdloglvl=$((stdloglvl + verbosity_mod_l
>  [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
>  [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
>  [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
> +[[ $msg_localisation_l ]] && msg_localisation=$msg_localisation_l
> +[[ $msg_localisation_l ]] || msg_localisation="yes"
>  [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
>  [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
>  [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
> @@ -1269,10 +1281,10 @@ export initdir dracutbasedir \
>      mods_to_load \
>      fw_dir drivers_dir debug no_kernel kernel_only \
>      omit_drivers mdadmconf lvmconf root_dev \
> -    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
> -    stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
> -    debug host_fs_types host_devs swap_devs sshkey add_fstab \
> -    DRACUT_VERSION udevdir prefix filesystems drivers \
> +    use_fstab fstab_lines msg_localisation libdirs fscks \
> +    nofscks ro_mnt stdloglvl sysloglvl fileloglvl kmsgloglvl \
> +    logile debug host_fs_types host_devs swap_devs sshkey \
> +    add_fstab DRACUT_VERSION udevdir prefix filesystems drivers \
>      systemdutildir systemdsystemunitdir systemdsystemconfdir \
>      hostonly_cmdline loginstall \
>      tmpfilesdir
> diff -pru dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh
> --- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-20 14:11:02.824944921 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh	2016-04-22 17:54:50.913345284 +0200
> @@ -6,6 +6,7 @@ if [ -x $systemdutildir/systemd-vconsole
>      $systemdutildir/systemd-vconsole-setup "$@"
>  fi
>  
> +[ -e /etc/locale.conf ] && . /etc/locale.conf
>  [ -e /etc/vconsole.conf ] && . /etc/vconsole.conf
>  
>  DEFAULT_FONT=LatArCyrHeb-16
> @@ -19,14 +20,14 @@ set_keyboard() {
>  }
>  
>  set_terminal() {
> -    local dev=$1
> -
>      if [ "${UNICODE}" = 1 ]; then
> -        printf '\033%%G' >&7
> -        stty -F ${dev} iutf8
> +        if [ "${FONT}" -a ! "${FONT_MAP}" ]; then
> +            /usr/bin/unicode_start "${FONT}"
> +        elif [ "${FONT}" -a "${FONT_MAP}" ]; then
> +            /usr/bin/unicode_start "${FONT}" "${FONT_MAP}"
> +        fi
>      else
> -        printf '\033%%@' >&7
> -        stty -F ${dev} -iutf8
> +        /usr/bin/unicode_stop
>      fi
>  }
>  
> @@ -44,16 +45,6 @@ set_keymap() {
>      loadkeys -q ${utf_switch} ${KEYMAP} ${EXT_KEYMAPS}
>  }
>  
> -set_font() {
> -    local dev=$1; local trans=''; local uni=''
> -
> -    [ -z "${FONT}" ] && FONT=${DEFAULT_FONT}
> -    [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}"
> -    [ -n "${FONT_UNIMAP}" ] && uni="-u ${FONT_UNIMAP}"
> -
> -    setfont ${FONT} -C ${dev} ${trans} ${uni}
> -}
> -
>  dev_close() {
>      exec 6>&-
>      exec 7>&-
> @@ -74,6 +65,27 @@ devname=${dev#/dev/}
>      exit 1
>  }
>  
> +if [ "${UNICODE}" ]; then
> +    if [ "${UNICODE}" = YES -o "${UNICODE}" = yes -o "${UNICODE}" = 1 ]; then
> +        UNICODE=1
> +    elif [ "${UNICODE}" = NO -o "${UNICODE}" = no -o "${UNICODE}" = 0 ]; then
> +        UNICODE=0
> +    else
> +        UNICODE=''
> +    fi
> +fi
> +if [ ! "${UNICODE}" ]; then
> +    IFS=.
> +    set -- $LANG
> +    tail=$2
> +    IFS=-
> +    set -- $tail
> +    type=$1
> +    if [ "${type}" = "UTF" ]; then
> +        UNICODE=1
> +    fi

What about LANG=en_US.utf8? You probably want "locale charmap" here.

> +fi
> +
>  dev_open ${dev}
>  
>  for fd in 6 7; do
> @@ -84,9 +96,19 @@ for fd in 6 7; do
>      fi
>  done
>  
> +# Immediately after booting up, the
> +# display driver needs to settle,
> +# otherwise the Unicode mode cannot
> +# be enabled and the non latin
> +# characters do not render properly.
> +if [ -d /usr/share/locale ]; then
> +    if [ ! -e /tmp/dracut-vga-init-complete ]; then
> +        sleep 2 && :> /tmp/dracut-vga-init-complete
> +    fi
> +fi
> +
>  set_keyboard
> -set_terminal ${dev}
> -set_font ${dev}
> +set_terminal
>  set_keymap
>  
>  dev_close
> diff -pru dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh
> --- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-22 14:25:26.949983919 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh	2016-04-22 15:42:18.988741282 +0200
> @@ -4,7 +4,11 @@
>  check() {
>      [[ "$mount_needs" ]] && return 1
>  
> -    require_binaries setfont loadkeys kbd_mode || return 1
> +    if [[ $msg_localisation == "yes" ]]; then
> +        require_binaries setfont loadkeys kbd_mode unicode_start unicode_stop stty tty tset reset sleep || return 1
> +    else
> +        require_binaries setfont loadkeys kbd_mode unicode_start unicode_stop || return 1
> +    fi
>  

Well, you should move common stuff that is always required outside of
"if". As soon as you need to modify the same item in two places, you are
bound to make mistakes.

>      return 0
>  }
> @@ -27,6 +31,11 @@ install() {
>      I18N_CONF="/etc/locale.conf"
>      VCONFIG_CONF="/etc/vconsole.conf"
>  
> +    # Core packages: always install the message-based localisation
> +    if [[ $msg_localisation == "yes" ]]; then
> +        CORE_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd"
> +    fi
> +

How custom modules are supposed to extend this list?

>      # This is from 10redhat-i18n.
>      findkeymap () {
>          local MAP=$1
> @@ -93,7 +102,11 @@ install() {
>      }
>  
>      install_base() {
> -        inst_multiple setfont loadkeys kbd_mode stty
> +        if [[ $msg_localisation == "yes" ]]; then
> +            inst_multiple setfont loadkeys kbd_mode unicode_start unicode_stop stty tty tset reset sleep
> +        else
> +            inst_multiple setfont loadkeys kbd_mode unicode_start unicode_stop
> +        fi
>  

Same here.

>          if ! dracut_module_included "systemd"; then
>              inst ${moddir}/console_init.sh /lib/udev/console_init
> @@ -212,11 +225,132 @@ install() {
>              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
>          fi
>  
> +        if [[ $msg_localisation == "yes" ]]; then
> +            [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
> +
> +            # Check if we can compile locale definitions
> +            command -v localedef > /dev/null && HAS_LOCALEDEF=true || HAS_LOCALEDEF=false
> +            if [ ${LC_ALL} ]; then
> +                read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
> +            fi
> +            if [ ${LANG} ]; then
> +                read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
> +            fi
> +            if [ ${LC_MESSAGES} ]; then
> +                read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
> +            fi
> +            if [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} || -e /usr/share/i18n/locales/${LANG_LOCALE} || -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]]; then
> +                HAS_LOCALE_SOURCES=true
> +            else
> +                HAS_LOCALE_SOURCES=false
> +            fi
> +            if [[ ${HAS_LOCALEDEF} == true && ${HAS_LOCALE_SOURCES} == true ]]; then
> +                CAN_BUILD_LOCALE=true
> +            else
> +                CAN_BUILD_LOCALE=false
> +            fi
> +
> +            # Generate locale definitions for LC_ALL
> +            if [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]]; then
> +                if [ ${CAN_BUILD_LOCALE} == true ]; then
> +                    if [ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ]; then
> +                        localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
> +                    fi
> +                fi
> +            fi
> +
> +            # Generate locale definitions for LANG
> +            if [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]]; then
> +                if [ ${CAN_BUILD_LOCALE} == true ]; then
> +                    if [ -e /usr/share/i18n/locales/${LANG_LOCALE} ]; then
> +                        localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
> +                    fi
> +                fi
> +            fi
> +
> +            # Generate locale definitions for LC_MESSAGES
> +            if [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]]; then
> +                if [ ${CAN_BUILD_LOCALE} == true ]; then
> +                    if [ -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]; then
> +                        localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
> +                    fi
> +                fi
> +            fi
> +
> +            # If locale definitions cannot be built, but compiled split definitions are
> +            # available, then install them
> +            if [ ${CAN_BUILD_LOCALE} == false ]; then

You set CAN_BUILD_LOCALE if *any* source is found. If some sources are
missing they will be neither compiled nor installed. So you really need
to change logic and simply do for every LC_ALL, LANG, LC_MESSAGES

if source exists
 compile
else if binary exists
 install

This actually makes code more clear.

> +                if [[ ${LC_ALL} && -d /usr/lib/locale/${LC_ALL} ]]; then
> +                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
> +                fi
> +                if [[ ${LANG} && -d /usr/lib/locale/${LANG} ]]; then
> +                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
> +                fi
> +                if [[ ${LC_MESSAGES} && -d /usr/lib/locale/${LC_MESSAGES} ]]; then
> +                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
> +                fi
> +            fi
> +
> +            # Install individual localisation files for core packages
> +            [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
> +            [[ ${LC_ALL_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE}"
> +            [[ ${LANG_LOCALE} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE}"
> +            [[ ${LC_MESSAGES_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE}"
> +            [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
> +            [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
> +            [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
> +            [[ ${LC_ALL_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE_SHORT}"
> +            [[ ${LANG_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE_SHORT}"
> +            [[ ${LC_MESSAGES_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}"
> +
> +            locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
> +            for dir in ${locale_dirs}; do
> +                [ -d "/usr/share/locale/${dir}" ] && for pkg in ${CORE_PACKAGES}; do
> +                    for file in `find "/usr/share/locale/${dir}" -type f -name "${pkg}.mo"`; do
> +                        inst_simple "${file}"
> +                    done
> +                done
> +            done
> +
> +            # Install ISO-8859 and Unicode charmap modules from GNU libc
> +            if [ -e "${initdir}/lib/ld-linux.so.*" ]; then
> +                LIBDIR=lib
> +            else
> +                LIBDIR=lib64
> +            fi

What about multi-arch and non-x86 systems? I have both
/lib/ld-linus.so.* and /lib64/ld-linux.so.* on 64 bit Ubuntu here.

> +            inst_multiple /usr/${LIBDIR}/gconv/ISO8859-*.so
> +            if [ ${UNICODE} == 1 ]; then
> +                inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so /usr/${LIBDIR}/gconv/UNICODE.so
> +            fi

And I have none of these files (assuming those files are required, can
you explain where they are used)? I have /usr/lib/x86_64-linux-gnu/gconv
and /usr/lib/i386-linux-gnu/gconv (and /usr/lib32/gconv, not sure how
they two are related to each other).

> +            if command -v iconvconfig > /dev/null; then
> +                if [ -e /usr/${LIBDIR}/gconv/gconv-modules ]; then
> +                    grep -E "^[[:space:]]*alias[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules > /tmp/gconv-modules
> +                    if [ ${UNICODE} == 1 ]; then
> +                        grep -E "^[[:space:]]*alias.*UTF-" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
> +                        grep -E "^[[:space:]]*alias.*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
> +                    fi
> +                    grep -E "^[[:space:]]*module[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
> +                    if [ ${UNICODE} == 1 ]; then
> +                        grep -E "^[[:space:]]*module[[:space:]]*UTF-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
> +                        grep -E "^[[:space:]]*module[[:space:]]*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
> +                    fi
> +                    if [ -e /tmp/gconv-modules ]; then
> +                        inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
> +                    fi
> +                fi
> +                iconvconfig --prefix="${initdir}"
> +            else
> +                if [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ]; then
> +                    inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache
> +                fi
> +            fi
> +        fi
> +
>          if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
>              inst_simple ${I18N_CONF}
>          else
>              mksubdirs ${initdir}${I18N_CONF}
> -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
> +            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
>          fi
>  
>          if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
> diff -pru dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh
> --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-20 14:11:02.825944933 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
> @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
>  inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
>  inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
>  
> -inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
> -inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
> -
> +inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
> +inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
> +inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
> + 
>  if [ -f /etc/locale.conf ]; then
>      . /etc/locale.conf
>      export LANG
>      export LC_ALL
> +    export LC_MESSAGES
>  fi
> diff -pru dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README
> --- dracut-git-orig/modules.d/10i18n/README	2016-04-20 14:11:02.826944946 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
> @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
>  
>      LANG
>      LC_ALL
> +    LC_MESSAGES
>  
>  If UNICODE variable is not provided, script indicates if UTF-8 should be
>  used on the basis of LANG value (if it ends with ".utf8" or similar).
> diff -pru dracut-git-orig/modules.d/90crypt/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh
> --- dracut-git-orig/modules.d/90crypt/module-setup.sh	2016-04-19 02:19:10.662042554 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh	2016-04-21 22:26:38.113859320 +0200
> @@ -88,6 +88,10 @@ install() {
>  
>      inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh"
>  
> +    if [[ $msg_localisation == "yes" ]]; then
> +        inst_i18n cryptsetup
> +    fi
> +

Oh, no, you should check for enabled l10n inside of inst_l10n and just
let other modules always install stuff they need. Let core logic handle
enabled stuff.

>      if dracut_module_included "systemd"; then
>          inst_multiple -o \
>                        $systemdutildir/system-generators/systemd-cryptsetup-generator \
> diff -pru dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh
> --- dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh	2016-04-19 02:19:10.667042618 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh	2016-04-22 18:06:54.504926340 +0200
> @@ -17,4 +17,8 @@ depends() {
>  install() {
>      inst_multiple gpg
>      inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
> +
> +    if [[ $msg_localisation == "yes" ]]; then
> +        inst_i18n gnupg
> +    fi
>  }
> diff -pru dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh
> --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20 14:11:02.826944946 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh	2016-04-20 14:02:01.578137511 +0200
> @@ -8,6 +8,8 @@
>  
>  export -p > /tmp/export.orig
>  
> +[ -f /etc/locale.conf ] && . /etc/locale.conf
> +
>  NEWROOT="/sysroot"
>  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
>  
> @@ -323,7 +325,7 @@ for i in $(export -p); do
>      i=${i%%=*}
>      [ -z "$i" ] && continue
>      case $i in
> -        root|PATH|HOME|TERM|PS4|RD_*)
> +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
>              :;;
>          *)
>              unset "$i";;
> diff -pru dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh
> --- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-20 14:11:02.827944958 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh	2016-04-21 20:01:54.611592039 +0200
> @@ -26,6 +26,10 @@ install() {
>          (ln -s bash "${initdir}/bin/sh" || :)
>      fi
>  
> +    if dracut_module_included "i18n"; then
> +       inst ${moddir}/profile /etc/profile
> +    fi
> +

Where this file comes from? It is not part of this patch?

>      #add common users in /etc/passwd, it will be used by nfs/ssh currently
>      grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
>      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
> Μόνο στο dracut-git-10i18n-full-support-for-localisation/modules.d/99base: profile
> diff -pru dracut-git-orig/NEWS dracut-git-10i18n-full-support-for-localisation/NEWS
> --- dracut-git-orig/NEWS	2016-04-19 02:19:10.648042373 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/NEWS	2016-04-21 17:00:46.436792093 +0200
> @@ -6,6 +6,7 @@ dracut now requires libkmod for the drac
>  dracut.sh:
>  - restorecon final image file
>  - fail hard, if we find modules and modules.dep is missing
> +- add an option to disable the new full localisation support
>  
>  dracut-functions.sh:
>  - fix check_vol_slaves() volume group name stripping
> @@ -34,6 +35,9 @@ general initramfs fixes:
>  - call dracut-cmdline-ask.service, if /etc/cmdline.d/*.conf exists
>  - break at switch_root only for bare rd.break
>  
> +i18n:
> +- add full localisation support (includes message-based localisation)
> +
>  dmsquash-live:
>  - fixed livenet-generator execution flag
>    and include only, if systemd is used
> --
> To unsubscribe from this list: send the line "unsubscribe initramfs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v8] dracut: add support for custom locale definitions
       [not found]                                             ` <571B2950.5060209-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2016-04-23 16:47                                               ` Guido Trentalancia
  0 siblings, 0 replies; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-23 16:47 UTC (permalink / raw)
  To: Andrei Borzenkov, Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

Hello.

On Sat, 23/04/2016 at 10.50 +0300, Andrei Borzenkov wrote:
> 22.04.2016 19:13, Guido Trentalancia пишет:
> > Compile and install locale definitions using localedef from GNU
> > libc or,
> > if locale definitions cannot be compiled but are available on the
> > system
> > as split definitions, just install them.
> > 
> > The resulting locale definitions archive contains at most two
> > different
> > locale definitions, therefore its size is relatively small.
> > 
> > Add support for localised messages from core packages
> > (LC_MESSAGES).
> > 
> > Add support for non-latin fonts using Unicode (tested successfully
> > with
> > Greek, Hebrew and Cyrillic).
> > 
> > This revised version fixes several issues in the initial patch
> > (including
> > the possibility to build locale definitions). Thanks to Andrei
> > Borzenkov
> > for reviewing the initial patch and providing useful suggestions.
> > 
> > Thanks for Harald Hoyer for the full style review and other useful
> > suggestions.
> > 
> > Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> > ---
> >  NEWS                                  |    4
> >  dracut-bash-completion.sh             |   11 +-
> >  dracut-init.sh                        |   37 ++++++++
> >  dracut.8.asc                          |    8 +
> >  dracut.conf.5.asc                     |   14 ++-
> >  dracut.sh                             |   20 +++-
> >  modules.d/10i18n/README               |    1
> >  modules.d/10i18n/console_init.sh      |   58 +++++++++-----
> >  modules.d/10i18n/module-setup.sh      |  140
> > +++++++++++++++++++++++++++++++++-
> >  modules.d/10i18n/parse-i18n.sh        |    8 +
> >  modules.d/90crypt/module-setup.sh     |    4
> >  modules.d/91crypt-gpg/module-setup.sh |    4
> >  modules.d/99base/init.sh              |    4
> >  modules.d/99base/module-setup.sh      |    4
> >  14 files changed, 279 insertions(+), 38 deletions(-)
> > 
> > diff -pru dracut-git-orig/dracut.8.asc dracut-git-10i18n-full-
> > support-for-localisation/dracut.8.asc
> > --- dracut-git-orig/dracut.8.asc	2016-04-19
> > 02:19:10.650042399 +0200
> > +++ dracut-git-10i18n-full-support-for-localisation/dracut.8.asc	
> > 2016-04-21 17:13:53.043188284 +0200
> > @@ -358,6 +358,14 @@ provide a valid _/etc/fstab_.
> >      LVM or an encrypted partition.
> >      [NB --device can be used for compatibility with earlier
> > releases]
> >  
> > +**--msg-localisation**::
> > +    Include full localisation support for the i18n module
> > (slightly increases
> > +    the initramfs size).
> > +
> 
> It is not "full" in any case. You only install message catalogs for
> selected compnents.

It is meant "full" compared to the actual support, which does only
include keyboard localisation. There aren't other standard Linux
localisation features that can be added, so it's full.

Message catalogs can be installed by all components, by using the new
inst_i18n() function, as suggested by Harald.

> > +**--no-msg-localisation**::
> > +    Do not include full localisation support for the i18n module
> > (to save
> > +    storage space or force the default locale).
> > +
> >  **-i, --include** _<SOURCE>_ _<TARGET>_::
> >      include the files in the SOURCE directory into the
> >      TARGET directory in the final initramfs. If SOURCE is a file,
> > it will be
> > diff -pru dracut-git-orig/dracut-bash-completion.sh dracut-git-
> > 10i18n-full-support-for-localisation/dracut-bash-completion.sh
> > --- dracut-git-orig/dracut-bash-completion.sh	2016-04-19
> > 02:19:10.648042373 +0200
> > +++ dracut-git-10i18n-full-support-for-localisation/dracut-bash-
> > completion.sh	2016-04-21 17:16:41.148400079 +0200
> > @@ -28,11 +28,12 @@ _dracut() {
> >                                --ro-mnt --force --kernel-only --no-
> > kernel --strip --nostrip
> >                                --hardlink --nohardlink --noprefix
> > --mdadmconf --nomdadmconf
> >                                --lvmconf --nolvmconf --debug --
> > profile --verbose --quiet
> > -                              --local --hostonly --no-hostonly --
> > fstab --help --bzip2 --lzma
> > -                              --xz --no-compress --gzip --list-
> > modules --show-modules --keep
> > -                              --printsize --regenerate-all --
> > noimageifnotneeded --early-microcode
> > -                              --no-early-microcode --print-cmdline 
> > --prelink --noprelink --reproducible
> > -                              --uefi
> > +                              --local --hostonly --no-hostonly --
> > fstab --msg-localisation
> > +                              --no-msg-localisation --help --bzip2 
> > --lzma --xz --no-compress
> > +                              --gzip --list-modules --show-modules 
> > --keep --printsize
> > +                              --regenerate-all --
> > noimageifnotneeded --early-microcode
> > +                              --no-early-microcode --print-cmdline 
> > --prelink --noprelink
> > +                              --reproducible --uefi
> >                                '
> >  
> >                         [ARG]='-a -m -o -d -I -k -c -L --kver --add 
> > --force-add --add-drivers
> > diff -pru dracut-git-orig/dracut.conf.5.asc dracut-git-10i18n-full-
> > support-for-localisation/dracut.conf.5.asc
> > --- dracut-git-orig/dracut.conf.5.asc	2016-04-19
> > 02:19:10.650042399 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/dracut.conf.5.asc	2016-04-21 17:21:57.576555027
> > +0200
> > @@ -99,9 +99,6 @@ Configuration files must have the extens
> >  *hostonly_cmdline=*"__{yes|no}__"::
> >      If set, store the kernel command line arguments needed in the
> > initramfs
> >  
> > -*i18n_install_all=*"__{yes|no}__"::
> > -    If set to yes, install all available fonts and keyboard files.
> > -
> >  *persistent_policy=*"__<policy>__"::
> >      Use _<policy>_ to address disks and partitions.
> >      _<policy>_ can be any directory name found in /dev/disk.
> > @@ -196,7 +193,16 @@ provide a valid _/etc/fstab_.
> >      Default is "LatArCyrHeb-16".
> >  
> >  *i18n_install_all=*"__{yes|no}__"::
> > -    Install everything regardless of generic or hostonly mode.
> > +    Install all available fonts and keyboard files regardless of
> > generic
> > +    or hostonly mode.
> > +
> > +*msg-localisation=*"__{yes|no}__"::
> > +    Add full localisation support (includes message-based
> > localisation
> > +    and non latin font support).
> > +
> 
> Are not fonts always installed? I do not see any dependency on this
> setings for fonts installation.

Fonts are installed but non latin characters are not being used, so
there is no full font localisation support.

> > +*no-msg-localisation=*"__{yes|no}__"::
> > +    Do not add full localisation support (only keyboard
> > localisation
> > +    is added): saves some storage space.
> >  
> >  *reproducible=*"__{yes|no}__"::
> >      Create reproducible images.
> > diff -pru dracut-git-orig/dracut-init.sh dracut-git-10i18n-full-
> > support-for-localisation/dracut-init.sh
> > --- dracut-git-orig/dracut-init.sh	2016-04-19
> > 02:19:10.649042386 +0200
> > +++ dracut-git-10i18n-full-support-for-localisation/dracut-init.sh	
> > 2016-04-22 18:05:08.033519479 +0200
> > @@ -214,6 +214,43 @@ inst_multiple() {
> >      return $_ret
> >  }
> >  
> > +# Install package translations (message-based localisations)
> > +inst_i18n() {
> 
> l10n is more common abbreviation for message translations. i18n
> usually
> refers to ability to process non-ASCII characters.

I am following the naming advice from Harald and will keep the current
name (also for consistency with the name of the module).

> > +    local _locale_dirs_dup
> > +    local _locale_dirs
> > +    local _tmppath
> > +    [[ $1 ]] || return 1  # no package name
> > +    [ -f /etc/locale.conf ] && . /etc/locale.conf
> > +    if [ ${LC_ALL} ]; then
> > +        read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
> > +    fi
> > +    if [ ${LANG} ]; then
> > +        read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
> > +    fi
> > +    if [ ${LC_MESSAGES} ]; then
> > +        read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo
> > ${LC_MESSAGES//./ })
> > +    fi
> > +    [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT
> > LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
> > +    [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT
> > LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
> > +    [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT
> > LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
> > +    _locale_dirs_dup="${LC_ALL_LOCALE} ${LANG_LOCALE}
> > ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT}
> > ${LC_MESSAGES_LOCALE_SHORT}"
> > +    _tmppath=
> > +    _locale_dirs=
> > +    for dir in ${_locale_dirs_dup}
> > +    do
> > +        case $_tmppath in
> > +            *\ ${dir}) ;;
> > +            *) _locale_dirs="${_tmppath} ${dir}";;
> > +        esac
> > +        _tmppath=${_locale_dirs}
> > +    done
> > +    for dir in ${_locale_dirs}; do
> > +        [[ -d "/usr/share/locale/${dir}" ]] && for file in `find
> > "/usr/share/locale/${dir}" -type f -name "$1.mo"`; do
> > +            inst_simple "${file}"
> > +        done
> > +    done
> > +}
> > +
> >  dracut_install() {
> >      inst_multiple "$@"
> >  }
> > diff -pru dracut-git-orig/dracut.sh dracut-git-10i18n-full-support-
> > for-localisation/dracut.sh
> > --- dracut-git-orig/dracut.sh	2016-04-19 02:19:10.652042425
> > +0200
> > +++ dracut-git-10i18n-full-support-for-localisation/dracut.sh	
> > 2016-04-21 23:06:34.022740183 +0200
> > @@ -163,6 +163,10 @@ Creates initial ramdisk images for prelo
> >    --mount "[MP]"	Same as above, but [DEV], [FSTYPE] and
> > [FSOPTS] are
> >  			determined by looking at the current
> > mounts.
> >    --add-device "[DEV]"  Bring up [DEV] in initramfs
> > +  --msg-localisation    Add full localisation support rather than
> > only
> > +                        the minimal keyboard support (default)
> > +  --no-msg-localisation Do not add full localisation support, but
> > only
> > +                        minimal keyboard support
> >    -i, --include [SOURCE] [TARGET]
> >                          Include the files in the SOURCE directory
> > into the
> >                           Target directory in the final initramfs.
> > @@ -344,6 +348,8 @@ rearrange_params()
> >          --long no-hostonly-cmdline \
> >          --long persistent-policy: \
> >          --long fstab \
> > +        --long msg-localisation \
> > +        --long no-msg-localisation \
> >          --long help \
> >          --long bzip2 \
> >          --long lzma \
> > @@ -538,6 +544,10 @@ while :; do
> >          --persistent-policy)
> >                         persistent_policy_l="$2";       PARMS_TO_ST
> > ORE+=" '$2'"; shift;;
> >          --fstab)       use_fstab_l="yes" ;;
> > +        --msg-localisation)
> > +                       msg_localisation_l="yes" ;;
> > +        --no-msg-localisation)
> > +                       msg_localisation_l="no" ;;
> >          -h|--help)     long_usage; exit 1 ;;
> >          -i|
> > --include)  include_src+=("$2");          PARMS_TO_STORE+=" '$2'";
> >                         shift;;
> > @@ -730,6 +740,8 @@ stdloglvl=$((stdloglvl + verbosity_mod_l
> >  [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
> >  [[ $persistent_policy_l ]] &&
> > persistent_policy=$persistent_policy_l
> >  [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
> > +[[ $msg_localisation_l ]] && msg_localisation=$msg_localisation_l
> > +[[ $msg_localisation_l ]] || msg_localisation="yes"
> >  [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
> >  [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
> >  [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
> > @@ -1269,10 +1281,10 @@ export initdir dracutbasedir \
> >      mods_to_load \
> >      fw_dir drivers_dir debug no_kernel kernel_only \
> >      omit_drivers mdadmconf lvmconf root_dev \
> > -    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
> > -    stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
> > -    debug host_fs_types host_devs swap_devs sshkey add_fstab \
> > -    DRACUT_VERSION udevdir prefix filesystems drivers \
> > +    use_fstab fstab_lines msg_localisation libdirs fscks \
> > +    nofscks ro_mnt stdloglvl sysloglvl fileloglvl kmsgloglvl \
> > +    logile debug host_fs_types host_devs swap_devs sshkey \
> > +    add_fstab DRACUT_VERSION udevdir prefix filesystems drivers \
> >      systemdutildir systemdsystemunitdir systemdsystemconfdir \
> >      hostonly_cmdline loginstall \
> >      tmpfilesdir
> > diff -pru dracut-git-orig/modules.d/10i18n/console_init.sh dracut-
> > git-10i18n-full-support-for-
> > localisation/modules.d/10i18n/console_init.sh
> > --- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-
> > 04-20 14:11:02.824944921 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/10i18n/console_init.sh	2016-04-22
> > 17:54:50.913345284 +0200
> > @@ -6,6 +6,7 @@ if [ -x $systemdutildir/systemd-vconsole
> >      $systemdutildir/systemd-vconsole-setup "$@"
> >  fi
> >  
> > +[ -e /etc/locale.conf ] && . /etc/locale.conf
> >  [ -e /etc/vconsole.conf ] && . /etc/vconsole.conf
> >  
> >  DEFAULT_FONT=LatArCyrHeb-16
> > @@ -19,14 +20,14 @@ set_keyboard() {
> >  }
> >  
> >  set_terminal() {
> > -    local dev=$1
> > -
> >      if [ "${UNICODE}" = 1 ]; then
> > -        printf '\033%%G' >&7
> > -        stty -F ${dev} iutf8
> > +        if [ "${FONT}" -a ! "${FONT_MAP}" ]; then
> > +            /usr/bin/unicode_start "${FONT}"
> > +        elif [ "${FONT}" -a "${FONT_MAP}" ]; then
> > +            /usr/bin/unicode_start "${FONT}" "${FONT_MAP}"
> > +        fi
> >      else
> > -        printf '\033%%@' >&7
> > -        stty -F ${dev} -iutf8
> > +        /usr/bin/unicode_stop
> >      fi
> >  }
> >  
> > @@ -44,16 +45,6 @@ set_keymap() {
> >      loadkeys -q ${utf_switch} ${KEYMAP} ${EXT_KEYMAPS}
> >  }
> >  
> > -set_font() {
> > -    local dev=$1; local trans=''; local uni=''
> > -
> > -    [ -z "${FONT}" ] && FONT=${DEFAULT_FONT}
> > -    [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}"
> > -    [ -n "${FONT_UNIMAP}" ] && uni="-u ${FONT_UNIMAP}"
> > -
> > -    setfont ${FONT} -C ${dev} ${trans} ${uni}
> > -}
> > -
> >  dev_close() {
> >      exec 6>&-
> >      exec 7>&-
> > @@ -74,6 +65,27 @@ devname=${dev#/dev/}
> >      exit 1
> >  }
> >  
> > +if [ "${UNICODE}" ]; then
> > +    if [ "${UNICODE}" = YES -o "${UNICODE}" = yes -o "${UNICODE}"
> > = 1 ]; then
> > +        UNICODE=1
> > +    elif [ "${UNICODE}" = NO -o "${UNICODE}" = no -o "${UNICODE}"
> > = 0 ]; then
> > +        UNICODE=0
> > +    else
> > +        UNICODE=''
> > +    fi
> > +fi
> > +if [ ! "${UNICODE}" ]; then
> > +    IFS=.
> > +    set -- $LANG
> > +    tail=$2
> > +    IFS=-
> > +    set -- $tail
> > +    type=$1
> > +    if [ "${type}" = "UTF" ]; then
> > +        UNICODE=1
> > +    fi
> 
> What about LANG=en_US.utf8? You probably want "locale charmap" here.

In my opinion, that will just increase the size (and complexity) of the
initramfs. Also, I am just following the existing code (the same is
done elsewhere).

> > +fi
> > +
> >  dev_open ${dev}
> >  
> >  for fd in 6 7; do
> > @@ -84,9 +96,19 @@ for fd in 6 7; do
> >      fi
> >  done
> >  
> > +# Immediately after booting up, the
> > +# display driver needs to settle,
> > +# otherwise the Unicode mode cannot
> > +# be enabled and the non latin
> > +# characters do not render properly.
> > +if [ -d /usr/share/locale ]; then
> > +    if [ ! -e /tmp/dracut-vga-init-complete ]; then
> > +        sleep 2 && :> /tmp/dracut-vga-init-complete
> > +    fi
> > +fi
> > +
> >  set_keyboard
> > -set_terminal ${dev}
> > -set_font ${dev}
> > +set_terminal
> >  set_keymap
> >  
> >  dev_close
> > diff -pru dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-
> > git-10i18n-full-support-for-localisation/modules.d/10i18n/module-
> > setup.sh
> > --- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-
> > 04-22 14:25:26.949983919 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/10i18n/module-setup.sh	2016-04-22
> > 15:42:18.988741282 +0200
> > @@ -4,7 +4,11 @@
> >  check() {
> >      [[ "$mount_needs" ]] && return 1
> >  
> > -    require_binaries setfont loadkeys kbd_mode || return 1
> > +    if [[ $msg_localisation == "yes" ]]; then
> > +        require_binaries setfont loadkeys kbd_mode unicode_start
> > unicode_stop stty tty tset reset sleep || return 1
> > +    else
> > +        require_binaries setfont loadkeys kbd_mode unicode_start
> > unicode_stop || return 1
> > +    fi
> >  
> 
> Well, you should move common stuff that is always required outside of
> "if". As soon as you need to modify the same item in two places, you
> are
> bound to make mistakes.

Done, thanks for the suggestion.

> >      return 0
> >  }
> > @@ -27,6 +31,11 @@ install() {
> >      I18N_CONF="/etc/locale.conf"
> >      VCONFIG_CONF="/etc/vconsole.conf"
> >  
> > +    # Core packages: always install the message-based localisation
> > +    if [[ $msg_localisation == "yes" ]]; then
> > +        CORE_PACKAGES="libc bash coreutils util-linux e2fsprogs
> > grep sed kbd"
> > +    fi
> > +
> 
> How custom modules are supposed to extend this list?
> 
> >      # This is from 10redhat-i18n.
> >      findkeymap () {
> >          local MAP=$1
> > @@ -93,7 +102,11 @@ install() {
> >      }
> >  
> >      install_base() {
> > -        inst_multiple setfont loadkeys kbd_mode stty
> > +        if [[ $msg_localisation == "yes" ]]; then
> > +            inst_multiple setfont loadkeys kbd_mode unicode_start
> > unicode_stop stty tty tset reset sleep
> > +        else
> > +            inst_multiple setfont loadkeys kbd_mode unicode_start
> > unicode_stop
> > +        fi
> >  
> 
> Same here.

Done.

> >          if ! dracut_module_included "systemd"; then
> >              inst ${moddir}/console_init.sh /lib/udev/console_init
> > @@ -212,11 +225,132 @@ install() {
> >              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
> >          fi
> >  
> > +        if [[ $msg_localisation == "yes" ]]; then
> > +            [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] &&
> > inst_dir /usr/lib/locale
> > +
> > +            # Check if we can compile locale definitions
> > +            command -v localedef > /dev/null && HAS_LOCALEDEF=true
> > || HAS_LOCALEDEF=false
> > +            if [ ${LC_ALL} ]; then
> > +                read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo
> > ${LC_ALL//./ })
> > +            fi
> > +            if [ ${LANG} ]; then
> > +                read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./
> > })
> > +            fi
> > +            if [ ${LC_MESSAGES} ]; then
> > +                read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP <
> > <(echo ${LC_MESSAGES//./ })
> > +            fi
> > +            if [[ -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ||
> > -e /usr/share/i18n/locales/${LANG_LOCALE} || -e
> > /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]]; then
> > +                HAS_LOCALE_SOURCES=true
> > +            else
> > +                HAS_LOCALE_SOURCES=false
> > +            fi
> > +            if [[ ${HAS_LOCALEDEF} == true &&
> > ${HAS_LOCALE_SOURCES} == true ]]; then
> > +                CAN_BUILD_LOCALE=true
> > +            else
> > +                CAN_BUILD_LOCALE=false
> > +            fi
> > +
> > +            # Generate locale definitions for LC_ALL
> > +            if [[ ${LC_ALL} && ${LC_ALL_LOCALE} &&
> > ${LC_ALL_CHARMAP} ]]; then
> > +                if [ ${CAN_BUILD_LOCALE} == true ]; then
> > +                    if [ -e
> > /usr/share/i18n/locales/${LC_ALL_LOCALE} ]; then
> > +                        localedef --prefix="${initdir}" -i
> > ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
> > +                    fi
> > +                fi
> > +            fi
> > +
> > +            # Generate locale definitions for LANG
> > +            if [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]];
> > then
> > +                if [ ${CAN_BUILD_LOCALE} == true ]; then
> > +                    if [ -e /usr/share/i18n/locales/${LANG_LOCALE}
> > ]; then
> > +                        localedef --prefix="${initdir}" -i
> > ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
> > +                    fi
> > +                fi
> > +            fi
> > +
> > +            # Generate locale definitions for LC_MESSAGES
> > +            if [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} &&
> > ${LC_MESSAGES_CHARMAP} ]]; then
> > +                if [ ${CAN_BUILD_LOCALE} == true ]; then
> > +                    if [ -e
> > /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]; then
> > +                        localedef --prefix="${initdir}" -i
> > ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
> > +                    fi
> > +                fi
> > +            fi
> > +
> > +            # If locale definitions cannot be built, but compiled
> > split definitions are
> > +            # available, then install them
> > +            if [ ${CAN_BUILD_LOCALE} == false ]; then
> 
> You set CAN_BUILD_LOCALE if *any* source is found. If some sources
> are
> missing they will be neither compiled nor installed. So you really
> need
> to change logic and simply do for every LC_ALL, LANG, LC_MESSAGES
> 
> if source exists
>  compile
> else if binary exists
>  install
> 
> This actually makes code more clear.

Changed.

> > +                if [[ ${LC_ALL} && -d /usr/lib/locale/${LC_ALL}
> > ]]; then
> > +                    cp -prfL -t "${initdir}/usr/lib/locale/"
> > /usr/lib/locale/${LC_ALL}
> > +                fi
> > +                if [[ ${LANG} && -d /usr/lib/locale/${LANG} ]];
> > then
> > +                    cp -prfL -t "${initdir}/usr/lib/locale/"
> > /usr/lib/locale/${LANG}
> > +                fi
> > +                if [[ ${LC_MESSAGES} && -d
> > /usr/lib/locale/${LC_MESSAGES} ]]; then
> > +                    cp -prfL -t "${initdir}/usr/lib/locale/"
> > /usr/lib/locale/${LC_MESSAGES}
> > +                fi
> > +            fi
> > +
> > +            # Install individual localisation files for core
> > packages
> > +            [ -e /usr/share/locale/locale.alias ] && inst_simple
> > /usr/share/locale/locale.alias
> > +            [[ ${LC_ALL_LOCALE} ]] && inst_dir
> > "/usr/share/locale/${LC_ALL_LOCALE}"
> > +            [[ ${LANG_LOCALE} ]] && inst_dir
> > "/usr/share/locale/${LANG_LOCALE}"
> > +            [[ ${LC_MESSAGES_LOCALE} ]] && inst_dir
> > "/usr/share/locale/${LC_MESSAGES_LOCALE}"
> > +            [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT
> > LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
> > +            [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT
> > LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
> > +            [[ ${LC_MESSAGES_LOCALE} ]] && read
> > LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo
> > ${LC_MESSAGES_LOCALE//_/ })
> > +            [[ ${LC_ALL_LOCALE_SHORT} ]] && inst_dir
> > "/usr/share/locale/${LC_ALL_LOCALE_SHORT}"
> > +            [[ ${LANG_LOCALE_SHORT} ]] && inst_dir
> > "/usr/share/locale/${LANG_LOCALE_SHORT}"
> > +            [[ ${LC_MESSAGES_LOCALE_SHORT} ]] && inst_dir
> > "/usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}"
> > +
> > +            locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE}
> > ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT}
> > {LC_MESSAGES_LOCALE_SHORT}"
> > +            for dir in ${locale_dirs}; do
> > +                [ -d "/usr/share/locale/${dir}" ] && for pkg in
> > ${CORE_PACKAGES}; do
> > +                    for file in `find "/usr/share/locale/${dir}"
> > -type f -name "${pkg}.mo"`; do
> > +                        inst_simple "${file}"
> > +                    done
> > +                done
> > +            done
> > +
> > +            # Install ISO-8859 and Unicode charmap modules from
> > GNU libc
> > +            if [ -e "${initdir}/lib/ld-linux.so.*" ]; then
> > +                LIBDIR=lib
> > +            else
> > +                LIBDIR=lib64
> > +            fi
> 
> What about multi-arch and non-x86 systems? I have both
> /lib/ld-linus.so.* and /lib64/ld-linux.so.* on 64 bit Ubuntu here.

It doesn't matter what you have on the system. What counts here is what
is installed in the initramfs. Initramfs doesn't support both, so it's
either "lib" or "lib64".

> > +            inst_multiple /usr/${LIBDIR}/gconv/ISO8859-*.so
> > +            if [ ${UNICODE} == 1 ]; then
> > +                inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so
> > /usr/${LIBDIR}/gconv/UNICODE.so
> > +            fi
> 
> And I have none of these files (assuming those files are required,
> can
> you explain where they are used)? I have /usr/lib/x86_64-linux-
> gnu/gconv
> and /usr/lib/i386-linux-gnu/gconv (and /usr/lib32/gconv, not sure how
> they two are related to each other).

If you have a non-standard installation, then it's up to you to submit
a patch to support it. I cannot test your installation and I cannot add
support for all different custom names, so please just wait that the
patch is committed and then submit a patch.

> > +            if command -v iconvconfig > /dev/null; then
> > +                if [ -e /usr/${LIBDIR}/gconv/gconv-modules ]; then
> > +                    grep -E "^[[:space:]]*alias[[:space:]]*ISO[-
> > ]*8859-" /usr/${LIBDIR}/gconv/gconv-modules > /tmp/gconv-modules
> > +                    if [ ${UNICODE} == 1 ]; then
> > +                        grep -E "^[[:space:]]*alias.*UTF-"
> > /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
> > +                        grep -E "^[[:space:]]*alias.*UNICODE"
> > /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
> > +                    fi
> > +                    grep -E "^[[:space:]]*module[[:space:]]*ISO[-
> > ]*8859-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >>
> > /tmp/gconv-modules
> > +                    if [ ${UNICODE} == 1 ]; then
> > +                        grep -E
> > "^[[:space:]]*module[[:space:]]*UTF-" /usr/${LIBDIR}/gconv/gconv-
> > modules | grep INTERNAL >> /tmp/gconv-modules
> > +                        grep -E
> > "^[[:space:]]*module[[:space:]]*UNICODE"
> > /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-
> > modules
> > +                    fi
> > +                    if [ -e /tmp/gconv-modules ]; then
> > +                        inst /tmp/gconv-modules
> > /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
> > +                    fi
> > +                fi
> > +                iconvconfig --prefix="${initdir}"
> > +            else
> > +                if [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache
> > ]; then
> > +                    inst_simple /usr/${LIBDIR}/gconv/gconv-
> > modules.cache
> > +                fi
> > +            fi
> > +        fi
> > +
> >          if dracut_module_included "systemd" && [[ -f ${I18N_CONF}
> > ]]; then
> >              inst_simple ${I18N_CONF}
> >          else
> >              mksubdirs ${initdir}${I18N_CONF}
> > -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
> > +            print_vars LANG LC_ALL LC_MESSAGES >>
> > ${initdir}${I18N_CONF}
> >          fi
> >  
> >          if dracut_module_included "systemd" && [[ -f
> > ${VCONFIG_CONF} ]]; then
> > diff -pru dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-
> > git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-
> > i18n.sh
> > --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-
> > 20 14:11:02.825944933 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/10i18n/parse-i18n.sh	2016-04-19
> > 02:26:46.617644187 +0200
> > @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
> >  inst_key_val /etc/vconsole.conf UNICODE      1
> > rd.vconsole.font.unicode UNICODE vconsole.unicode
> >  inst_key_val /etc/vconsole.conf EXT_KEYMAP  ''
> > rd.vconsole.keymap.ext   EXT_KEYMAP
> >  
> > -inst_key_val /etc/locale.conf   LANG        ''
> > rd.locale.LANG           LANG
> > -inst_key_val /etc/locale.conf   LC_ALL      ''
> > rd.locale.LC_ALL         LC_ALL
> > -
> > +inst_key_val /etc/locale.conf   LANG              ''
> > rd.locale.LANG               LANG
> > +inst_key_val /etc/locale.conf   LC_ALL            ''
> > rd.locale.LC_ALL             LC_ALL
> > +inst_key_val /etc/locale.conf   LC_MESSAGES       ''
> > rd.locale.LC_MESSAGES        LC_MESSAGES
> > + 
> >  if [ -f /etc/locale.conf ]; then
> >      . /etc/locale.conf
> >      export LANG
> >      export LC_ALL
> > +    export LC_MESSAGES
> >  fi
> > diff -pru dracut-git-orig/modules.d/10i18n/README dracut-git-
> > 10i18n-full-support-for-localisation/modules.d/10i18n/README
> > --- dracut-git-orig/modules.d/10i18n/README	2016-04-20
> > 14:11:02.826944946 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/10i18n/README	2016-04-19
> > 02:26:46.617644187 +0200
> > @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
> >  
> >      LANG
> >      LC_ALL
> > +    LC_MESSAGES
> >  
> >  If UNICODE variable is not provided, script indicates if UTF-8
> > should be
> >  used on the basis of LANG value (if it ends with ".utf8" or
> > similar).
> > diff -pru dracut-git-orig/modules.d/90crypt/module-setup.sh dracut-
> > git-10i18n-full-support-for-localisation/modules.d/90crypt/module-
> > setup.sh
> > --- dracut-git-orig/modules.d/90crypt/module-setup.sh	2016-
> > 04-19 02:19:10.662042554 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/90crypt/module-setup.sh	2016-04-21
> > 22:26:38.113859320 +0200
> > @@ -88,6 +88,10 @@ install() {
> >  
> >      inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh"
> >  
> > +    if [[ $msg_localisation == "yes" ]]; then
> > +        inst_i18n cryptsetup
> > +    fi
> > +
> 
> Oh, no, you should check for enabled l10n inside of inst_l10n and
> just
> let other modules always install stuff they need. Let core logic
> handle
> enabled stuff.

I have added the check you suggest.

> >      if dracut_module_included "systemd"; then
> >          inst_multiple -o \
> >                        $systemdutildir/system-generators/systemd-
> > cryptsetup-generator \
> > diff -pru dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh
> > dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-
> > gpg/module-setup.sh
> > --- dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh	20
> > 16-04-19 02:19:10.667042618 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/91crypt-gpg/module-setup.sh	2016-04-
> > 22 18:06:54.504926340 +0200
> > @@ -17,4 +17,8 @@ depends() {
> >  install() {
> >      inst_multiple gpg
> >      inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
> > +
> > +    if [[ $msg_localisation == "yes" ]]; then
> > +        inst_i18n gnupg
> > +    fi
> >  }
> > diff -pru dracut-git-orig/modules.d/99base/init.sh dracut-git-
> > 10i18n-full-support-for-localisation/modules.d/99base/init.sh
> > --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20
> > 14:11:02.826944946 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/99base/init.sh	2016-04-20
> > 14:02:01.578137511 +0200
> > @@ -8,6 +8,8 @@
> >  
> >  export -p > /tmp/export.orig
> >  
> > +[ -f /etc/locale.conf ] && . /etc/locale.conf
> > +
> >  NEWROOT="/sysroot"
> >  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
> >  
> > @@ -323,7 +325,7 @@ for i in $(export -p); do
> >      i=${i%%=*}
> >      [ -z "$i" ] && continue
> >      case $i in
> > -        root|PATH|HOME|TERM|PS4|RD_*)
> > +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
> >              :;;
> >          *)
> >              unset "$i";;
> > diff -pru dracut-git-orig/modules.d/99base/module-setup.sh dracut-
> > git-10i18n-full-support-for-localisation/modules.d/99base/module-
> > setup.sh
> > --- dracut-git-orig/modules.d/99base/module-setup.sh	2016-
> > 04-20 14:11:02.827944958 +0200
> > +++ dracut-git-10i18n-full-support-for-
> > localisation/modules.d/99base/module-setup.sh	2016-04-21
> > 20:01:54.611592039 +0200
> > @@ -26,6 +26,10 @@ install() {
> >          (ln -s bash "${initdir}/bin/sh" || :)
> >      fi
> >  
> > +    if dracut_module_included "i18n"; then
> > +       inst ${moddir}/profile /etc/profile
> > +    fi
> > +
> 
> Where this file comes from? It is not part of this patch?

I have included the file in the latest patch that I am going to post
shortly.

> >      #add common users in /etc/passwd, it will be used by nfs/ssh
> > currently
> >      grep '^root:' "$initdir/etc/passwd" 2>/dev/null ||
> > echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
> >      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
> > Μόνο στο dracut-git-10i18n-full-support-for-
> > localisation/modules.d/99base: profile
> > diff -pru dracut-git-orig/NEWS dracut-git-10i18n-full-support-for-
> > localisation/NEWS
> > --- dracut-git-orig/NEWS	2016-04-19 02:19:10.648042373 +0200
> > +++ dracut-git-10i18n-full-support-for-localisation/NEWS	201
> > 6-04-21 17:00:46.436792093 +0200
> > @@ -6,6 +6,7 @@ dracut now requires libkmod for the drac
> >  dracut.sh:
> >  - restorecon final image file
> >  - fail hard, if we find modules and modules.dep is missing
> > +- add an option to disable the new full localisation support
> >  
> >  dracut-functions.sh:
> >  - fix check_vol_slaves() volume group name stripping
> > @@ -34,6 +35,9 @@ general initramfs fixes:
> >  - call dracut-cmdline-ask.service, if /etc/cmdline.d/*.conf exists
> >  - break at switch_root only for bare rd.break
> >  
> > +i18n:
> > +- add full localisation support (includes message-based
> > localisation)
> > +
> >  dmsquash-live:
> >  - fixed livenet-generator execution flag
> >    and include only, if systemd is used

Regards,

Guido

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v9] dracut: add support for custom locale definitions
       [not found]                                         ` <1461341618.21231.0.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  2016-04-23  7:50                                           ` Andrei Borzenkov
@ 2016-04-23 16:50                                           ` Guido Trentalancia
       [not found]                                             ` <1461430242.2604.15.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  1 sibling, 1 reply; 24+ messages in thread
From: Guido Trentalancia @ 2016-04-23 16:50 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Compile and install locale definitions using localedef from GNU libc or,
if locale definitions cannot be compiled but are available on the system
as split definitions, just install them.

The resulting locale definitions archive contains at most two different
locale definitions, therefore its size is relatively small.

Add support for localised messages from core packages (LC_MESSAGES).

Add support for non-latin fonts using Unicode (tested successfully with
Greek, Hebrew and Cyrillic).

This revised version fixes several issues in the initial patch (including
the possibility to build locale definitions). Thanks to Andrei Borzenkov
for reviewing the initial patch and providing useful suggestions.

Thanks for Harald Hoyer for the full style review and other useful
suggestions.

Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
---
 NEWS                                  |    4 +
 dracut-bash-completion.sh             |   11 +--
 dracut-init.sh                        |   37 ++++++++++
 dracut.8.asc                          |    8 ++
 dracut.conf.5.asc                     |   14 ++-
 dracut.sh                             |   20 ++++-
 modules.d/10i18n/README               |    1
 modules.d/10i18n/console_init.sh      |   58 +++++++++++-----
 modules.d/10i18n/module-setup.sh      |  123 +++++++++++++++++++++++++++++++++-
 modules.d/10i18n/parse-i18n.sh        |    8 +-
 modules.d/90crypt/module-setup.sh     |    6 +
 modules.d/91crypt-gpg/module-setup.sh |    6 +
 modules.d/99base/init.sh              |    4 -
 modules.d/99base/module-setup.sh      |    4 +
 modules.d/99base/profile              |    9 ++
 15 files changed, 275 insertions(+), 38 deletions(-)

diff -pruN dracut-git-orig/dracut.8.asc dracut-git-10i18n-full-support-for-localisation/dracut.8.asc
--- dracut-git-orig/dracut.8.asc	2016-04-19 02:19:10.650042399 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut.8.asc	2016-04-21 17:13:53.043188284 +0200
@@ -358,6 +358,14 @@ provide a valid _/etc/fstab_.
     LVM or an encrypted partition.
     [NB --device can be used for compatibility with earlier releases]
 
+**--msg-localisation**::
+    Include full localisation support for the i18n module (slightly increases
+    the initramfs size).
+
+**--no-msg-localisation**::
+    Do not include full localisation support for the i18n module (to save
+    storage space or force the default locale).
+
 **-i, --include** _<SOURCE>_ _<TARGET>_::
     include the files in the SOURCE directory into the
     TARGET directory in the final initramfs. If SOURCE is a file, it will be
diff -pruN dracut-git-orig/dracut-bash-completion.sh dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh
--- dracut-git-orig/dracut-bash-completion.sh	2016-04-19 02:19:10.648042373 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh	2016-04-21 17:16:41.148400079 +0200
@@ -28,11 +28,12 @@ _dracut() {
                               --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
                               --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
                               --lvmconf --nolvmconf --debug --profile --verbose --quiet
-                              --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
-                              --xz --no-compress --gzip --list-modules --show-modules --keep
-                              --printsize --regenerate-all --noimageifnotneeded --early-microcode
-                              --no-early-microcode --print-cmdline --prelink --noprelink --reproducible
-                              --uefi
+                              --local --hostonly --no-hostonly --fstab --msg-localisation
+                              --no-msg-localisation --help --bzip2 --lzma --xz --no-compress
+                              --gzip --list-modules --show-modules --keep --printsize
+                              --regenerate-all --noimageifnotneeded --early-microcode
+                              --no-early-microcode --print-cmdline --prelink --noprelink
+                              --reproducible --uefi
                               '
 
                        [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
diff -pruN dracut-git-orig/dracut.conf.5.asc dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc
--- dracut-git-orig/dracut.conf.5.asc	2016-04-19 02:19:10.650042399 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc	2016-04-21 17:21:57.576555027 +0200
@@ -99,9 +99,6 @@ Configuration files must have the extens
 *hostonly_cmdline=*"__{yes|no}__"::
     If set, store the kernel command line arguments needed in the initramfs
 
-*i18n_install_all=*"__{yes|no}__"::
-    If set to yes, install all available fonts and keyboard files.
-
 *persistent_policy=*"__<policy>__"::
     Use _<policy>_ to address disks and partitions.
     _<policy>_ can be any directory name found in /dev/disk.
@@ -196,7 +193,16 @@ provide a valid _/etc/fstab_.
     Default is "LatArCyrHeb-16".
 
 *i18n_install_all=*"__{yes|no}__"::
-    Install everything regardless of generic or hostonly mode.
+    Install all available fonts and keyboard files regardless of generic
+    or hostonly mode.
+
+*msg-localisation=*"__{yes|no}__"::
+    Add full localisation support (includes message-based localisation
+    and non latin font support).
+
+*no-msg-localisation=*"__{yes|no}__"::
+    Do not add full localisation support (only keyboard localisation
+    is added): saves some storage space.
 
 *reproducible=*"__{yes|no}__"::
     Create reproducible images.
diff -pruN dracut-git-orig/dracut-init.sh dracut-git-10i18n-full-support-for-localisation/dracut-init.sh
--- dracut-git-orig/dracut-init.sh	2016-04-19 02:19:10.649042386 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut-init.sh	2016-04-22 18:05:08.033519479 +0200
@@ -214,6 +214,43 @@ inst_multiple() {
     return $_ret
 }
 
+# Install package translations (message-based localisations)
+inst_i18n() {
+    local _locale_dirs_dup
+    local _locale_dirs
+    local _tmppath
+    [[ $1 ]] || return 1  # no package name
+    [ -f /etc/locale.conf ] && . /etc/locale.conf
+    if [ ${LC_ALL} ]; then
+        read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
+    fi
+    if [ ${LANG} ]; then
+        read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
+    fi
+    if [ ${LC_MESSAGES} ]; then
+        read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
+    fi
+    [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
+    [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
+    [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
+    _locale_dirs_dup="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} ${LC_MESSAGES_LOCALE_SHORT}"
+    _tmppath=
+    _locale_dirs=
+    for dir in ${_locale_dirs_dup}
+    do
+        case $_tmppath in
+            *\ ${dir}) ;;
+            *) _locale_dirs="${_tmppath} ${dir}";;
+        esac
+        _tmppath=${_locale_dirs}
+    done
+    for dir in ${_locale_dirs}; do
+        [[ -d "/usr/share/locale/${dir}" ]] && for file in `find "/usr/share/locale/${dir}" -type f -name "$1.mo"`; do
+            inst_simple "${file}"
+        done
+    done
+}
+
 dracut_install() {
     inst_multiple "$@"
 }
diff -pruN dracut-git-orig/dracut.sh dracut-git-10i18n-full-support-for-localisation/dracut.sh
--- dracut-git-orig/dracut.sh	2016-04-19 02:19:10.652042425 +0200
+++ dracut-git-10i18n-full-support-for-localisation/dracut.sh	2016-04-21 23:06:34.022740183 +0200
@@ -163,6 +163,10 @@ Creates initial ramdisk images for prelo
   --mount "[MP]"	Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
 			determined by looking at the current mounts.
   --add-device "[DEV]"  Bring up [DEV] in initramfs
+  --msg-localisation    Add full localisation support rather than only
+                        the minimal keyboard support (default)
+  --no-msg-localisation Do not add full localisation support, but only
+                        minimal keyboard support
   -i, --include [SOURCE] [TARGET]
                         Include the files in the SOURCE directory into the
                          Target directory in the final initramfs.
@@ -344,6 +348,8 @@ rearrange_params()
         --long no-hostonly-cmdline \
         --long persistent-policy: \
         --long fstab \
+        --long msg-localisation \
+        --long no-msg-localisation \
         --long help \
         --long bzip2 \
         --long lzma \
@@ -538,6 +544,10 @@ while :; do
         --persistent-policy)
                        persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
         --fstab)       use_fstab_l="yes" ;;
+        --msg-localisation)
+                       msg_localisation_l="yes" ;;
+        --no-msg-localisation)
+                       msg_localisation_l="no" ;;
         -h|--help)     long_usage; exit 1 ;;
         -i|--include)  include_src+=("$2");          PARMS_TO_STORE+=" '$2'";
                        shift;;
@@ -730,6 +740,8 @@ stdloglvl=$((stdloglvl + verbosity_mod_l
 [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
+[[ $msg_localisation_l ]] && msg_localisation=$msg_localisation_l
+[[ $msg_localisation_l ]] || msg_localisation="yes"
 [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
 [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
@@ -1269,10 +1281,10 @@ export initdir dracutbasedir \
     mods_to_load \
     fw_dir drivers_dir debug no_kernel kernel_only \
     omit_drivers mdadmconf lvmconf root_dev \
-    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
-    stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
-    debug host_fs_types host_devs swap_devs sshkey add_fstab \
-    DRACUT_VERSION udevdir prefix filesystems drivers \
+    use_fstab fstab_lines msg_localisation libdirs fscks \
+    nofscks ro_mnt stdloglvl sysloglvl fileloglvl kmsgloglvl \
+    logile debug host_fs_types host_devs swap_devs sshkey \
+    add_fstab DRACUT_VERSION udevdir prefix filesystems drivers \
     systemdutildir systemdsystemunitdir systemdsystemconfdir \
     hostonly_cmdline loginstall \
     tmpfilesdir
diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh
--- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-20 14:11:02.824944921 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh	2016-04-22 17:54:50.913345284 +0200
@@ -6,6 +6,7 @@ if [ -x $systemdutildir/systemd-vconsole
     $systemdutildir/systemd-vconsole-setup "$@"
 fi
 
+[ -e /etc/locale.conf ] && . /etc/locale.conf
 [ -e /etc/vconsole.conf ] && . /etc/vconsole.conf
 
 DEFAULT_FONT=LatArCyrHeb-16
@@ -19,14 +20,14 @@ set_keyboard() {
 }
 
 set_terminal() {
-    local dev=$1
-
     if [ "${UNICODE}" = 1 ]; then
-        printf '\033%%G' >&7
-        stty -F ${dev} iutf8
+        if [ "${FONT}" -a ! "${FONT_MAP}" ]; then
+            /usr/bin/unicode_start "${FONT}"
+        elif [ "${FONT}" -a "${FONT_MAP}" ]; then
+            /usr/bin/unicode_start "${FONT}" "${FONT_MAP}"
+        fi
     else
-        printf '\033%%@' >&7
-        stty -F ${dev} -iutf8
+        /usr/bin/unicode_stop
     fi
 }
 
@@ -44,16 +45,6 @@ set_keymap() {
     loadkeys -q ${utf_switch} ${KEYMAP} ${EXT_KEYMAPS}
 }
 
-set_font() {
-    local dev=$1; local trans=''; local uni=''
-
-    [ -z "${FONT}" ] && FONT=${DEFAULT_FONT}
-    [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}"
-    [ -n "${FONT_UNIMAP}" ] && uni="-u ${FONT_UNIMAP}"
-
-    setfont ${FONT} -C ${dev} ${trans} ${uni}
-}
-
 dev_close() {
     exec 6>&-
     exec 7>&-
@@ -74,6 +65,27 @@ devname=${dev#/dev/}
     exit 1
 }
 
+if [ "${UNICODE}" ]; then
+    if [ "${UNICODE}" = YES -o "${UNICODE}" = yes -o "${UNICODE}" = 1 ]; then
+        UNICODE=1
+    elif [ "${UNICODE}" = NO -o "${UNICODE}" = no -o "${UNICODE}" = 0 ]; then
+        UNICODE=0
+    else
+        UNICODE=''
+    fi
+fi
+if [ ! "${UNICODE}" ]; then
+    IFS=.
+    set -- $LANG
+    tail=$2
+    IFS=-
+    set -- $tail
+    type=$1
+    if [ "${type}" = "UTF" ]; then
+        UNICODE=1
+    fi
+fi
+
 dev_open ${dev}
 
 for fd in 6 7; do
@@ -84,9 +96,19 @@ for fd in 6 7; do
     fi
 done
 
+# Immediately after booting up, the
+# display driver needs to settle,
+# otherwise the Unicode mode cannot
+# be enabled and the non latin
+# characters do not render properly.
+if [ -d /usr/share/locale ]; then
+    if [ ! -e /tmp/dracut-vga-init-complete ]; then
+        sleep 2 && :> /tmp/dracut-vga-init-complete
+    fi
+fi
+
 set_keyboard
-set_terminal ${dev}
-set_font ${dev}
+set_terminal
 set_keymap
 
 dev_close
diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh
--- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-22 14:25:26.949983919 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh	2016-04-23 18:23:14.911103135 +0200
@@ -4,7 +4,11 @@
 check() {
     [[ "$mount_needs" ]] && return 1
 
-    require_binaries setfont loadkeys kbd_mode || return 1
+    require_binaries setfont loadkeys kbd_mode unicode_start unicode_stop
+
+    if [[ $msg_localisation == "yes" ]]; then
+        require_binaries stty tty tset reset sleep || return 1
+    fi
 
     return 0
 }
@@ -27,6 +31,11 @@ install() {
     I18N_CONF="/etc/locale.conf"
     VCONFIG_CONF="/etc/vconsole.conf"
 
+    # Core packages: always install the message-based localisation
+    if [[ $msg_localisation == "yes" ]]; then
+        CORE_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd"
+    fi
+
     # This is from 10redhat-i18n.
     findkeymap () {
         local MAP=$1
@@ -93,7 +102,11 @@ install() {
     }
 
     install_base() {
-        inst_multiple setfont loadkeys kbd_mode stty
+        inst_multiple setfont loadkeys kbd_mode unicode_start unicode_stop
+
+        if [[ $msg_localisation == "yes" ]]; then
+            inst_multiple stty tty tset reset sleep
+        fi
 
         if ! dracut_module_included "systemd"; then
             inst ${moddir}/console_init.sh /lib/udev/console_init
@@ -212,11 +225,115 @@ install() {
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
         fi
 
+        if [[ $msg_localisation == "yes" ]]; then
+            [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
+
+            # Check if we can compile locale definitions
+            if command -v localedef > /dev/null; then
+                HAS_LOCALEDEF=true
+            else
+                HAS_LOCALEDEF=false
+            fi
+            if [ ${LC_ALL} ]; then
+                read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
+            fi
+            if [ ${LANG} ]; then
+                read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
+            fi
+            if [ ${LC_MESSAGES} ]; then
+                read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
+            fi
+
+            # Generate locale definitions for LC_ALL or install compiled split
+            # definitions where available
+            if [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]]; then
+                if [[ ${HAS_LOCALEDEF} == true && -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ]]; then
+                    localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
+                elif [ -d "/usr/lib/locale/${LC_ALL}" ]; then
+                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
+                fi
+            fi
+
+            # Generate locale definitions for LANG or install compiled split
+            # definitions where available
+            if [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]]; then
+                if [[ ${HAS_LOCALEDEF} == true && -e /usr/share/i18n/locales/${LANG_LOCALE} ]]; then
+                    localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
+                elif [ -d "/usr/lib/locale/${LANG}" ]; then
+                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
+                fi
+            fi
+
+            # Generate locale definitions for LC_MESSAGES of install compiled split
+            # definitions where available
+            if [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]]; then
+                if [[ ${HAS_LOCALEDEF} == true && -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]]; then
+                    localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
+                elif [ -d "/usr/lib/locale/${LC_MESSAGES}" ]; then
+                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
+                fi
+            fi
+
+            # Install individual localisation files for core packages
+            [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
+            [[ ${LC_ALL_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE}"
+            [[ ${LANG_LOCALE} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE}"
+            [[ ${LC_MESSAGES_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE}"
+            [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
+            [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
+            [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
+            [[ ${LC_ALL_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE_SHORT}"
+            [[ ${LANG_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE_SHORT}"
+            [[ ${LC_MESSAGES_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}"
+
+            locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
+            for dir in ${locale_dirs}; do
+                [ -d "/usr/share/locale/${dir}" ] && for pkg in ${CORE_PACKAGES}; do
+                    for file in `find "/usr/share/locale/${dir}" -type f -name "${pkg}.mo"`; do
+                        inst_simple "${file}"
+                    done
+                done
+            done
+
+            # Install ISO-8859 and Unicode charmap modules from GNU libc
+            if [ -e "${initdir}/lib/ld-linux.so.*" ]; then
+                LIBDIR=lib
+            else
+                LIBDIR=lib64
+            fi
+            inst_multiple /usr/${LIBDIR}/gconv/ISO8859-*.so
+            if [ ${UNICODE} == 1 ]; then
+                inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so /usr/${LIBDIR}/gconv/UNICODE.so
+            fi
+            if command -v iconvconfig > /dev/null; then
+                if [ -e /usr/${LIBDIR}/gconv/gconv-modules ]; then
+                    grep -E "^[[:space:]]*alias[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules > /tmp/gconv-modules
+                    if [ ${UNICODE} == 1 ]; then
+                        grep -E "^[[:space:]]*alias.*UTF-" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
+                        grep -E "^[[:space:]]*alias.*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
+                    fi
+                    grep -E "^[[:space:]]*module[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
+                    if [ ${UNICODE} == 1 ]; then
+                        grep -E "^[[:space:]]*module[[:space:]]*UTF-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
+                        grep -E "^[[:space:]]*module[[:space:]]*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
+                    fi
+                    if [ -e /tmp/gconv-modules ]; then
+                        inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
+                    fi
+                fi
+                iconvconfig --prefix="${initdir}"
+            else
+                if [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ]; then
+                    inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache
+                fi
+            fi
+        fi
+
         if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
             inst_simple ${I18N_CONF}
         else
             mksubdirs ${initdir}${I18N_CONF}
-            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
+            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
         fi
 
         if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh
--- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-20 14:11:02.825944933 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
@@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
 inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
 inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
 
-inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
-inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
-
+inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
+inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
+inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
+ 
 if [ -f /etc/locale.conf ]; then
     . /etc/locale.conf
     export LANG
     export LC_ALL
+    export LC_MESSAGES
 fi
diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README
--- dracut-git-orig/modules.d/10i18n/README	2016-04-20 14:11:02.826944946 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
@@ -65,6 +65,7 @@ I'm leaving it in case...  The following
 
     LANG
     LC_ALL
+    LC_MESSAGES
 
 If UNICODE variable is not provided, script indicates if UTF-8 should be
 used on the basis of LANG value (if it ends with ".utf8" or similar).
diff -pruN dracut-git-orig/modules.d/90crypt/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh
--- dracut-git-orig/modules.d/90crypt/module-setup.sh	2016-04-19 02:19:10.662042554 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh	2016-04-23 17:09:50.584472072 +0200
@@ -88,6 +88,12 @@ install() {
 
     inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh"
 
+    if dracut_module_included "i18n"; then
+        if [[ $msg_localisation == "yes" ]]; then
+            inst_i18n cryptsetup
+        fi
+    fi
+
     if dracut_module_included "systemd"; then
         inst_multiple -o \
                       $systemdutildir/system-generators/systemd-cryptsetup-generator \
diff -pruN dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh
--- dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh	2016-04-19 02:19:10.667042618 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh	2016-04-23 17:10:10.783667188 +0200
@@ -17,4 +17,10 @@ depends() {
 install() {
     inst_multiple gpg
     inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
+
+    if dracut_module_included "i18n"; then
+        if [[ $msg_localisation == "yes" ]]; then
+            inst_i18n gnupg
+        fi
+    fi
 }
diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh
--- dracut-git-orig/modules.d/99base/init.sh	2016-04-20 14:11:02.826944946 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh	2016-04-20 14:02:01.578137511 +0200
@@ -8,6 +8,8 @@
 
 export -p > /tmp/export.orig
 
+[ -f /etc/locale.conf ] && . /etc/locale.conf
+
 NEWROOT="/sysroot"
 [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
 
@@ -323,7 +325,7 @@ for i in $(export -p); do
     i=${i%%=*}
     [ -z "$i" ] && continue
     case $i in
-        root|PATH|HOME|TERM|PS4|RD_*)
+        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
             :;;
         *)
             unset "$i";;
diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh
--- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-20 14:11:02.827944958 +0200
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh	2016-04-21 20:01:54.611592039 +0200
@@ -26,6 +26,10 @@ install() {
         (ln -s bash "${initdir}/bin/sh" || :)
     fi
 
+    if dracut_module_included "i18n"; then
+       inst ${moddir}/profile /etc/profile
+    fi
+
     #add common users in /etc/passwd, it will be used by nfs/ssh currently
     grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
     grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
diff -pruN dracut-git-orig/modules.d/99base/profile dracut-git-10i18n-full-support-for-localisation/modules.d/99base/profile
--- dracut-git-orig/modules.d/99base/profile	1970-01-01 01:00:00.000000000 +0100
+++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/profile	2016-04-21 23:43:08.049029619 +0200
@@ -0,0 +1,9 @@
+# /etc/profile
+
+# Load locale settings
+if [ -f /etc/locale.conf ]; then
+  . /etc/locale.conf
+  [ -n "${LANG}" ] && export LANG || unset LANG
+  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
+  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset LC_MESSAGES
+fi
diff -pruN dracut-git-orig/NEWS dracut-git-10i18n-full-support-for-localisation/NEWS
--- dracut-git-orig/NEWS	2016-04-19 02:19:10.648042373 +0200
+++ dracut-git-10i18n-full-support-for-localisation/NEWS	2016-04-21 17:00:46.436792093 +0200
@@ -6,6 +6,7 @@ dracut now requires libkmod for the drac
 dracut.sh:
 - restorecon final image file
 - fail hard, if we find modules and modules.dep is missing
+- add an option to disable the new full localisation support
 
 dracut-functions.sh:
 - fix check_vol_slaves() volume group name stripping
@@ -34,6 +35,9 @@ general initramfs fixes:
 - call dracut-cmdline-ask.service, if /etc/cmdline.d/*.conf exists
 - break at switch_root only for bare rd.break
 
+i18n:
+- add full localisation support (includes message-based localisation)
+
 dmsquash-live:
 - fixed livenet-generator execution flag
   and include only, if systemd is used

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v9] dracut: add support for custom locale definitions
       [not found]                                             ` <1461430242.2604.15.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
@ 2016-05-06 15:01                                               ` Guido Trentalancia
  2017-10-11 13:17                                               ` Harald Hoyer
  1 sibling, 0 replies; 24+ messages in thread
From: Guido Trentalancia @ 2016-05-06 15:01 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Hello !

I have noticed the patch below has not been applied yet, despite the
amendments that have been made as required. Is there any reason for
that ?

Regards,

Guido

On Sat, 23/04/2016 at 18.50 +0200, Guido Trentalancia wrote:
> Compile and install locale definitions using localedef from GNU libc
> or,
> if locale definitions cannot be compiled but are available on the
> system
> as split definitions, just install them.
> 
> The resulting locale definitions archive contains at most two
> different
> locale definitions, therefore its size is relatively small.
> 
> Add support for localised messages from core packages (LC_MESSAGES).
> 
> Add support for non-latin fonts using Unicode (tested successfully
> with
> Greek, Hebrew and Cyrillic).
> 
> This revised version fixes several issues in the initial patch
> (including
> the possibility to build locale definitions). Thanks to Andrei
> Borzenkov
> for reviewing the initial patch and providing useful suggestions.
> 
> Thanks for Harald Hoyer for the full style review and other useful
> suggestions.
> 
> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> ---
>  NEWS                                  |    4 +
>  dracut-bash-completion.sh             |   11 +--
>  dracut-init.sh                        |   37 ++++++++++
>  dracut.8.asc                          |    8 ++
>  dracut.conf.5.asc                     |   14 ++-
>  dracut.sh                             |   20 ++++-
>  modules.d/10i18n/README               |    1
>  modules.d/10i18n/console_init.sh      |   58 +++++++++++-----
>  modules.d/10i18n/module-setup.sh      |  123
> +++++++++++++++++++++++++++++++++-
>  modules.d/10i18n/parse-i18n.sh        |    8 +-
>  modules.d/90crypt/module-setup.sh     |    6 +
>  modules.d/91crypt-gpg/module-setup.sh |    6 +
>  modules.d/99base/init.sh              |    4 -
>  modules.d/99base/module-setup.sh      |    4 +
>  modules.d/99base/profile              |    9 ++
>  15 files changed, 275 insertions(+), 38 deletions(-)

[...]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v7] dracut: add support for custom locale definitions
       [not found]                                         ` <1461241841.10934.12.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  2016-04-21 12:41                                           ` Andrei Borzenkov
  2016-04-21 13:07                                           ` Harald Hoyer
@ 2016-05-17 10:12                                           ` Thomas Renninger
  2016-05-17 12:36                                             ` [PATCH v9] " Guido Trentalancia
  2 siblings, 1 reply; 24+ messages in thread
From: Thomas Renninger @ 2016-05-17 10:12 UTC (permalink / raw)
  To: Guido Trentalancia; +Cc: Harald Hoyer, initramfs-u79uwXL29TY76Z2rM5mHXA

On Thursday, April 21, 2016 02:30:41 PM Guido Trentalancia wrote:
> Hello Harald !
> 
> On Thu, 21/04/2016 Guido Trentalancia wrote:
> > > Compile and install locale definitions using localedef from GNU
> > > libc or,
> > > if locale definitions cannot be compiled but are available on the
> > > system
> > > as split definitions, just install them.
> > > 
> > > The resulting locale definitions archive contains at most two
> > > different
> > > locale definitions, therefore its size is relatively small.
> > > 
> > > Add support for localised messages from core packages
> > > (LC_MESSAGES).
> > 
> > Do we really need this in the initramfs?
> 
> It's a killer functionality !!! And it requires very little extra disk
> space compared to the actual initramfs. You know, we tend not to use
> the floppy disk anymore nowadays !...

Linux runs on platforms you cannot lift, but it may run on platforms you
can hardly see. Dracut is meant to be platform independent and may also
run on platforms which memory/storage devices are very expensive or just
very small.

In general initramfs is precious.

Without having a closer look at the whole patchset.., but if this gets
in, it should certainly be configurable or a separate module
(10i18n_full?) if this is possible.

How much would the initrd about grow in a real number?

   Thomas

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v9] dracut: add support for custom locale definitions
  2016-05-17 10:12                                           ` Thomas Renninger
@ 2016-05-17 12:36                                             ` Guido Trentalancia
  0 siblings, 0 replies; 24+ messages in thread
From: Guido Trentalancia @ 2016-05-17 12:36 UTC (permalink / raw)
  To: Thomas Renninger; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA

Hello Thomas !

Sorry for my late reply...

On Thu, 17/05/2016 at 12.12 +0200, Thomas Renninger wrote:
> On Thursday, April 21, 2016 02:30:41 PM Guido Trentalancia wrote:
> > Hello Harald !
> > 
> > On Thu, 21/04/2016 Guido Trentalancia wrote:
> > > > Compile and install locale definitions using localedef from GNU
> > > > libc or,
> > > > if locale definitions cannot be compiled but are available on
> > > > the
> > > > system
> > > > as split definitions, just install them.
> > > > 
> > > > The resulting locale definitions archive contains at most two
> > > > different
> > > > locale definitions, therefore its size is relatively small.
> > > > 
> > > > Add support for localised messages from core packages
> > > > (LC_MESSAGES).
> > > 
> > > Do we really need this in the initramfs?
> > 
> > It's a killer functionality !!! And it requires very little extra
> > disk
> > space compared to the actual initramfs. You know, we tend not to
> > use
> > the floppy disk anymore nowadays !...
> 
> Linux runs on platforms you cannot lift, but it may run on platforms
> you
> can hardly see. Dracut is meant to be platform independent and may
> also
> run on platforms which memory/storage devices are very expensive or
> just
> very small.
> 
> In general initramfs is precious.

I agree with you.

> Without having a closer look at the whole patchset.., but if this
> gets
> in, it should certainly be configurable or a separate module
> (10i18n_full?) if this is possible.

It is already configurable (and enabled by default, as we cannot
predict the user knows the English language).

Please use --msg-localisation and --no-msg-localisation to enable and
disable the feature.

> How much would the initrd about grow in a real number?

The difference between a 4.5.4 kernel initramfs fully localised with
the Italian language and a 4.5.4 kernel initramfs without full
localisation support (English-only messages) is 810 kilobytes.

> 
>    Thomas
> 


Best regards,

Guido

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v9] dracut: add support for custom locale definitions
       [not found]                                             ` <1461430242.2604.15.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
  2016-05-06 15:01                                               ` Guido Trentalancia
@ 2017-10-11 13:17                                               ` Harald Hoyer
  1 sibling, 0 replies; 24+ messages in thread
From: Harald Hoyer @ 2017-10-11 13:17 UTC (permalink / raw)
  To: initramfs-u79uwXL29TY76Z2rM5mHXA

Please file a pull request on https://github.com/dracutdevs/dracut


On 23.04.2016 18:50, Guido Trentalancia wrote:
> Compile and install locale definitions using localedef from GNU libc or,
> if locale definitions cannot be compiled but are available on the system
> as split definitions, just install them.
> 
> The resulting locale definitions archive contains at most two different
> locale definitions, therefore its size is relatively small.
> 
> Add support for localised messages from core packages (LC_MESSAGES).
> 
> Add support for non-latin fonts using Unicode (tested successfully with
> Greek, Hebrew and Cyrillic).
> 
> This revised version fixes several issues in the initial patch (including
> the possibility to build locale definitions). Thanks to Andrei Borzenkov
> for reviewing the initial patch and providing useful suggestions.
> 
> Thanks for Harald Hoyer for the full style review and other useful
> suggestions.
> 
> Signed-off-by: Guido Trentalancia <guido-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
> ---
>  NEWS                                  |    4 +
>  dracut-bash-completion.sh             |   11 +--
>  dracut-init.sh                        |   37 ++++++++++
>  dracut.8.asc                          |    8 ++
>  dracut.conf.5.asc                     |   14 ++-
>  dracut.sh                             |   20 ++++-
>  modules.d/10i18n/README               |    1
>  modules.d/10i18n/console_init.sh      |   58 +++++++++++-----
>  modules.d/10i18n/module-setup.sh      |  123 +++++++++++++++++++++++++++++++++-
>  modules.d/10i18n/parse-i18n.sh        |    8 +-
>  modules.d/90crypt/module-setup.sh     |    6 +
>  modules.d/91crypt-gpg/module-setup.sh |    6 +
>  modules.d/99base/init.sh              |    4 -
>  modules.d/99base/module-setup.sh      |    4 +
>  modules.d/99base/profile              |    9 ++
>  15 files changed, 275 insertions(+), 38 deletions(-)
> 
> diff -pruN dracut-git-orig/dracut.8.asc dracut-git-10i18n-full-support-for-localisation/dracut.8.asc
> --- dracut-git-orig/dracut.8.asc	2016-04-19 02:19:10.650042399 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut.8.asc	2016-04-21 17:13:53.043188284 +0200
> @@ -358,6 +358,14 @@ provide a valid _/etc/fstab_.
>      LVM or an encrypted partition.
>      [NB --device can be used for compatibility with earlier releases]
>  
> +**--msg-localisation**::
> +    Include full localisation support for the i18n module (slightly increases
> +    the initramfs size).
> +
> +**--no-msg-localisation**::
> +    Do not include full localisation support for the i18n module (to save
> +    storage space or force the default locale).
> +
>  **-i, --include** _<SOURCE>_ _<TARGET>_::
>      include the files in the SOURCE directory into the
>      TARGET directory in the final initramfs. If SOURCE is a file, it will be
> diff -pruN dracut-git-orig/dracut-bash-completion.sh dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh
> --- dracut-git-orig/dracut-bash-completion.sh	2016-04-19 02:19:10.648042373 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut-bash-completion.sh	2016-04-21 17:16:41.148400079 +0200
> @@ -28,11 +28,12 @@ _dracut() {
>                                --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
>                                --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
>                                --lvmconf --nolvmconf --debug --profile --verbose --quiet
> -                              --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
> -                              --xz --no-compress --gzip --list-modules --show-modules --keep
> -                              --printsize --regenerate-all --noimageifnotneeded --early-microcode
> -                              --no-early-microcode --print-cmdline --prelink --noprelink --reproducible
> -                              --uefi
> +                              --local --hostonly --no-hostonly --fstab --msg-localisation
> +                              --no-msg-localisation --help --bzip2 --lzma --xz --no-compress
> +                              --gzip --list-modules --show-modules --keep --printsize
> +                              --regenerate-all --noimageifnotneeded --early-microcode
> +                              --no-early-microcode --print-cmdline --prelink --noprelink
> +                              --reproducible --uefi
>                                '
>  
>                         [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
> diff -pruN dracut-git-orig/dracut.conf.5.asc dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc
> --- dracut-git-orig/dracut.conf.5.asc	2016-04-19 02:19:10.650042399 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut.conf.5.asc	2016-04-21 17:21:57.576555027 +0200
> @@ -99,9 +99,6 @@ Configuration files must have the extens
>  *hostonly_cmdline=*"__{yes|no}__"::
>      If set, store the kernel command line arguments needed in the initramfs
>  
> -*i18n_install_all=*"__{yes|no}__"::
> -    If set to yes, install all available fonts and keyboard files.
> -
>  *persistent_policy=*"__<policy>__"::
>      Use _<policy>_ to address disks and partitions.
>      _<policy>_ can be any directory name found in /dev/disk.
> @@ -196,7 +193,16 @@ provide a valid _/etc/fstab_.
>      Default is "LatArCyrHeb-16".
>  
>  *i18n_install_all=*"__{yes|no}__"::
> -    Install everything regardless of generic or hostonly mode.
> +    Install all available fonts and keyboard files regardless of generic
> +    or hostonly mode.
> +
> +*msg-localisation=*"__{yes|no}__"::
> +    Add full localisation support (includes message-based localisation
> +    and non latin font support).
> +
> +*no-msg-localisation=*"__{yes|no}__"::
> +    Do not add full localisation support (only keyboard localisation
> +    is added): saves some storage space.
>  
>  *reproducible=*"__{yes|no}__"::
>      Create reproducible images.
> diff -pruN dracut-git-orig/dracut-init.sh dracut-git-10i18n-full-support-for-localisation/dracut-init.sh
> --- dracut-git-orig/dracut-init.sh	2016-04-19 02:19:10.649042386 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut-init.sh	2016-04-22 18:05:08.033519479 +0200
> @@ -214,6 +214,43 @@ inst_multiple() {
>      return $_ret
>  }
>  
> +# Install package translations (message-based localisations)
> +inst_i18n() {
> +    local _locale_dirs_dup
> +    local _locale_dirs
> +    local _tmppath
> +    [[ $1 ]] || return 1  # no package name
> +    [ -f /etc/locale.conf ] && . /etc/locale.conf
> +    if [ ${LC_ALL} ]; then
> +        read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
> +    fi
> +    if [ ${LANG} ]; then
> +        read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
> +    fi
> +    if [ ${LC_MESSAGES} ]; then
> +        read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
> +    fi
> +    [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
> +    [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
> +    [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
> +    _locale_dirs_dup="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} ${LC_MESSAGES_LOCALE_SHORT}"
> +    _tmppath=
> +    _locale_dirs=
> +    for dir in ${_locale_dirs_dup}
> +    do
> +        case $_tmppath in
> +            *\ ${dir}) ;;
> +            *) _locale_dirs="${_tmppath} ${dir}";;
> +        esac
> +        _tmppath=${_locale_dirs}
> +    done
> +    for dir in ${_locale_dirs}; do
> +        [[ -d "/usr/share/locale/${dir}" ]] && for file in `find "/usr/share/locale/${dir}" -type f -name "$1.mo"`; do
> +            inst_simple "${file}"
> +        done
> +    done
> +}
> +
>  dracut_install() {
>      inst_multiple "$@"
>  }
> diff -pruN dracut-git-orig/dracut.sh dracut-git-10i18n-full-support-for-localisation/dracut.sh
> --- dracut-git-orig/dracut.sh	2016-04-19 02:19:10.652042425 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/dracut.sh	2016-04-21 23:06:34.022740183 +0200
> @@ -163,6 +163,10 @@ Creates initial ramdisk images for prelo
>    --mount "[MP]"	Same as above, but [DEV], [FSTYPE] and [FSOPTS] are
>  			determined by looking at the current mounts.
>    --add-device "[DEV]"  Bring up [DEV] in initramfs
> +  --msg-localisation    Add full localisation support rather than only
> +                        the minimal keyboard support (default)
> +  --no-msg-localisation Do not add full localisation support, but only
> +                        minimal keyboard support
>    -i, --include [SOURCE] [TARGET]
>                          Include the files in the SOURCE directory into the
>                           Target directory in the final initramfs.
> @@ -344,6 +348,8 @@ rearrange_params()
>          --long no-hostonly-cmdline \
>          --long persistent-policy: \
>          --long fstab \
> +        --long msg-localisation \
> +        --long no-msg-localisation \
>          --long help \
>          --long bzip2 \
>          --long lzma \
> @@ -538,6 +544,10 @@ while :; do
>          --persistent-policy)
>                         persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
>          --fstab)       use_fstab_l="yes" ;;
> +        --msg-localisation)
> +                       msg_localisation_l="yes" ;;
> +        --no-msg-localisation)
> +                       msg_localisation_l="no" ;;
>          -h|--help)     long_usage; exit 1 ;;
>          -i|--include)  include_src+=("$2");          PARMS_TO_STORE+=" '$2'";
>                         shift;;
> @@ -730,6 +740,8 @@ stdloglvl=$((stdloglvl + verbosity_mod_l
>  [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
>  [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
>  [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
> +[[ $msg_localisation_l ]] && msg_localisation=$msg_localisation_l
> +[[ $msg_localisation_l ]] || msg_localisation="yes"
>  [[ $mdadmconf_l ]] && mdadmconf=$mdadmconf_l
>  [[ $lvmconf_l ]] && lvmconf=$lvmconf_l
>  [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
> @@ -1269,10 +1281,10 @@ export initdir dracutbasedir \
>      mods_to_load \
>      fw_dir drivers_dir debug no_kernel kernel_only \
>      omit_drivers mdadmconf lvmconf root_dev \
> -    use_fstab fstab_lines libdirs fscks nofscks ro_mnt \
> -    stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
> -    debug host_fs_types host_devs swap_devs sshkey add_fstab \
> -    DRACUT_VERSION udevdir prefix filesystems drivers \
> +    use_fstab fstab_lines msg_localisation libdirs fscks \
> +    nofscks ro_mnt stdloglvl sysloglvl fileloglvl kmsgloglvl \
> +    logile debug host_fs_types host_devs swap_devs sshkey \
> +    add_fstab DRACUT_VERSION udevdir prefix filesystems drivers \
>      systemdutildir systemdsystemunitdir systemdsystemconfdir \
>      hostonly_cmdline loginstall \
>      tmpfilesdir
> diff -pruN dracut-git-orig/modules.d/10i18n/console_init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh
> --- dracut-git-orig/modules.d/10i18n/console_init.sh	2016-04-20 14:11:02.824944921 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/console_init.sh	2016-04-22 17:54:50.913345284 +0200
> @@ -6,6 +6,7 @@ if [ -x $systemdutildir/systemd-vconsole
>      $systemdutildir/systemd-vconsole-setup "$@"
>  fi
>  
> +[ -e /etc/locale.conf ] && . /etc/locale.conf
>  [ -e /etc/vconsole.conf ] && . /etc/vconsole.conf
>  
>  DEFAULT_FONT=LatArCyrHeb-16
> @@ -19,14 +20,14 @@ set_keyboard() {
>  }
>  
>  set_terminal() {
> -    local dev=$1
> -
>      if [ "${UNICODE}" = 1 ]; then
> -        printf '\033%%G' >&7
> -        stty -F ${dev} iutf8
> +        if [ "${FONT}" -a ! "${FONT_MAP}" ]; then
> +            /usr/bin/unicode_start "${FONT}"
> +        elif [ "${FONT}" -a "${FONT_MAP}" ]; then
> +            /usr/bin/unicode_start "${FONT}" "${FONT_MAP}"
> +        fi
>      else
> -        printf '\033%%@' >&7
> -        stty -F ${dev} -iutf8
> +        /usr/bin/unicode_stop
>      fi
>  }
>  
> @@ -44,16 +45,6 @@ set_keymap() {
>      loadkeys -q ${utf_switch} ${KEYMAP} ${EXT_KEYMAPS}
>  }
>  
> -set_font() {
> -    local dev=$1; local trans=''; local uni=''
> -
> -    [ -z "${FONT}" ] && FONT=${DEFAULT_FONT}
> -    [ -n "${FONT_MAP}" ] && trans="-m ${FONT_MAP}"
> -    [ -n "${FONT_UNIMAP}" ] && uni="-u ${FONT_UNIMAP}"
> -
> -    setfont ${FONT} -C ${dev} ${trans} ${uni}
> -}
> -
>  dev_close() {
>      exec 6>&-
>      exec 7>&-
> @@ -74,6 +65,27 @@ devname=${dev#/dev/}
>      exit 1
>  }
>  
> +if [ "${UNICODE}" ]; then
> +    if [ "${UNICODE}" = YES -o "${UNICODE}" = yes -o "${UNICODE}" = 1 ]; then
> +        UNICODE=1
> +    elif [ "${UNICODE}" = NO -o "${UNICODE}" = no -o "${UNICODE}" = 0 ]; then
> +        UNICODE=0
> +    else
> +        UNICODE=''
> +    fi
> +fi
> +if [ ! "${UNICODE}" ]; then
> +    IFS=.
> +    set -- $LANG
> +    tail=$2
> +    IFS=-
> +    set -- $tail
> +    type=$1
> +    if [ "${type}" = "UTF" ]; then
> +        UNICODE=1
> +    fi
> +fi
> +
>  dev_open ${dev}
>  
>  for fd in 6 7; do
> @@ -84,9 +96,19 @@ for fd in 6 7; do
>      fi
>  done
>  
> +# Immediately after booting up, the
> +# display driver needs to settle,
> +# otherwise the Unicode mode cannot
> +# be enabled and the non latin
> +# characters do not render properly.
> +if [ -d /usr/share/locale ]; then
> +    if [ ! -e /tmp/dracut-vga-init-complete ]; then
> +        sleep 2 && :> /tmp/dracut-vga-init-complete
> +    fi
> +fi
> +
>  set_keyboard
> -set_terminal ${dev}
> -set_font ${dev}
> +set_terminal
>  set_keymap
>  
>  dev_close
> diff -pruN dracut-git-orig/modules.d/10i18n/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh
> --- dracut-git-orig/modules.d/10i18n/module-setup.sh	2016-04-22 14:25:26.949983919 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/module-setup.sh	2016-04-23 18:23:14.911103135 +0200
> @@ -4,7 +4,11 @@
>  check() {
>      [[ "$mount_needs" ]] && return 1
>  
> -    require_binaries setfont loadkeys kbd_mode || return 1
> +    require_binaries setfont loadkeys kbd_mode unicode_start unicode_stop
> +
> +    if [[ $msg_localisation == "yes" ]]; then
> +        require_binaries stty tty tset reset sleep || return 1
> +    fi
>  
>      return 0
>  }
> @@ -27,6 +31,11 @@ install() {
>      I18N_CONF="/etc/locale.conf"
>      VCONFIG_CONF="/etc/vconsole.conf"
>  
> +    # Core packages: always install the message-based localisation
> +    if [[ $msg_localisation == "yes" ]]; then
> +        CORE_PACKAGES="libc bash coreutils util-linux e2fsprogs grep sed kbd"
> +    fi
> +
>      # This is from 10redhat-i18n.
>      findkeymap () {
>          local MAP=$1
> @@ -93,7 +102,11 @@ install() {
>      }
>  
>      install_base() {
> -        inst_multiple setfont loadkeys kbd_mode stty
> +        inst_multiple setfont loadkeys kbd_mode unicode_start unicode_stop
> +
> +        if [[ $msg_localisation == "yes" ]]; then
> +            inst_multiple stty tty tset reset sleep
> +        fi
>  
>          if ! dracut_module_included "systemd"; then
>              inst ${moddir}/console_init.sh /lib/udev/console_init
> @@ -212,11 +225,115 @@ install() {
>              inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
>          fi
>  
> +        if [[ $msg_localisation == "yes" ]]; then
> +            [[ ${LC_ALL} || ${LANG} || ${LC_MESSAGES} ]] && inst_dir /usr/lib/locale
> +
> +            # Check if we can compile locale definitions
> +            if command -v localedef > /dev/null; then
> +                HAS_LOCALEDEF=true
> +            else
> +                HAS_LOCALEDEF=false
> +            fi
> +            if [ ${LC_ALL} ]; then
> +                read LC_ALL_LOCALE LC_ALL_CHARMAP < <(echo ${LC_ALL//./ })
> +            fi
> +            if [ ${LANG} ]; then
> +                read LANG_LOCALE LANG_CHARMAP < <(echo ${LANG//./ })
> +            fi
> +            if [ ${LC_MESSAGES} ]; then
> +                read LC_MESSAGES_LOCALE LC_MESSAGES_CHARMAP < <(echo ${LC_MESSAGES//./ })
> +            fi
> +
> +            # Generate locale definitions for LC_ALL or install compiled split
> +            # definitions where available
> +            if [[ ${LC_ALL} && ${LC_ALL_LOCALE} && ${LC_ALL_CHARMAP} ]]; then
> +                if [[ ${HAS_LOCALEDEF} == true && -e /usr/share/i18n/locales/${LC_ALL_LOCALE} ]]; then
> +                    localedef --prefix="${initdir}" -i ${LC_ALL_LOCALE} -f ${LC_ALL_CHARMAP} ${LC_ALL}
> +                elif [ -d "/usr/lib/locale/${LC_ALL}" ]; then
> +                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_ALL}
> +                fi
> +            fi
> +
> +            # Generate locale definitions for LANG or install compiled split
> +            # definitions where available
> +            if [[ ${LANG} && ${LANG_LOCALE} && ${LANG_CHARMAP} ]]; then
> +                if [[ ${HAS_LOCALEDEF} == true && -e /usr/share/i18n/locales/${LANG_LOCALE} ]]; then
> +                    localedef --prefix="${initdir}" -i ${LANG_LOCALE} -f ${LANG_CHARMAP} ${LANG}
> +                elif [ -d "/usr/lib/locale/${LANG}" ]; then
> +                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LANG}
> +                fi
> +            fi
> +
> +            # Generate locale definitions for LC_MESSAGES of install compiled split
> +            # definitions where available
> +            if [[ ${LC_MESSAGES} && ${LC_MESSAGES_LOCALE} && ${LC_MESSAGES_CHARMAP} ]]; then
> +                if [[ ${HAS_LOCALEDEF} == true && -e /usr/share/i18n/locales/${LC_MESSAGES_LOCALE} ]]; then
> +                    localedef --prefix="${initdir}" -i ${LC_MESSAGES_LOCALE} -f ${LC_MESSAGES_CHARMAP} ${LC_MESSAGES}
> +                elif [ -d "/usr/lib/locale/${LC_MESSAGES}" ]; then
> +                    cp -prfL -t "${initdir}/usr/lib/locale/" /usr/lib/locale/${LC_MESSAGES}
> +                fi
> +            fi
> +
> +            # Install individual localisation files for core packages
> +            [ -e /usr/share/locale/locale.alias ] && inst_simple /usr/share/locale/locale.alias
> +            [[ ${LC_ALL_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE}"
> +            [[ ${LANG_LOCALE} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE}"
> +            [[ ${LC_MESSAGES_LOCALE} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE}"
> +            [[ ${LC_ALL_LOCALE} ]] && read LC_ALL_LOCALE_SHORT LC_ALL_LOCALE_COUNTRY < <(echo ${LC_ALL_LOCALE//_/ })
> +            [[ ${LANG_LOCALE} ]] && read LANG_LOCALE_SHORT LANG_LOCALE_COUNTRY < <(echo ${LANG_LOCALE//_/ })
> +            [[ ${LC_MESSAGES_LOCALE} ]] && read LC_MESSAGES_LOCALE_SHORT LC_MESSAGES_LOCALE_COUNTRY < <(echo ${LC_MESSAGES_LOCALE//_/ })
> +            [[ ${LC_ALL_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_ALL_LOCALE_SHORT}"
> +            [[ ${LANG_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LANG_LOCALE_SHORT}"
> +            [[ ${LC_MESSAGES_LOCALE_SHORT} ]] && inst_dir "/usr/share/locale/${LC_MESSAGES_LOCALE_SHORT}"
> +
> +            locale_dirs="${LC_ALL_LOCALE} ${LANG_LOCALE} ${LC_MESSAGES_LOCALE} ${LC_ALL_LOCALE_SHORT} ${LANG_LOCALE_SHORT} {LC_MESSAGES_LOCALE_SHORT}"
> +            for dir in ${locale_dirs}; do
> +                [ -d "/usr/share/locale/${dir}" ] && for pkg in ${CORE_PACKAGES}; do
> +                    for file in `find "/usr/share/locale/${dir}" -type f -name "${pkg}.mo"`; do
> +                        inst_simple "${file}"
> +                    done
> +                done
> +            done
> +
> +            # Install ISO-8859 and Unicode charmap modules from GNU libc
> +            if [ -e "${initdir}/lib/ld-linux.so.*" ]; then
> +                LIBDIR=lib
> +            else
> +                LIBDIR=lib64
> +            fi
> +            inst_multiple /usr/${LIBDIR}/gconv/ISO8859-*.so
> +            if [ ${UNICODE} == 1 ]; then
> +                inst_multiple /usr/${LIBDIR}/gconv/UTF-*.so /usr/${LIBDIR}/gconv/UNICODE.so
> +            fi
> +            if command -v iconvconfig > /dev/null; then
> +                if [ -e /usr/${LIBDIR}/gconv/gconv-modules ]; then
> +                    grep -E "^[[:space:]]*alias[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules > /tmp/gconv-modules
> +                    if [ ${UNICODE} == 1 ]; then
> +                        grep -E "^[[:space:]]*alias.*UTF-" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
> +                        grep -E "^[[:space:]]*alias.*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules >> /tmp/gconv-modules
> +                    fi
> +                    grep -E "^[[:space:]]*module[[:space:]]*ISO[-]*8859-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
> +                    if [ ${UNICODE} == 1 ]; then
> +                        grep -E "^[[:space:]]*module[[:space:]]*UTF-" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
> +                        grep -E "^[[:space:]]*module[[:space:]]*UNICODE" /usr/${LIBDIR}/gconv/gconv-modules | grep INTERNAL >> /tmp/gconv-modules
> +                    fi
> +                    if [ -e /tmp/gconv-modules ]; then
> +                        inst /tmp/gconv-modules /usr/${LIBDIR}/gconv/gconv-modules && rm -f /tmp/gconv-modules
> +                    fi
> +                fi
> +                iconvconfig --prefix="${initdir}"
> +            else
> +                if [ -e /usr/${LIBDIR}/gconv/gconv-modules.cache ]; then
> +                    inst_simple /usr/${LIBDIR}/gconv/gconv-modules.cache
> +                fi
> +            fi
> +        fi
> +
>          if dracut_module_included "systemd" && [[ -f ${I18N_CONF} ]]; then
>              inst_simple ${I18N_CONF}
>          else
>              mksubdirs ${initdir}${I18N_CONF}
> -            print_vars LC_ALL LANG >> ${initdir}${I18N_CONF}
> +            print_vars LANG LC_ALL LC_MESSAGES >> ${initdir}${I18N_CONF}
>          fi
>  
>          if dracut_module_included "systemd" && [[ -f ${VCONFIG_CONF} ]]; then
> diff -pruN dracut-git-orig/modules.d/10i18n/parse-i18n.sh dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh
> --- dracut-git-orig/modules.d/10i18n/parse-i18n.sh	2016-04-20 14:11:02.825944933 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/parse-i18n.sh	2016-04-19 02:26:46.617644187 +0200
> @@ -23,11 +23,13 @@ inst_key_val /etc/vconsole.conf FONT_UNI
>  inst_key_val /etc/vconsole.conf UNICODE      1 rd.vconsole.font.unicode UNICODE vconsole.unicode
>  inst_key_val /etc/vconsole.conf EXT_KEYMAP  '' rd.vconsole.keymap.ext   EXT_KEYMAP
>  
> -inst_key_val /etc/locale.conf   LANG        '' rd.locale.LANG           LANG
> -inst_key_val /etc/locale.conf   LC_ALL      '' rd.locale.LC_ALL         LC_ALL
> -
> +inst_key_val /etc/locale.conf   LANG              '' rd.locale.LANG               LANG
> +inst_key_val /etc/locale.conf   LC_ALL            '' rd.locale.LC_ALL             LC_ALL
> +inst_key_val /etc/locale.conf   LC_MESSAGES       '' rd.locale.LC_MESSAGES        LC_MESSAGES
> + 
>  if [ -f /etc/locale.conf ]; then
>      . /etc/locale.conf
>      export LANG
>      export LC_ALL
> +    export LC_MESSAGES
>  fi
> diff -pruN dracut-git-orig/modules.d/10i18n/README dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README
> --- dracut-git-orig/modules.d/10i18n/README	2016-04-20 14:11:02.826944946 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/10i18n/README	2016-04-19 02:26:46.617644187 +0200
> @@ -65,6 +65,7 @@ I'm leaving it in case...  The following
>  
>      LANG
>      LC_ALL
> +    LC_MESSAGES
>  
>  If UNICODE variable is not provided, script indicates if UTF-8 should be
>  used on the basis of LANG value (if it ends with ".utf8" or similar).
> diff -pruN dracut-git-orig/modules.d/90crypt/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh
> --- dracut-git-orig/modules.d/90crypt/module-setup.sh	2016-04-19 02:19:10.662042554 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/90crypt/module-setup.sh	2016-04-23 17:09:50.584472072 +0200
> @@ -88,6 +88,12 @@ install() {
>  
>      inst_simple "$moddir/crypt-lib.sh" "/lib/dracut-crypt-lib.sh"
>  
> +    if dracut_module_included "i18n"; then
> +        if [[ $msg_localisation == "yes" ]]; then
> +            inst_i18n cryptsetup
> +        fi
> +    fi
> +
>      if dracut_module_included "systemd"; then
>          inst_multiple -o \
>                        $systemdutildir/system-generators/systemd-cryptsetup-generator \
> diff -pruN dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh
> --- dracut-git-orig/modules.d/91crypt-gpg/module-setup.sh	2016-04-19 02:19:10.667042618 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/91crypt-gpg/module-setup.sh	2016-04-23 17:10:10.783667188 +0200
> @@ -17,4 +17,10 @@ depends() {
>  install() {
>      inst_multiple gpg
>      inst "$moddir/crypt-gpg-lib.sh" "/lib/dracut-crypt-gpg-lib.sh"
> +
> +    if dracut_module_included "i18n"; then
> +        if [[ $msg_localisation == "yes" ]]; then
> +            inst_i18n gnupg
> +        fi
> +    fi
>  }
> diff -pruN dracut-git-orig/modules.d/99base/init.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh
> --- dracut-git-orig/modules.d/99base/init.sh	2016-04-20 14:11:02.826944946 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/init.sh	2016-04-20 14:02:01.578137511 +0200
> @@ -8,6 +8,8 @@
>  
>  export -p > /tmp/export.orig
>  
> +[ -f /etc/locale.conf ] && . /etc/locale.conf
> +
>  NEWROOT="/sysroot"
>  [ -d $NEWROOT ] || mkdir -p -m 0755 $NEWROOT
>  
> @@ -323,7 +325,7 @@ for i in $(export -p); do
>      i=${i%%=*}
>      [ -z "$i" ] && continue
>      case $i in
> -        root|PATH|HOME|TERM|PS4|RD_*)
> +        root|PATH|HOME|TERM|PS4|RD_*|LANG|LC_*)
>              :;;
>          *)
>              unset "$i";;
> diff -pruN dracut-git-orig/modules.d/99base/module-setup.sh dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh
> --- dracut-git-orig/modules.d/99base/module-setup.sh	2016-04-20 14:11:02.827944958 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/module-setup.sh	2016-04-21 20:01:54.611592039 +0200
> @@ -26,6 +26,10 @@ install() {
>          (ln -s bash "${initdir}/bin/sh" || :)
>      fi
>  
> +    if dracut_module_included "i18n"; then
> +       inst ${moddir}/profile /etc/profile
> +    fi
> +
>      #add common users in /etc/passwd, it will be used by nfs/ssh currently
>      grep '^root:' "$initdir/etc/passwd" 2>/dev/null || echo  'root:x:0:0::/root:/bin/sh' >> "$initdir/etc/passwd"
>      grep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
> diff -pruN dracut-git-orig/modules.d/99base/profile dracut-git-10i18n-full-support-for-localisation/modules.d/99base/profile
> --- dracut-git-orig/modules.d/99base/profile	1970-01-01 01:00:00.000000000 +0100
> +++ dracut-git-10i18n-full-support-for-localisation/modules.d/99base/profile	2016-04-21 23:43:08.049029619 +0200
> @@ -0,0 +1,9 @@
> +# /etc/profile
> +
> +# Load locale settings
> +if [ -f /etc/locale.conf ]; then
> +  . /etc/locale.conf
> +  [ -n "${LANG}" ] && export LANG || unset LANG
> +  [ -n "${LC_ALL}" ] && export LC_ALL || unset LC_ALL
> +  [ -n "${LC_MESSAGES}" ] && export LC_MESSAGES || unset LC_MESSAGES
> +fi
> diff -pruN dracut-git-orig/NEWS dracut-git-10i18n-full-support-for-localisation/NEWS
> --- dracut-git-orig/NEWS	2016-04-19 02:19:10.648042373 +0200
> +++ dracut-git-10i18n-full-support-for-localisation/NEWS	2016-04-21 17:00:46.436792093 +0200
> @@ -6,6 +6,7 @@ dracut now requires libkmod for the drac
>  dracut.sh:
>  - restorecon final image file
>  - fail hard, if we find modules and modules.dep is missing
> +- add an option to disable the new full localisation support
>  
>  dracut-functions.sh:
>  - fix check_vol_slaves() volume group name stripping
> @@ -34,6 +35,9 @@ general initramfs fixes:
>  - call dracut-cmdline-ask.service, if /etc/cmdline.d/*.conf exists
>  - break at switch_root only for bare rd.break
>  
> +i18n:
> +- add full localisation support (includes message-based localisation)
> +
>  dmsquash-live:
>  - fixed livenet-generator execution flag
>    and include only, if systemd is used
> --
> To unsubscribe from this list: send the line "unsubscribe initramfs" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2017-10-11 13:17 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-15 22:07 [PATCH] dracut: add support for custom locale definitions Guido Trentalancia
     [not found] ` <1460758050.3211.2.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-16  6:00   ` Andrei Borzenkov
     [not found]     ` <5711D4E7.9070705-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-16 14:12       ` [PATCH v2] dracut: 10i18n: " Guido Trentalancia
     [not found]         ` <1460815966.4296.13.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-16 17:52           ` Andrei Borzenkov
     [not found]             ` <57127BC9.70103-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-16 19:32               ` [PATCH v3] " Guido Trentalancia
     [not found]                 ` <1460835143.3201.10.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-16 20:13                   ` [PATCH v4] " Guido Trentalancia
     [not found]                     ` <1460837622.3201.14.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-16 20:24                       ` [PATCH v5] " Guido Trentalancia
     [not found]                         ` <1460838269.3201.18.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-19  0:36                           ` [PATCH v6] dracut: " Guido Trentalancia
     [not found]                             ` <1461026208.2262.1.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-20 13:04                               ` [PATCH v7] " Guido Trentalancia
     [not found]                                 ` <1461157491.11229.3.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-21 10:24                                   ` Harald Hoyer
     [not found]                                     ` <5718AA77.8090600-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-04-21 12:30                                       ` Guido Trentalancia
     [not found]                                         ` <1461241841.10934.12.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-21 12:41                                           ` Andrei Borzenkov
     [not found]                                             ` <CAA91j0U0XaJBaWNzBmRE3hs0zV7UKMEvO-6nBx_jaxkwhEHckg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-04-21 12:57                                               ` Guido Trentalancia
2016-04-21 13:07                                           ` Harald Hoyer
     [not found]                                             ` <5718D074.70507-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-21 13:48                                               ` Guido Trentalancia
2016-04-21 15:03                                               ` Guido Trentalancia
2016-05-17 10:12                                           ` Thomas Renninger
2016-05-17 12:36                                             ` [PATCH v9] " Guido Trentalancia
2016-04-22 16:13                                       ` [PATCH v8] " Guido Trentalancia
     [not found]                                         ` <1461341618.21231.0.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-04-23  7:50                                           ` Andrei Borzenkov
     [not found]                                             ` <571B2950.5060209-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-04-23 16:47                                               ` Guido Trentalancia
2016-04-23 16:50                                           ` [PATCH v9] " Guido Trentalancia
     [not found]                                             ` <1461430242.2604.15.camel-D1bseh+SzQhuxeB9wqlrNw@public.gmane.org>
2016-05-06 15:01                                               ` Guido Trentalancia
2017-10-11 13:17                                               ` Harald Hoyer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.