forked from ungleich-public/cdist
__locale: add state explorer
.. so it doesn't execute code all the time.
This commit is contained in:
parent
fded60bd0f
commit
a95eab77a5
2 changed files with 47 additions and 4 deletions
36
cdist/conf/type/__locale/explorer/state
Executable file
36
cdist/conf/type/__locale/explorer/state
Executable file
|
@ -0,0 +1,36 @@
|
|||
#!/bin/sh -e
|
||||
# __locale/explorer/state
|
||||
#
|
||||
# 2020 Matthias Stecher (matthiasstecher at gmx.de)
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#
|
||||
# Check if the locale is already installed on the system.
|
||||
# Outputs 'present' or 'absent' depending if the locale exists.
|
||||
#
|
||||
|
||||
|
||||
# Get user-defined locale
|
||||
# locale name is echoed differently than the user propably set it (for UTF-8)
|
||||
locale="$(echo "$__object_id" | sed 's/UTF-8/utf8/')"
|
||||
|
||||
# Check if the given locale exists on the system
|
||||
if localedef --list-archive | grep -qFx "$locale"; then
|
||||
echo present
|
||||
else
|
||||
echo absent
|
||||
fi
|
|
@ -23,6 +23,15 @@
|
|||
|
||||
locale="$__object_id"
|
||||
|
||||
state_is=$(cat "$__object/explorer/state")
|
||||
state_should=$(cat "$__object/parameter/state")
|
||||
|
||||
# short circuit if there is nothing to do
|
||||
if [ "$state_is" = "$state_should" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# Hardcoded, create a pull request with
|
||||
# branching on $os in case it is at another location
|
||||
alias=/usr/share/locale/locale.alias
|
||||
|
@ -35,8 +44,6 @@ charmap=$(echo "$locale" | cut -d . -f 2)
|
|||
# W-T-F!
|
||||
locale_remove=$(echo "$locale" | sed 's/UTF-8/utf8/')
|
||||
|
||||
state=$(cat "$__object/parameter/state")
|
||||
|
||||
os=$(cat "$__global/explorer/os")
|
||||
|
||||
# Nothing to be done on alpine
|
||||
|
@ -46,7 +53,7 @@ case "$os" in
|
|||
;;
|
||||
esac
|
||||
|
||||
case "$state" in
|
||||
case "$state_should" in
|
||||
present)
|
||||
echo localedef -A "$alias" -f "$charmap" -i "$input" "$locale"
|
||||
;;
|
||||
|
@ -54,7 +61,7 @@ case "$state" in
|
|||
echo localedef --delete-from-archive "$locale_remove"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported state: $state" >&2
|
||||
echo "Unsupported state: $state_should" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
Loading…
Reference in a new issue