From e7e610d8295095d45513121c31ac15efd1d7df41 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Mon, 14 Oct 2013 22:05:29 +0900 Subject: [PATCH] add state parameter Signed-off-by: Nico Schottelius --- cdist/conf/type/__locale/gencode-remote | 52 +++++++++++++++++-- cdist/conf/type/__locale/man.text | 19 +++---- cdist/conf/type/__locale/manifest | 36 ++++++++++--- .../type/__locale/parameter/default/state | 1 + cdist/conf/type/__locale/parameter/optional | 1 + 5 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 cdist/conf/type/__locale/parameter/default/state create mode 100644 cdist/conf/type/__locale/parameter/optional diff --git a/cdist/conf/type/__locale/gencode-remote b/cdist/conf/type/__locale/gencode-remote index ed8052a8..538ce2cd 100644 --- a/cdist/conf/type/__locale/gencode-remote +++ b/cdist/conf/type/__locale/gencode-remote @@ -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 . +# +# +# Let localedef do the magic +# -locale=$__object_id -input=$(echo $locale | cut -d . -f 1) -charmap=$(echo $locale | cut -d . -f 2) +locale="$__object_id" + +# Hardcoded, create a pull request with +# branching on $os in case it is at another location 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 diff --git a/cdist/conf/type/__locale/man.text b/cdist/conf/type/__locale/man.text index 9ed4a6d1..f76c2059 100644 --- a/cdist/conf/type/__locale/man.text +++ b/cdist/conf/type/__locale/man.text @@ -10,15 +10,9 @@ cdist-type__locale - Configure locales 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 ------------------- state:: @@ -29,18 +23,21 @@ EXAMPLES -------- -------------------------------------------------------------------------------- -# Configure locales en_US and de_CH, both as UTF8 -__locale --name "en_US.UTF-8 UTF-8" \ - --name "de_CH.UTF-8 UTF-8" \ - de_DE.UTF-8 UTF-8 +# Add locale de_CH.UTF-8 +__locale de_CH.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 -------- - locale(1) +- localedef(1) - cdist-type(7) diff --git a/cdist/conf/type/__locale/manifest b/cdist/conf/type/__locale/manifest index dd3f0f55..5dd5fd8f 100644 --- a/cdist/conf/type/__locale/manifest +++ b/cdist/conf/type/__locale/manifest @@ -1,8 +1,32 @@ -locales=$(cat "$__object/parameter/name") -state=$(cat "$__object/parameter/state") +#!/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 . +# +# +# Install required packages +# -__package locales --state $state +os=$(cat "$__global/explorer/os") -__file /etc/locale.gen \ - --mode 0644 \ - --source "$__object/parameter/name" + +case "$os" in + debian) + # Debian needs a seperate package + __package locales --state present + ;; +esac diff --git a/cdist/conf/type/__locale/parameter/default/state b/cdist/conf/type/__locale/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__locale/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__locale/parameter/optional b/cdist/conf/type/__locale/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__locale/parameter/optional @@ -0,0 +1 @@ +state