omega8cc/boa — pull request #447 by ar-jan (2014-10-05 21:59:34+00:00)
Title: Improve locales consistency

I've been doing some more reading and testing as follow-up to #398, and I think we can make some further improvements to locale handling.

There are some potential locale-related problems:

1. Regular expressions and LC_COLLATE
After reading [this explanation](http://unix.stackexchange.com/a/149129/20865), I believe we should enforce `LC_COLLATE=POSIX`:
LC_COLLATE impacts e.g. regular expressions, and since it can be overridden by an SSH client's settings, a default should be enforced and set to C or POSIX (these are equivalent).

I've done [this test](http://unix.stackexchange.com/q/15980/20865) on several systems, and at least on some the collation order is problematic:

root@boa1:~# echo B | LC_COLLATE=en_US grep '[a-z]'
B

While the Ubuntu and Debian 7 systems I tested did not show this behavior, Debian 6 on DigitalOcean does, for example.

2. LC_ environment variables take precedence over LANG
If locales are not UTF-8, BARRACUDA.sh.txt configures LANG and LANGUAGE as en_US.UTF-8 (and LC_ALL as empty) on the fly using `export`. While this overrides the LANG variable, LC_* environment variables that are set explicly take precedence over LANG, so we should explicitly define the important ones as defaults in /etc/default/locale:
LC_CTYPE and LC_COLLATE (and maybe also LC_NUMERIC?).
I think enforcing the desired LC_* variables explicitly is preferable to disabling `AcceptEnv LANG LC_*` in sshd_config.
In fact, during installation we should set all LC_* variables to en_US.UTF-8 on-the-fly (except LC_COLLATE, so we cannot use LC_ALL here), because otherwise we may still end up with locale error message throughout the installer log. ("Cannot set LC_ALL to default locale: No such file or directory".)

I believe this PR improves upon this. Some minor other changes:
- Simplified generating locales in Ubuntu
- Added the "Remove empty lines from /etc/locale.gen" commit for consistency with the other section in fix_locales
- Only exporting the LANG and LC_ variables seems sufficient (without echoing into /root/.bashrc)

Maybe:
- fix_locales is run three times in total. Is there a particular reason for that? I've tested the installer with just the first call to fix_locales, and that worked.
- add instructions to the _LOCALE_TEST=BROKEN message to install extra locales (as required by your SSH client), or possibly enforce en_US.UTF-8 for all LC_ variables.