From 87faffd8750cac94190707c2b37233229c3fbde2 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sat, 14 Nov 2020 10:41:50 +0100 Subject: [PATCH] [type/__localdef] Also check for aliases in state explorer --- cdist/conf/type/__localedef/explorer/state | 31 +++++++++++++++++++++- cdist/conf/type/__localedef/gencode-remote | 7 +++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__localedef/explorer/state b/cdist/conf/type/__localedef/explorer/state index d8db29c5..3ba57661 100755 --- a/cdist/conf/type/__localedef/explorer/state +++ b/cdist/conf/type/__localedef/explorer/state @@ -25,8 +25,14 @@ # the main locale (and possibly aliases) is present # absent: # neither the main locale nor any aliases are present +# alias-present: +# the main locale is absent, but at least one of its aliases is present # +# Hardcoded, create a pull request in case it is at another location for +# some other distro. (cf. gencode-remote) +aliasfile='/usr/share/locale/locale.alias' + command -v locale >/dev/null 2>&1 || exit 0 locales=$(locale -a) @@ -68,4 +74,27 @@ locale_available() ( } ) -locale_available "${__object_id:?}" && echo present || echo absent +if locale_available "${__object_id:?}" +then + echo present +else + # NOTE: locale.alias can be symlinked. + if test -e "${aliasfile}" + then + # Check if one of the aliases of the locale is defined + baselocale=$( + parse_locale "${__object_id:?}" _lang _codeset _modifiers \ + && format_locale "${_lang}" "${_codeset}") + while read -r _alias _localename + do + if test "${_localename}" = "${baselocale}" \ + && echo "${locales}" | grep -qxF "${_alias}" + then + echo alias-present + exit 0 + fi + done <"${aliasfile}" + fi + + echo absent +fi diff --git a/cdist/conf/type/__localedef/gencode-remote b/cdist/conf/type/__localedef/gencode-remote index d7fd6942..4538151f 100755 --- a/cdist/conf/type/__localedef/gencode-remote +++ b/cdist/conf/type/__localedef/gencode-remote @@ -94,9 +94,12 @@ in localedef --delete-from-archive "\${_alias}" fi done <'${aliasfile}' - - localedef --delete-from-archive '${main_localename}' EOF + + if test "${state_is}" = present + then + printf "localedef --delete-from-archive '%s'\n" "${main_localename}" + fi ;; esac ;;