From f6fb93f5e6e19e43f28d84a181ad8dc325e534df Mon Sep 17 00:00:00 2001 From: David Lutz Date: Wed, 2 May 2012 14:10:27 +0000 Subject: [PATCH] add support for CentOS and make more robust --- README.md | 19 ++++++++++++++++--- attributes/default.rb | 2 +- metadata.rb | 3 ++- recipes/default.rb | 25 ++++++++++++++++++++----- templates/default/locale.erb | 1 - 5 files changed, 39 insertions(+), 11 deletions(-) delete mode 100644 templates/default/locale.erb diff --git a/README.md b/README.md index 30ef2b8..3b0861e 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,30 @@ Description =========== -Sets system locale +Sets default system locale + +You can see which languages are available by +$ locale -a + +On debian based systems you can set the locale by running +# update-locale LANG={lang} +e.g. +# update-locale LANG=en_AU.utf8 + +It updates the file /etc/default/locale + +On rhel based systems you can set default locale updating /etc/sysconfig/i18n +There doesn't seem to be a command line tool to update this file?!? Requirements ============ -Tested on Ubuntu +Tested on Ubuntu, CentOS Attributes ========== -* `node[:locale][:lang]` -- defaults to "en_US.UTF-8" +* `node[:locale][:lang]` -- defaults to "en_US.utf8" Usage ===== diff --git a/attributes/default.rb b/attributes/default.rb index ff3b1be..1edaa68 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1 +1 @@ -default[:locale][:lang] = "en_US.UTF-8" +default[:locale][:lang] = "en_US.utf8" diff --git a/metadata.rb b/metadata.rb index 9bf7575..bb852f8 100644 --- a/metadata.rb +++ b/metadata.rb @@ -3,7 +3,8 @@ license "Apache 2.0" description "Installs/Configures locale" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.0.1" +version "0.0.2" supports "ubuntu" supports "debian" +supports "centos" diff --git a/recipes/default.rb b/recipes/default.rb index c6d9dd0..c4d4c7c 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -17,9 +17,24 @@ # limitations under the License. # -template "/etc/default/locale" do - source "locale.erb" - mode "644" - variables( :lang => node[:locale][:lang] ) - action :create_if_missing +if platform?("ubuntu", "debian") + + package "locales" do + action :install + end + + execute "Update locale" do + command "update-locale LANG=#{node[:locale][:lang]}" + action :nothing + end + +end + +if platform?("ubuntu", "redhat", "centos", "fedora") + + execute "Update locale" do + command "locale -a | grep ^#{node[:locale][:lang]}$ && sed -i 's|LANG=.*|LANG=#{node[:locale][:lang]}|' /etc/sysconfig/i18n" + end + end + diff --git a/templates/default/locale.erb b/templates/default/locale.erb deleted file mode 100644 index 230a8d8..0000000 --- a/templates/default/locale.erb +++ /dev/null @@ -1 +0,0 @@ -LANG=<%= @lang %> \ No newline at end of file