add state parameter
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								465749f377
							
						
					
				
			
			
				commit
				
					
						e7e610d829
					
				
			
		
					 5 changed files with 88 additions and 21 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,13 +10,7 @@ cdist-type__locale - Configure locales
 | 
			
		|||
 | 
			
		||||
DESCRIPTION
 | 
			
		||||
-----------
 | 
			
		||||
This cdist type allows you to setup the locales.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
REQUIRED MULTIPLE PARAMETERS
 | 
			
		||||
----------------------------
 | 
			
		||||
name::
 | 
			
		||||
    Specify the locale to be present
 | 
			
		||||
This cdist type allows you to setup locales.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
OPTIONAL PARAMETERS
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 <http://www.gnu.org/licenses/>.
 | 
			
		||||
#
 | 
			
		||||
#
 | 
			
		||||
# 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								cdist/conf/type/__locale/parameter/default/state
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__locale/parameter/default/state
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
present
 | 
			
		||||
							
								
								
									
										1
									
								
								cdist/conf/type/__locale/parameter/optional
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								cdist/conf/type/__locale/parameter/optional
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
state
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue