add state parameter

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-10-14 22:05:29 +09:00
parent 465749f377
commit e7e610d829
5 changed files with 88 additions and 21 deletions

View file

@ -1,7 +1,51 @@
#!/bin/sh
#
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Let localedef do the magic
#
locale=$__object_id locale="$__object_id"
input=$(echo $locale | cut -d . -f 1)
charmap=$(echo $locale | cut -d . -f 2) # Hardcoded, create a pull request with
# branching on $os in case it is at another location
alias=/usr/share/locale/locale.alias alias=/usr/share/locale/locale.alias
echo localedef -A "$alias" -f "$charmap" -i "$input" input=$(echo "$locale" | cut -d . -f 1)
charmap=$(echo "$locale" | cut -d . -f 2)
# Adding locale? The name is de_CH.UTF-8
# Removing locale? The name is de_CH.utf8.
# W-T-F!
locale_remove=$(echo "$locale" | sed 's/UTF-8/utf8/')
state=$(cat "$__object/parameter/state")
case "$state" in
present)
echo localedef -A "$alias" -f "$charmap" -i "$input" "$locale"
;;
absent)
echo localedef --delete-from-archive "$locale_remove"
;;
*)
echo "Unsupported state: $state" >&2
exit 1
;;
esac

View file

@ -10,13 +10,7 @@ cdist-type__locale - Configure locales
DESCRIPTION DESCRIPTION
----------- -----------
This cdist type allows you to setup the locales. This cdist type allows you to setup locales.
REQUIRED MULTIPLE PARAMETERS
----------------------------
name::
Specify the locale to be present
OPTIONAL PARAMETERS OPTIONAL PARAMETERS
@ -29,18 +23,21 @@ EXAMPLES
-------- --------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
# Configure locales en_US and de_CH, both as UTF8 # Add locale de_CH.UTF-8
__locale --name "en_US.UTF-8 UTF-8" \ __locale de_CH.UTF-8
--name "de_CH.UTF-8 UTF-8" \
de_DE.UTF-8 UTF-8
# Same as above, but more explicit
__locale de_CH.UTF-8 --state present
# Remove colourful British English
__locale en_GB.UTF-8 --state absent
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
SEE ALSO SEE ALSO
-------- --------
- locale(1) - locale(1)
- localedef(1)
- cdist-type(7) - cdist-type(7)

View file

@ -1,8 +1,32 @@
locales=$(cat "$__object/parameter/name") #!/bin/sh
state=$(cat "$__object/parameter/state") #
# 2013 Nico Schottelius (nico-cdist at schottelius.org)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Install required packages
#
__package locales --state $state os=$(cat "$__global/explorer/os")
__file /etc/locale.gen \
--mode 0644 \ case "$os" in
--source "$__object/parameter/name" debian)
# Debian needs a seperate package
__package locales --state present
;;
esac

View file

@ -0,0 +1 @@
present

View file

@ -0,0 +1 @@
state