core/chakra-init-live/locale_setup.sh

73 lines
2.3 KiB
Bash
Raw Normal View History

#!/bin/bash
2013-01-30 09:27:58 +08:00
#
# Copyright (c) 2013 - Manuel Tortosa <manutortosa@chakra-project.org>
#
# This script is released under the LGPL2+
# $1: the parameter whose value you want to get
# returns: the value of the parameter, if existant
2013-01-30 09:27:58 +08:00
get_bootparam_value() {
[ -z "$CMDLINE" ] && CMDLINE="$(< /proc/cmdline)"
case "$CMDLINE" in *\ $1=*) ;; *) return 1; ;; esac
local result="${CMDLINE##*$1=}"
echo ${result%%[ ]*}
}
# returns: the country of the user, if set as kernel parameter
2013-01-30 09:27:58 +08:00
get_country() {
local COUNTRY=$(get_bootparam_value lang)
echo $COUNTRY
}
2013-01-30 09:27:58 +08:00
get_keyboard() {
2013-02-09 03:47:55 +08:00
local KEYBOARD=$(get_bootparam_value keytable)
2013-01-30 09:27:58 +08:00
echo $KEYBOARD
}
2013-02-08 03:15:51 +08:00
get_layout() {
2013-02-06 06:32:14 +08:00
local LAYOUT=$(get_bootparam_value layout)
echo $LAYOUT
}
2013-01-30 09:27:58 +08:00
# sets the locale as well the keymap
set_locale() {
# hack to be able to set the locale on bootup
local LOCALE=$(get_country)
2013-02-06 06:32:14 +08:00
local KEYMAP=$(get_keyboard)
local KBLAYOUT=$(get_layout)
2013-01-30 09:27:58 +08:00
# set a default value, in case something goes wrong, or a language doesn't have
# good defult settings
[ -n "$LOCALE" ] || LOCALE="en_US"
[ -n "$KEYMAP" ] || KEYMAP="us"
2013-02-09 04:19:39 +08:00
[ -n "$KBLAYOUT" ] || KBLAYOUT="us"
2013-02-09 04:19:39 +08:00
# set vconsole.conf
echo "KEYMAP=\"${KEYMAP}\"" >> /etc/vconsole.conf
2013-02-06 06:32:14 +08:00
2013-02-09 04:19:39 +08:00
# generate 10-keyboard.conf
2013-02-06 06:32:14 +08:00
mkdir -p /etc/X11/xorg.conf.d
echo "Section \"InputClass\"" >> /etc/X11/xorg.conf.d/10-keyboard.conf
echo " Identifier \"Keyboard Defaults\"" >> /etc/X11/xorg.conf.d/10-keyboard.conf
echo " MatchIsKeyboard \"yes\"" >> /etc/X11/xorg.conf.d/10-keyboard.conf
2013-02-09 03:04:05 +08:00
echo " Option \"XkbLayout\" \"${KBLAYOUT}\"" >> /etc/X11/xorg.conf.d/10-keyboard.conf
2013-02-06 06:32:14 +08:00
if [ "$KEYMAP" = "dvorak" ] ; then
echo " Option \"XkbVariant\" \"dvorak\"" >> /etc/X11/xorg.conf.d/10-keyboard.conf
fi
2013-02-09 01:14:33 +08:00
echo "EndSection" >> /etc/X11/xorg.conf.d/10-keyboard.conf
2013-02-06 06:32:14 +08:00
2013-01-30 09:27:58 +08:00
# set systemwide language
echo "LANG=${LOCALE}.UTF-8" > /etc/locale.conf
echo "LC_MESSAGES=${LOCALE}.UTF-8" >> /etc/locale.conf
2013-02-06 06:32:14 +08:00
2013-01-30 09:27:58 +08:00
# generate LOCALE
2013-02-09 04:19:39 +08:00
# comment out all locales which we don't need
sed -i "s/^/#/g" /etc/locale.gen
2013-01-30 09:27:58 +08:00
local TLANG=${LOCALE%.*} # remove everything after the ., including the dot from LOCALE
sed -i -r "s/#(.*${TLANG}.*UTF-8)/\1/g" /etc/locale.gen
# add also American English as safe default
sed -i -r "s/#(en_US.*UTF-8)/\1/g" /etc/locale.gen
locale-gen
}