commonlib
commonlib copied to clipboard
Only set up default locale on FixMyStreet install.
FixMyStreet uses the default locale in order to have working URIs with floating point numbers. This could be moved to the FixMyStreet install script with its next release and then removed from here.
Have added commit to implement different locale setup. Would be good to have a number of eyes checking this @garethrees @mhl :)
Running against the puppetlabs/squeeze VM I get:
/vagrant/install.sh: line 53: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
Here's some more info: http://pastie.org/private/9ujduo5nfmqckjjoobsfxg
My terminal sends the locale I want
debug1: Sending env LANG = en_GB.UTF-8
and the script seems to generate it
Generating locale en_GB... done
but then we get the warning and the locale remains as en_US
/vagrant/install.sh: line 53: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
done
vagrant@debian-607-x64-vbox4210-nocm:~$ locale
LANG=en_US
After logging out and starting a new SSH session:
Linux debian-607-x64-vbox4210-nocm 2.6.32-5-amd64 #1 SMP Fri Feb 15 15:39:52 UTC 2013 x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jul 21 11:16:39 2014 from 192.168.33.1
-bash: warning: setlocale: LC_ALL: cannot change locale (en_GB.UTF-8)
vagrant@debian-607-x64-vbox4210-nocm:~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_GB.UTF-8
LANGUAGE=
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=en_GB.UTF-8
@garethrees You didn't set DISTRIBUTION in your miniscript, so en_GB.UTF-8 wasn't generated; I think that's the issue with that output anyway. I've pushed a sh/bash difference fix that I think is unrelated but I came across whilst looking. I think e.g. https://vagrantcloud.com/puppetlabs/debian-6.0.9-64-nocm is more up to date than ones at puppetlabs.com (and has en_US.UTF-8 instead of en_US as the default, interestingly).
Separate issue - if LANG is an okay UTF-8, but not installed on the server, my first if will fail because you can't yet set LC_ALL in order to call locale and check its charmap. Also call to add_locale expects just first half of locale line, without UTF-8, which this doesn't do, and not sure its [ is correct. I guess it could just look for utf-8 in $LANG and strip/assume that's enough, seems likely that it would be?
You didn't set DISTRIBUTION in your miniscript
Oops. Updated http://pastie.org/private/dnl3fu91emrgxdwl9dsq (including 975e309).
add_locale seems to be writing literal \n in to /etc/locale.gen:
$ tail -n 4 /etc/locale.gen
# zu_ZA ISO-8859-1
# zu_ZA.UTF-8 UTF-8
en_US ISO-8859-1
\nen_GB.UTF-8 UTF-8
Yes, that will happen if you run the install script with bash rather than sh as the instructions/Vagrantfile do, due to the differing behaviours of echo. That line is the same as it always has been, I guess it could use printf.
Ah, yeah, running through sh works. Sorry about that.
I notice it still needs a logout to pick up the new locale, but interestingly appending apt-get -y install postgres to the end of the script seems to install postgres with the correct encoding settings:
$ sudo su
# sudo -u postgres psql -c '\list'
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres
: postgres=CTc/postgres
(3 rows)