* Denis Barbier [2004-07-24 22:51:00+0200] [...] > If termwrap is needed outside of d-i, I suggest to have a minimal > termwrap-di to deal with Asian locales, and nothing more. Eugeniy has once said that only those languages without a declared debian-installer/consoletype needed termwrap. I've prepared proof of concept by using the idea. Attached is the minimal implementation. It doesn't behave according to the ENCODING, instead it first evaluates the CONSOLETYPE from debian-installer/consoletype and only then it does something based on the ENCODING. Following explains this idea: WRAPPER="" WRAPPER_OPTION="" CONSOLETYPE=$(get_db debian-installer/consoletype) ENCODING=$(locale charmap) case $CONSOLETYPE in kbd|cyr) # Nothing to do. ;; *) case $ENCODING in eucJP|EUC-JP) [...] Please note that this is only a draft, far from complete and untested. Now, could it be a base for further discussions? -- roktas
#!/bin/sh
#
# Termwrap detects the type of terminal that it is run on, and the language
# the user is using, and sets up the terminal for that language. This is
# useful for languages (e.g., Japanese) where a special program is needed
# to display that language at the console.
#
# Termwrap is used to run programs including base-config on the
# second-stage install.
#
# This is really something of a hack, since once termwrap is done the user
# still gets a standard login prompt and is no longer shielded by
# termwrap.
######################################################################
## Display usage if no argument.
######################################################################
if [ -z "$1" ]; then
echo "usage: $0 [-nnt] <command> [...]"
echo "-nnt: don't run another terminal"
exit 0
fi
######################################################################
## Some functions
######################################################################
# Get a variable from the debconf database of the first stage installer.
get_db () {
DI_DB=/var/log/debian-installer/cdebconf/questions.dat
if [ -e $DI_DB ]; then
debconf-copydb d-i stdout -c Name:d-i -c Driver:File \
-c Filename:$DI_DB -c Name:stdout \
-c Driver:Pipe -c InFd:none \
--pattern="^$1$" | \
grep ^Value: | cut -d ' ' -f 2
fi
}
info() {
echo "info: $@"
logger -p user.info -t termwrap "info: $@"
}
warning() {
echo "warning: $@"
logger -p user.warning -t termwrap "warning: $@"
}
error() {
echo "error: $@"
logger -p user.crit -t termwrap "error: $@"
}
try_load_fb() {
# Load framebuffer module (debian-installer/framebuffer value is null(not true!) or false.)
if [ "$(get_db debian-installer/framebuffer)" != "false" ]; then
case $(dpkg --print-installation-architecture) in
i386)
case $(uname -r) in
2.6.*)
(modprobe -q vesafb >/dev/null 2>&1 && modprobe -q fbcon >/dev/null 2>&1) || (modprobe -q vga16fb >/dev/null 2>&1 && modprobe -q fbcon >/dev/null 2>&1)
;;
*)
modprobe -q vesafb >/dev/null 2>&1 || modprobe -q vga16fb >/dev/null 2>&1
;;
esac
;;
esac
fi
}
######################################################################
## Check the locale
######################################################################
# For this to work, the current locale must be valid. The block
# generating the locale should have taken care of that. If it isn't
# valid, the output is 'ANSI_X3.4-1968' (at least on my test machine
# 2002-02-09), and the case test below should unset both LANG and
# LOCALE
if [ -z "$LANG" ]; then
echo "Locale is not set; aborting"
exit 1
fi
if ! validlocale $LANG > /dev/null 2>&1; then
echo "Locale \"$LANG\" is not valid; aborting"
exit 1
fi
######################################################################
## Recognize terminal type.
######################################################################
case `/usr/bin/tty` in
/dev/console)
# Use fgconsole to detect if it is a serial console.
if command -v fgconsole >/dev/null 2>&1 && [ serial = "$(fgconsole)" ] ; then
TERMINAL=serial
else
TERMINAL=console
fi
# Or try another way, copied from d-i udeb rootskel.
#case `readlink /proc/self/fd/0` in
# /dev/console)
# TERMINAL=serial
# ;;
# *)
# TERMINAL=console
# ;;
#esac
;;
/dev/tty|/dev/tty[1-9]*|/dev/vc/*)
TERMINAL=console
;;
/dev/tty[p-za-e]*|/dev/pts/*)
TERMINAL=pseudo
if [ ! -z "$DISPLAY" ]; then
TERMINAL=x
else
case $TERM in
rxvt|xterm*|kterm) TERMINAL=x;;
esac
fi
;;
/dev/tty[A-Z]*|/dev/cu*)
TERMINAL=serial
;;
esac
# If the default linux kernel TERM setting is used for serial consoles, change
# it to vt100. This assume serial consoles understand vt100. Almost
# all terminal programs can handle vt100.
if [ serial = "$TERMINAL" ] && [ linux = "$TERM" ] ; then
TERM=vt100
fi
case $TERM in
dumb) TERMINAL=dumb
esac
export TERMINAL
case $(dpkg --print-installation-architecture) in
i386) /bin/grep -q 9800 /proc/version && SUBARCH=pc9800 ;;
esac
######################################################################
## Select suitable terminal as wrapper.
######################################################################
WRAPPER=""
WRAPPER_OPTION=""
CONSOLETYPE=$(get_db debian-installer/consoletype)
ENCODING=$(locale charmap)
case $CONSOLETYPE in
kbd|cyr)
# Nothing to do.
;;
*)
case $ENCODING in
eucJP|EUC-JP)
# Japanese
case $TERMINAL in
x)
WRAPPER="/usr/X11R6/bin/krxvt"
WRAPPER_OPTION="-e"
;;
console)
if [ "$SUBARCH" != pc9800 ] && [ "$TERMINAL" = console ]; then
# Any platform except PC9800 require jfbterm
# to display japanese fonts on console.
try_load_fb
WRAPPER="/usr/bin/jfbterm"
WRAPPER_OPTION="-q -c other,EUC-JP,iconv,UTF-8 -e"
fi
;;
# On pseudo and serial, we can't tell
# if the terminal can display japanese fonts...
esac
;;
*)
# Fallback jfbterm
# Mainly Korean, Chinese, Greek, Bulgarian
case $TERMINAL in
console)
try_load_fb
WRAPPER="/usr/bin/jfbterm"
WRAPPER_OPTION="-q -c other,$ENCODING,iconv,UTF-8 -e"
;;
esac
;;
esac
esac
if [ "$1" = "-nnt" ]; then
WRAPPER=""
shift
fi
######################################################################
## Execute Wrapper.
######################################################################
if [ ! -z "$WRAPPER" ] && [ -x "$WRAPPER" ]; then
$WRAPPER $WRAPPER_OPTION /bin/true && exec $WRAPPER $WRAPPER_OPTION $@
fi
# Run the program.
$@
Attachment:
signature.asc
Description: Digital signature