Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix locale setting with openhabian.conf not working #1723

Merged
merged 2 commits into from
Sep 25, 2022

Conversation

florian-h05
Copy link
Contributor

Fixes #1721.

@mstormi Am I right with the following assumption?
Removed dpkg-reconfigure --frontend=noninteractive locales because it's only generating the locales, which is already done with locale-gen.

I tested the locale setup using openhabian.conf and the openhabian-config tool a few times, seems to work this time.
Maybe you could also test.

Signed-off-by: Florian Hotze florianh_dev@icloud.com

Fixes openhab#1721.
Removed `dpkg-reconfigure --frontend=noninteractive locales` because
it's only generating the locales, which is already done with
`locale-gen`.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@mstormi
Copy link
Contributor

mstormi commented Sep 25, 2022

@mstormi Am I right with the following assumption?

I don't know.

I tested the locale setup using openhabian.conf and the openhabian-config tool a few times, seems to work this time.

with that 'reconfigure' line removed ?
Did you check locale inside OH e.g. Komma als Trenner für Nachkommastellen ?

@florian-h05
Copy link
Contributor Author

with that 'reconfigure' line removed ?

Seems like reconfigure with the noniteractive frontend only generates the locales, see the command output compared to locale-gen:

openhabian@smarthomevm ~> sudo dpkg-reconfigure --frontend=noninteractive locales
[sudo] password for openhabian: 
Generating locales (this might take a while)...
  de_DE.UTF-8... done
  en_US.UTF-8... done
Generation complete.
openhabian@smarthomevm ~> sudo locale-gen
Generating locales (this might take a while)...
  de_DE.UTF-8... done
  en_US.UTF-8... done
Generation complete.

Moreover, the reconfigure line with noniteractive frontend does not change anything in /etc/default/locales, the interactive dialogue allows to select the default system locale LANG=.

@@ -161,10 +162,10 @@ locale_setting() {
done
if ! cond_redirect locale-gen; then echo "FAILED (locale-gen)"; return 1; fi
fi
if ! cond_redirect dpkg-reconfigure --frontend=noninteractive locales; then echo "FAILED (reconfigure locales)"; return 1; fi
# shellcheck disable=SC2154
syslocale=$system_default_locale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if system_default_locale is unset ?
And will /etc/default/locale be adapted to match system_default_locale (if set) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if system_default_locale is unset ?

Then en_US.UTF-8 will be used as defined in line 171:

if cond_redirect update-locale LANG="${syslocale:-en_US.UTF-8}" LC_ALL="${syslocale:-en_US.UTF-8}" LC_CTYPE="${syslocale:-en_US.UTF-8}" LANGUAGE="${syslocale:-en_US.UTF-8}"; then echo "OK (reboot required)"; else echo "FAILED"; return 1; fi

Use the following code snippet to verify that:

#!/bin/bash
# system_default_locale=de_DE.UTF-8

syslocale=$system_default_locale

echo ${syslocale:-en_US.UTF-8}

And will /etc/default/locale be adapted to match system_default_locale (if set) ?

update-locale automatically updates /etc/default/locale on every call.

Copy link
Contributor

@mstormi mstormi Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but update-locale is only called before your new line syslocale=$system_default_locale so does not have the value by then

Use defaults on assignments i.e. X=${Y:-z}, can even be X=${Y:-${Z:-z}}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but update-locale is only called before your new line syslocale=$system_default_locale so does not have the value by then

No, see:

# shellcheck disable=SC2154
    syslocale=$system_default_locale
  fi

  if cond_redirect update-locale LANG="${syslocale:-en_US.UTF-8}" LC_ALL="${syslocale:-en_US.UTF-8}" LC_CTYPE="${syslocale:-en_US.UTF-8}" LANGUAGE="${syslocale:-en_US.UTF-8}"; then echo "OK (reboot required)"; else echo "FAILED"; return 1; fi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use defaults on assignments i.e. X=${Y:-z}, can even be X=${Y:-${Z:-z}}

In the line syslocale=$system_default_locale?

Copy link
Contributor

@mstormi mstormi Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes and everywhere where appropriate never mind it should do

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the update-locale statement, for the syslocale var it is not required. (If interactive, an error is thrown if syslocale cant be assigned, and if unattened, syslocale gets a default from the assignment to system_default_locale.

Can I remove it?

Copy link
Contributor

@mstormi mstormi Sep 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if unattened, syslocale gets a default from the assignment to system_default_locale.

which is not guaranteed to be set as it's user-defined.

Can I remove it?

At some place you have to provide a default to apply to all use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my latest commit, I assign a default if system_default_locale is not set and we are in unattended mode.
If we are in interactive mode, syslocal can not be empty, because the function exits with an error if the assignment fails.

@florian-h05
Copy link
Contributor Author

Did you check locale inside OH e.g. Komma als Trenner für Nachkommastellen ?

I used the openhabian-configtool to switch to en-EN.UTF-8, rebooted and checked /etc/default/locale as well as the Trenner für Nachkommastellen ist Punkt in OH: changing the locale worked.
Then I again used the openhabian-config tool to switch back to de_DE.UTF-8, rebooted and checked the locale file as well as Komma als Trenner für Nachkommastellen in OH: changing the locale worked again.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Copy link
Contributor

@mstormi mstormi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright then, thanks!

@mstormi mstormi merged commit 139f2e0 into openhab:main Sep 25, 2022
@florian-h05 florian-h05 deleted the fix-locale-setting branch September 25, 2022 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

java locale ?
2 participants