84 lines
2.6 KiB
Bash
84 lines
2.6 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()
|
|
{
|
|
pkginst locales locales-all
|
|
local gen_fname=/etc/locale.gen
|
|
backupdist $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 "Definingdsystem language..."
|
|
[[ ! $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 "No locales definition!"
|
|
else
|
|
prnt m "Available locales will be: $LOCALESET"
|
|
fi
|
|
|
|
if [[ -z $SYSLOCALE ]]; then
|
|
prnt W "No system locale defined, we'll use s."
|
|
export SYSLOCALE="C"
|
|
fi
|
|
prnt m "The default locale will be $SYSLOCALE"
|
|
}
|
|
|
|
export -f conf_locale
|
|
export -f precheck_conf_locale
|
|
|
|
# EOF
|