Merge branch 'feature/type/__locale_system/os-support' into 'master'
__locale_system: Wider OS support See merge request ungleich-public/cdist!914
This commit is contained in:
commit
5c5890d458
1 changed files with 151 additions and 14 deletions
|
@ -3,6 +3,7 @@
|
||||||
# 2012-2016 Steven Armstrong (steven-cdist at armstrong.cc)
|
# 2012-2016 Steven Armstrong (steven-cdist at armstrong.cc)
|
||||||
# 2016 Carlos Ortigoza (carlos.ortigoza at ungleich.ch)
|
# 2016 Carlos Ortigoza (carlos.ortigoza at ungleich.ch)
|
||||||
# 2016 Nico Schottelius (nico.schottelius at ungleich.ch)
|
# 2016 Nico Schottelius (nico.schottelius at ungleich.ch)
|
||||||
|
# 2020 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
|
||||||
#
|
#
|
||||||
# This file is part of cdist.
|
# This file is part of cdist.
|
||||||
#
|
#
|
||||||
|
@ -23,17 +24,151 @@
|
||||||
# Configure system-wide locale by modifying i18n file.
|
# Configure system-wide locale by modifying i18n file.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
key=$__object_id
|
||||||
|
onchange_cmd= # none, by default
|
||||||
|
quote_value=false
|
||||||
|
|
||||||
|
catval() {
|
||||||
|
# shellcheck disable=SC2059
|
||||||
|
printf "$($quote_value && echo '"%s"' || echo '%s')" "$(cat "$1")"
|
||||||
|
}
|
||||||
|
|
||||||
|
state_should=$(cat "${__object}/parameter/state")
|
||||||
|
|
||||||
os=$(cat "$__global/explorer/os")
|
os=$(cat "$__global/explorer/os")
|
||||||
|
|
||||||
case "$os" in
|
case $os
|
||||||
debian|devuan|ubuntu)
|
in
|
||||||
|
debian)
|
||||||
|
os_version=$(cat "${__global}/explorer/os_version")
|
||||||
|
if expr "${os_version}" '>=' 4 >/dev/null
|
||||||
|
then
|
||||||
|
# Debian 4 (etch) and later
|
||||||
locale_conf="/etc/default/locale"
|
locale_conf="/etc/default/locale"
|
||||||
|
else
|
||||||
|
locale_conf="/etc/environment"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
devuan)
|
||||||
|
locale_conf="/etc/default/locale"
|
||||||
|
;;
|
||||||
|
ubuntu)
|
||||||
|
os_version=$(cat "${__global}/explorer/os_version")
|
||||||
|
if expr "${os_version}" '>=' 6.10 >/dev/null
|
||||||
|
then
|
||||||
|
# Ubuntu 6.10 (edgy) and later
|
||||||
|
locale_conf="/etc/default/locale"
|
||||||
|
else
|
||||||
|
locale_conf="/etc/environment"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
archlinux)
|
archlinux)
|
||||||
locale_conf="/etc/locale.conf"
|
locale_conf="/etc/locale.conf"
|
||||||
;;
|
;;
|
||||||
redhat|centos)
|
centos|redhat|scientific)
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}")
|
||||||
|
if expr "${version_id}" '>=' 7 >/dev/null
|
||||||
|
then
|
||||||
|
locale_conf="/etc/locale.conf"
|
||||||
|
else
|
||||||
locale_conf="/etc/sysconfig/i18n"
|
locale_conf="/etc/sysconfig/i18n"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
fedora)
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
version_id=$(. "${__global}/explorer/os_release" && echo "${VERSION_ID:-0}")
|
||||||
|
if expr "${version_id}" '>=' 18 >/dev/null
|
||||||
|
then
|
||||||
|
locale_conf="/etc/locale.conf"
|
||||||
|
quote_value=false
|
||||||
|
else
|
||||||
|
locale_conf="/etc/sysconfig/i18n"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
gentoo)
|
||||||
|
case $(cat "${__global}/explorer/init")
|
||||||
|
in
|
||||||
|
(*openrc*)
|
||||||
|
locale_conf="/etc/env.d/02locale"
|
||||||
|
onchange_cmd="env-update --no-ldconfig"
|
||||||
|
quote_value=true
|
||||||
|
;;
|
||||||
|
(systemd)
|
||||||
|
locale_conf="/etc/locale.conf"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
freebsd|netbsd)
|
||||||
|
# NetBSD doesn't have a separate configuration file to set locales.
|
||||||
|
# In FreeBSD locales could be configured via /etc/login.conf but parsing
|
||||||
|
# that would be annoying, so the shell login file will have to do.
|
||||||
|
# "Non-POSIX" shells like csh will not be updated here.
|
||||||
|
|
||||||
|
locale_conf="/etc/profile"
|
||||||
|
quote_value=true
|
||||||
|
value="$(catval "${__object}/parameter/value"); export ${key}"
|
||||||
|
;;
|
||||||
|
solaris)
|
||||||
|
locale_conf="/etc/default/init"
|
||||||
|
locale_conf_group="sys"
|
||||||
|
|
||||||
|
if expr "$(cat "${__global}/explorer/os_version")" '>=' 5.11 >/dev/null
|
||||||
|
then
|
||||||
|
# mode on Oracle Solaris 11 is actually 0444,
|
||||||
|
# but the write bit makes sense, IMO
|
||||||
|
locale_conf_mode=0644
|
||||||
|
|
||||||
|
# Oracle Solaris 11.2 and later uses SMF to store environment info.
|
||||||
|
# This is a hack, but I didn't feel like modifying the whole type
|
||||||
|
# just for some Oracle nonsense.
|
||||||
|
# 11.3 apparently added nlsadm(1m), but it is missing from 11.2.
|
||||||
|
# Illumos continues to use /etc/default/init
|
||||||
|
# NOTE: Remember not to use "cool" POSIX features like -q or -e with
|
||||||
|
# Solaris grep.
|
||||||
|
release_regex='Oracle Solaris 11.[2-9][0-9]*'
|
||||||
|
case $state_should
|
||||||
|
in
|
||||||
|
(present)
|
||||||
|
svccfg_cmd="svccfg -s svc:/system/environment:init setprop environment/${key} = astring: '$(cat "${__object}/parameter/value")'"
|
||||||
|
;;
|
||||||
|
(absent)
|
||||||
|
svccfg_cmd="svccfg -s svc:/system/environment:init delprop environment/${key}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
refresh_cmd='svcadm refresh svc:/system/environment'
|
||||||
|
onchange_cmd="grep '${release_regex}' /etc/release >&- || exit 0; ${svccfg_cmd:-:} && ${refresh_cmd}"
|
||||||
|
else
|
||||||
|
locale_conf_mode=0555
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
slackware)
|
||||||
|
# NOTE: lang.csh (csh config) is ignored here.
|
||||||
|
locale_conf="/etc/profile.d/lang.sh"
|
||||||
|
locale_conf_mode=0755
|
||||||
|
key="export ${__object_id}"
|
||||||
|
;;
|
||||||
|
suse)
|
||||||
|
os_version=$(cat "${__global}/explorer/os_version")
|
||||||
|
os_major=$(expr "${os_version}" : '\([0-9]\{1,\}\)')
|
||||||
|
|
||||||
|
# https://documentation.suse.com/sles/15-SP2/html/SLES-all/cha-suse.html#sec-suse-l10n
|
||||||
|
if expr "${os_major}" '>=' 15 \& "${os_major}" != 42
|
||||||
|
then
|
||||||
|
# It seems that starting with SuSE 15 the systemd /etc/locale.conf
|
||||||
|
# is the preferred way to set locales, although
|
||||||
|
# /etc/sysconfig/language is still available.
|
||||||
|
# Older documentation doesn't mention /etc/locale.conf, even though
|
||||||
|
# is it created when localectl is used.
|
||||||
|
locale_conf="/etc/locale.conf"
|
||||||
|
else
|
||||||
|
locale_conf="/etc/sysconfig/language"
|
||||||
|
quote_value=true
|
||||||
|
key="RC_${__object_id}"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
voidlinux)
|
||||||
|
locale_conf="/etc/locale.conf"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
||||||
|
@ -42,14 +177,16 @@ case "$os" in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
__file "$locale_conf" \
|
__file "${locale_conf}" --state exists \
|
||||||
--owner root --group root --mode 644 \
|
--owner "${locale_conf_owner:-0}" \
|
||||||
--state exists
|
--group "${locale_conf_group:-0}" \
|
||||||
|
--mode "${locale_conf_mode:-0644}"
|
||||||
|
|
||||||
require="__file/$locale_conf" \
|
require="__file/${locale_conf}" \
|
||||||
__key_value "$locale_conf:$__object_id" \
|
__key_value "${locale_conf}:${key#export }" \
|
||||||
--file "$locale_conf" \
|
--file "${locale_conf}" \
|
||||||
--key "$__object_id" \
|
--key "${key}" \
|
||||||
--delimiter = \
|
--delimiter '=' --exact_delimiter \
|
||||||
--state "$(cat "$__object/parameter/state")" \
|
--state "${state_should}" \
|
||||||
--value "$(cat "$__object/parameter/value")"
|
--value "${value:-$(catval "${__object}/parameter/value")}" \
|
||||||
|
--onchange "${onchange_cmd}"
|
||||||
|
|
Loading…
Reference in a new issue