Files
init.sh/modules/conf_locale.sh

87 lines
2.7 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.5"
conf_locale()
{
pkginst locales locales-all
local gen_fname=/etc/locale.gen
backup_dist $gen_fname
tag_file $gen_fname
# Removing locales not in the list
prnt I "Deactivating initial locales from installation..."
if [[ $(grep -v '^#' $gen_fname | grep -v -e '^[[:space:]]*$') ]]; then
grep -v '^#' $gen_fname | grep -v -e '^[[:space:]]*$' |
while read -r line; do
sed -i "s/$line/# $line/" $gen_fname
done
fi
# 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 "Regenerating locales cache..."
locale-gen
prnt I "Defining system language..."
[[ -z $SYSLOCALE ]] &&
export SYSLOCALE=C
local sys_fname=/etc/default/locale
backup_dist $sys_fname
tag_file $sys_fname
echo "LANG=$SYSLOCALE" >> $sys_fname
# We define all LC_* but LC_ALL as recommended by GNU
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 "No locales definition!"
else
prnt m "Available locales will be: $LOCALESET"
fi
if [[ -z $SYSLOCALE ]]; then
prnt W "No system locale defined, we will use C as default."
export SYSLOCALE="C"
fi
prnt m "The default locale will be $SYSLOCALE"
}
export -f conf_locale
export -f precheck_conf_locale
# EOF