Skip to content

Commit

Permalink
config_language: rely on console-setup for keyboard + font handling
Browse files Browse the repository at this point in the history
Our old approach with running loadkeys, setting console font and
invoking unicode_start via grml-autoconfig is incomplete for nowadays'
environments.

We tried to fix that by changing the order in which we set up the fonts,
runnning loadkeys and finally invoking unicode_start (see commit
c820a66). But this changed only the behavior on tty1, the other
consoles still had problems when trying to display unicode characters
(see e.g. `systemctl status` output).

Instead when running under systemd rely on console-setup, by assuming
/etc/default/console-setup is set up as needed (implemented in grml-live
>=0.33.4) and adjusting /etc/default/keyboard according to
keyboard=.../lang=... boot options. Finally we invoke the console-setup
service.  (We might want to handle this outside of grml-autoconfig in
the future, but this approach for now guarantees to execute this in the
right order and not spit on the console at the end of the boot process).

Closes: #9, grml/grml#50
Thanks: Darshaka Pathirana for debugging this
  • Loading branch information
mika committed Dec 29, 2018
1 parent 8be7a42 commit fc67c18
Showing 1 changed file with 154 additions and 130 deletions.
284 changes: 154 additions & 130 deletions autoconfig.functions
Expand Up @@ -229,166 +229,190 @@ fi
### {{{ language configuration / localization
config_language(){

einfo "Activating language settings:"
eindent
einfo "Activating language settings:"
eindent

# people can specify $LANGUAGE and $CONSOLEFONT in a config file
[ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig
# people can specify $LANGUAGE and $CONSOLEFONT in a config file
[ -r /etc/grml/autoconfig ] && . /etc/grml/autoconfig

# check for bootoption which overrides config from /etc/grml/autoconfig
BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
[ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"
# check for bootoption which overrides config from /etc/grml/autoconfig
BOOT_LANGUAGE="$(getbootparam 'lang' 2>>$DEBUG)"
[ -n "$BOOT_LANGUAGE" ] && LANGUAGE="$BOOT_LANGUAGE"

# set default to 'en' in live-cd mode iff $LANGUAGE is not set yet
if [ -z "$INSTALLED" ] ; then
# set default to 'en' in live-cd mode iff $LANGUAGE is not set yet
if [ -z "$INSTALLED" ] ; then
[ -n "$LANGUAGE" ] || LANGUAGE='en'
fi
fi

if [ -x /usr/sbin/grml-setlang ] ; then
# if bootoption lang is used update /etc/default/locale accordingly
if [ -n "$BOOT_LANGUAGE" ] ; then
/usr/sbin/grml-setlang "$LANGUAGE"
# otherwise default to lang=en
else
/usr/sbin/grml-setlang "en"
fi
fi
if [ -x /usr/sbin/grml-setlang ] ; then
# if bootoption lang is used update /etc/default/locale accordingly
if [ -n "$BOOT_LANGUAGE" ] ; then
/usr/sbin/grml-setlang "$LANGUAGE"
# otherwise default to lang=en
else
/usr/sbin/grml-setlang "en"
fi
fi

# set console font
if [ -z "$CONSOLEFONT" ] ; then
if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
if ! $SYSTEMD ; then
# set console font
if [ -z "$CONSOLEFONT" ] ; then
if ! checkbootparam 'nodefaultfont' >>$DEBUG 2>&1 ; then
if [ -r /usr/share/consolefonts/Uni3-Terminus16.psf.gz ] ; then
CONSOLEFONT='Uni3-Terminus16'
else
else
ewarn "/usr/share/consolefonts/Uni3-Terminus16.psf.gz not available. Please upgrade package console-terminus." ; eend 1
fi
if ! hasfb ; then
fi
if ! hasfb ; then
CONSOLEFONT='Lat15-Terminus16'
fi
fi
fi
fi
fi
fi # not running systemd

# export it now, so error messages get translated, too
[ -r /etc/default/locale ] && . /etc/default/locale
export LANG LANGUAGE

# configure keyboard layout, read in already set values first:
[ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard

# now allow keyboard override by boot commandline for later use:
KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
[ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
# notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
[[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
[[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys

# modify /etc/sysconfig/keyboard only in live-cd mode:
if [ -z "$INSTALLED" ] ; then

local LANGUAGE="$BOOT_LANGUAGE"
. /etc/grml/language-functions
# allow setting xkeyboard explicitly different than console keyboard
KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
if [ -n "$KXKEYBOARD" ]; then
XKEYBOARD="$KXKEYBOARD"
KDEKEYBOARD="$KXKEYBOARD"
elif [ -n "$KKEYBOARD" ]; then
XKEYBOARD="$KKEYBOARD"
KDEKEYBOARD="$KKEYBOARD"
fi
# export it now, so error messages get translated, too
[ -r /etc/default/locale ] && . /etc/default/locale
export LANG LANGUAGE

# duplicate of previous code to make sure /etc/grml/language-functions
# does not overwrite our values....
# now allow keyboard override by boot commandline for later use:
KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
[ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
# notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
[[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
[[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys

# write keyboard related variables to file for later use
[ -d /etc/sysconfig ] || mkdir /etc/sysconfig
if ! [ -e /etc/sysconfig/keyboard ] ; then
echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard
echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard
echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard
echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
fi
fi
if $SYSTEMD ; then
local KEYBOARD
KEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
[ -n "$KEYBOARD" ] || KEYBOARD="$LANGUAGE"
# "symbols/en" doesn't exist, so rewrite to "us"
[[ "$KEYBOARD" == 'en' ]] && KEYBOARD="us"

if [ -r /etc/default/keyboard ] ; then
sed -i "s/^XKBLAYOUT=.*/XKBLAYOUT=\"$KEYBOARD\"/" /etc/default/keyboard

case "$KEYBOARD" in
de|at)
sed -i "s/^XKBVARIANT=.*/XKBVARIANT=\"nodeadkeys\"/" /etc/default/keyboard
;;
esac

[ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
fi
service_wrapper console-setup restart >>$DEBUG 2>&1 ; eend $?
else # not running systemd, keeing for backwards compatibility:
# configure keyboard layout, read in already set values first:
[ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard

# now allow keyboard override by boot commandline for later use:
KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
[ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
# notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
[[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
[[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys

# modify /etc/sysconfig/keyboard only in live-cd mode:
if [ -z "$INSTALLED" ] ; then

local LANGUAGE="$BOOT_LANGUAGE"
. /etc/grml/language-functions
# allow setting xkeyboard explicitly different than console keyboard
KXKEYBOARD="$(getbootparam 'xkeyboard' 2>>$DEBUG)"
if [ -n "$KXKEYBOARD" ]; then
XKEYBOARD="$KXKEYBOARD"
KDEKEYBOARD="$KXKEYBOARD"
elif [ -n "$KKEYBOARD" ]; then
XKEYBOARD="$KKEYBOARD"
KDEKEYBOARD="$KKEYBOARD"
fi

# duplicate of previous code to make sure /etc/grml/language-functions
# does not overwrite our values....
# now allow keyboard override by boot commandline for later use:
KKEYBOARD="$(getbootparam 'keyboard' 2>>$DEBUG)"
[ -n "$KKEYBOARD" ] && KEYTABLE="$KKEYBOARD"
# notce: de/at is a bad choice, so take de-latin1-nodeadkeys instead:
[[ "$KKEYBOARD" == 'de' ]] && KEYTABLE=de-latin1-nodeadkeys
[[ "$KKEYBOARD" == 'at' ]] && KEYTABLE=de-latin1-nodeadkeys

# write keyboard related variables to file for later use
[ -d /etc/sysconfig ] || mkdir /etc/sysconfig
if ! [ -e /etc/sysconfig/keyboard ] ; then
echo "KEYTABLE=\"$KEYTABLE\"" > /etc/sysconfig/keyboard
echo "XKEYBOARD=\"$XKEYBOARD\"" >> /etc/sysconfig/keyboard
echo "KDEKEYBOARD=\"$KDEKEYBOARD\"" >> /etc/sysconfig/keyboard
echo "KDEKEYBOARDS=\"$KDEKEYBOARDS\"" >> /etc/sysconfig/keyboard
fi
fi

# we have to set up all consoles, therefore loop it over all ttys:
NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null)
if [ -n "$NUM_CONSOLES" ] ; then
NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
[ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
fi
CUR_CONSOLE=$(fgconsole 2>/dev/null)
[ -r /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard
fi

if [ -x "$(which setfont)" ] ; then
use_setfont=true
elif [ -x "$(which consolechars)" ] ; then
use_consolechars=true
else
eerror "Neither setfont nor consolechars tool present, can not set font."
eend 1
return 1
fi

if [ -n "$CHARMAP" ] ; then
einfo "Setting font to ${CHARMAP}"
RC=0
for vc in $(seq 0 ${NUM_CONSOLES}) ; do
if ! $SYSTEMD ; then
# we have to set up all consoles, therefore loop it over all ttys:
NUM_CONSOLES=$(fgconsole --next-available 2>/dev/null)
if [ -n "$NUM_CONSOLES" ] ; then
NUM_CONSOLES=$(expr ${NUM_CONSOLES} - 1)
[ ${NUM_CONSOLES} -eq 1 ] && NUM_CONSOLES=6
fi
CUR_CONSOLE=$(fgconsole 2>/dev/null)

if [ -x "$(which setfont)" ] ; then
use_setfont=true
elif [ -x "$(which consolechars)" ] ; then
use_consolechars=true
else
eerror "Neither setfont nor consolechars tool present, can not set font."
eend 1
return 1
fi

if [ -n "$CHARMAP" ] ; then
einfo "Setting font to ${CHARMAP}"
RC=0
for vc in $(seq 0 ${NUM_CONSOLES}) ; do
if $use_setfont ; then
setfont -C /dev/tty${vc} $CHARMAP ; RC=$?
elif $use_consolechars ; then
consolechars --tty=/dev/tty${vc} -m ${CHARMAP} ; RC=$?
fi
done
if [ -n "$CUR_CONSOLE" ] ; then
[ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
done
if [ -n "$CUR_CONSOLE" ] ; then
[ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
fi
eend $RC
fi
eend $RC
fi

if checkbootparam 'noconsolefont' ; then
ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
else
if [ -n "$CONSOLEFONT" ] ; then
einfo "Setting font to ${CONSOLEFONT}"
RC=0
for vc in $(seq 0 ${NUM_CONSOLES}) ; do
if $use_setfont ; then
setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$?
elif $use_consolechars ; then
consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$?
fi
done
if [ -n "$CUR_CONSOLE" ] ; then
if checkbootparam 'noconsolefont' ; then
ewarn "Skipping setting console font as requested on boot commandline." ; eend 0
else
if [ -n "$CONSOLEFONT" ] ; then
einfo "Setting font to ${CONSOLEFONT}"
RC=0
for vc in $(seq 0 ${NUM_CONSOLES}) ; do
if $use_setfont ; then
setfont -C /dev/tty${vc} ${CONSOLEFONT} ; RC=$?
elif $use_consolechars ; then
consolechars --tty=/dev/tty${vc} -f ${CONSOLEFONT} ; RC=$?
fi
done
if [ -n "$CUR_CONSOLE" ] ; then
[ "$CUR_CONSOLE" != "serial" ] && chvt $CUR_CONSOLE
fi
eend $RC
fi
eend $RC
fi
fi
fi

# Set default keyboard before interactive setup
if [ -n "$KEYTABLE" ] ; then
einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
loadkeys -q $KEYTABLE &
eend $?
fi
# Set default keyboard before interactive setup
if [ -n "$KEYTABLE" ] ; then
einfo "Running loadkeys for ${WHITE}${KEYTABLE}${NORMAL} in background"
loadkeys -q $KEYTABLE &
eend $?
fi

# activate unicode console if running within utf8 environment
if [ -r /etc/default/locale ] ; then
if grep -q "LANG=.*UTF" /etc/default/locale ; then
einfo "Setting up unicode environment."
unicode_start ; eend $?
# activate unicode console if running within utf8 environment
if [ -r /etc/default/locale ] ; then
if grep -q "LANG=.*UTF" /etc/default/locale ; then
einfo "Setting up unicode environment."
unicode_start ; eend $?
fi
fi
fi
fi # not running systemd

eoutdent
eoutdent
}
# }}}

Expand Down

0 comments on commit fc67c18

Please sign in to comment.