Files
init.sh/modules/conf_locale.sh
2021-09-28 13:46:22 +02:00

81 lines
2.5 KiB
Bash

# ------------------------------------------------------------------------------
# Configure locale
# This file is part of the init.sh project
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
# ------------------------------------------------------------------------------
# This file is distributed under 3-clause BSD license.
# The complete license agreement can be obtained at:
# https://opensource.org/licenses/BSD-3-Clause
# ------------------------------------------------------------------------------
# Variable:
# * LOCALESET: List of locale that will be supported by system
# * SYSLOCALE: Default system wide locale
#
# Both case will be formated in that way (with exemple for French:
# fr_FR.UTF-8
# ^ ^ ^
# | | |
# ISO-631-1 language code | |
# ISO 3166-2 country subdivision |
# Character table (ISO or UTF)
# ------------------------------------------------------------------------------
export VER_conf_locale="0.1.2"
conf_locale()
{
local gen_fname=/etc/locale.gen
backupdist $gen_fname
# Removing locales not in the list
prnt I "Désactivation des locales initiales..."
grep -v '^#' $gen_fname | grep -v -e '^[[:space:]]*$' |
while read -r line; do
sed -i "s/$line/# $line/" $gen_fname
done
# Adding locales not yet enabled
for loc in $LOCALESET; do
prnt I "Activation de la locale ${loc}..."
sed -i "/^# $loc /s/^# //" $gen_fname
done
unset loc
unset gen_fname
prnt I "Régénération du cache de locale..."
locale-gen
prnt I "Définition de la langue du systême..."
[[ ! $SYSLOCALE ]] &&
export SYSLOCALE=C
local sys_fname=/etc/default/locale
backupdist $sys_fname
echo "# Generated by init on $(stdtime)" > $sys_fname
echo "LANG=$SYSLOCALE" >> $sys_fname
for cfg in ADDRESS IDENTIFICATION MEASUREMENT MONETARY NAME NUMERIC PAPER \
TELEPHONE TIME; do
echo "LC_$cfg=$SYSLOCALE" >> $sys_fname
done
}
precheck_conf_locale()
{
if [[ -z $LOCALESET ]]; then
prnt W "Aucune locale définie !"
else
prnt m "Les locales disponibles seront : $LOCALESET"
fi
if [[ -z $SYSLOCALE ]]; then
prnt W "Pas de locale systême définie, C sera utilié."
export SYSLOCALE="C"
fi
prnt m "La locale par défaut sera : $SYSLOCALE"
}
export -f conf_locale
export -f precheck_conf_locale
# EOF