119 lines
2.9 KiB
Text
119 lines
2.9 KiB
Text
|
#!/bin/sh
|
||
|
#
|
||
|
# PROVIDE: locale
|
||
|
# REQUIRE: cleartmp
|
||
|
# BEFORE: NETWORKING
|
||
|
|
||
|
$_rc_subr_loaded . /etc/rc.subr
|
||
|
|
||
|
name="locale"
|
||
|
start_cmd="locale_start"
|
||
|
stop_cmd=":"
|
||
|
|
||
|
locale_start()
|
||
|
{
|
||
|
# Flush old locale settings
|
||
|
[ ! -d /etc/profile.d ] && mkdir -p /etc/profile.d
|
||
|
|
||
|
: >/etc/profile.d/locale.sh
|
||
|
chmod 755 /etc/profile.d/locale.sh
|
||
|
|
||
|
# Check if requested locale was already created
|
||
|
if ! $(localedef --list-archive|grep -q $LOCALE); then
|
||
|
[ ! -d /usr/lib/locale ] && mkdir -p /usr/lib/locale
|
||
|
echo -n "=> Building locale: $LOCALE... "
|
||
|
localedef -i ${LOCALE%.*} -f UTF-8 ${LOCALE}
|
||
|
show_rval
|
||
|
fi
|
||
|
|
||
|
# Set user defined locale
|
||
|
[ -z "$LOCALE" ] && LOCALE="en_US"
|
||
|
echo -n "=> Setting locale: $LOCALE... "
|
||
|
echo "export LANG=$LOCALE" >> /etc/profile.d/locale.sh
|
||
|
show_rval
|
||
|
|
||
|
if echo "$LOCALE" | grep -qi utf ; then
|
||
|
echo -n "=> Setting consoles to UTF-8 mode... "
|
||
|
# UTF-8 consoles are default since 2.6.24 kernel
|
||
|
# this code is needed not only for older kernels,
|
||
|
# but also when user has set vt.default_utf8=0 but LOCALE
|
||
|
# is *.UTF-8.
|
||
|
for i in $(seq 0 63); do
|
||
|
[ ! -e /dev/tty${i} ] && continue
|
||
|
kbd_mode -u < /dev/tty${i}
|
||
|
printf "\e%%G" > /dev/tty${i}
|
||
|
done
|
||
|
# the $CONSOLE check helps us avoid this when running scripts
|
||
|
# from cron.
|
||
|
cat >> /etc/profile.d/locale.sh <<_EOF
|
||
|
if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then
|
||
|
printf "\e%%G"
|
||
|
fi
|
||
|
_EOF
|
||
|
show_rval
|
||
|
if [ -n "$KEYMAP" ]; then
|
||
|
echo -n "=> Loading keyboard map: $KEYMAP... "
|
||
|
loadkeys -q -u $KEYMAP
|
||
|
show_rval
|
||
|
fi
|
||
|
else
|
||
|
echo -n "=> Setting consoles to legacy mode... "
|
||
|
# make non-UTF-8 consoles work on 2.6.24 and newer kernels
|
||
|
for i in $(seq 0 63); do
|
||
|
[ ! -e /dev/tty${i} ] && continue
|
||
|
kbd_mode -a < /dev/tty${i}
|
||
|
printf "\e%%@" > /dev/tty${i}
|
||
|
done
|
||
|
# the $CONSOLE check helps us avoid this when running scripts
|
||
|
# from cron.
|
||
|
cat >> /etc/profile.d/locale.sh <<_EOF
|
||
|
if [ -z "$CONSOLE" -a "$TERM" = "linux" -a -t 1 ]; then
|
||
|
printf "\e%%@"
|
||
|
fi
|
||
|
_EOF
|
||
|
show_rval
|
||
|
if [ -n "$KEYMAP" ]; then
|
||
|
echo -n "=> Loading keyboard map: $KEYMAP... "
|
||
|
loadkeys -q $KEYMAP
|
||
|
show_rval
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
if [ -n "$CONSOLEFONT" ]; then
|
||
|
echo -n "=> Loading console font: $CONSOLEFONT... "
|
||
|
# CONSOLEMAP in UTF-8 shouldn't be used
|
||
|
if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | grep -qi utf ; then
|
||
|
CONSOLEMAP=""
|
||
|
fi
|
||
|
for i in $(seq 0 63); do
|
||
|
[ ! -e /dev/tty${i} ] && continue
|
||
|
if [ -n "$CONSOLEMAP" ]; then
|
||
|
setfont -m $CONSOLEMAP $CONSOLEFONT -C \
|
||
|
/dev/tty${i} >/dev/null 2>&1
|
||
|
else
|
||
|
setfont $CONSOLEFONT -C /dev/tty${i} \
|
||
|
>/dev/null 2>&1
|
||
|
fi
|
||
|
done
|
||
|
if [ $? -ne 0 ]; then
|
||
|
echo "failed!"
|
||
|
else
|
||
|
for i in $(seq 0 63); do
|
||
|
[ ! -e /dev/tty${i} ] && continue
|
||
|
printf "\e(K" > /dev/tty${i}
|
||
|
done
|
||
|
# the $CONSOLE check helps us avoid this when running
|
||
|
# scripts from cron.
|
||
|
cat >> /etc/profile.d/locale.sh <<_EOF
|
||
|
if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then
|
||
|
printf "\e(K"
|
||
|
fi
|
||
|
_EOF
|
||
|
echo "done."
|
||
|
fi
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
load_rc_config $name
|
||
|
run_rc_command "$1"
|