2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2013-10-14 13:05:29 +00:00
|
|
|
#
|
2019-04-15 16:54:30 +00:00
|
|
|
# 2013-2019 Nico Schottelius (nico-cdist at schottelius.org)
|
2013-10-14 13:05:29 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2013-10-14 12:27:07 +00:00
|
|
|
|
2013-10-14 13:05:29 +00:00
|
|
|
locale="$__object_id"
|
|
|
|
|
2020-11-08 14:18:04 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2013-10-14 13:05:29 +00:00
|
|
|
# Hardcoded, create a pull request with
|
|
|
|
# branching on $os in case it is at another location
|
2013-10-14 12:38:47 +00:00
|
|
|
alias=/usr/share/locale/locale.alias
|
2013-10-14 12:27:07 +00:00
|
|
|
|
2013-10-14 13:05:29 +00:00
|
|
|
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/')
|
|
|
|
|
2019-04-15 16:56:51 +00:00
|
|
|
os=$(cat "$__global/explorer/os")
|
|
|
|
|
|
|
|
# Nothing to be done on alpine
|
|
|
|
case "$os" in
|
|
|
|
alpine)
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2020-11-08 14:18:04 +00:00
|
|
|
case "$state_should" in
|
2013-10-14 13:05:29 +00:00
|
|
|
present)
|
|
|
|
echo localedef -A "$alias" -f "$charmap" -i "$input" "$locale"
|
|
|
|
;;
|
|
|
|
absent)
|
|
|
|
echo localedef --delete-from-archive "$locale_remove"
|
|
|
|
;;
|
|
|
|
*)
|
2020-11-08 14:18:04 +00:00
|
|
|
echo "Unsupported state: $state_should" >&2
|
2013-10-14 13:05:29 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|