3 # setupcon -- setup the font and keyboard on the Linux console
4 # Copyright © 1999,2000,2001,2002,2003,2006 Anton Zinoviev
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # If you have not received a copy of the GNU General Public License
17 # along with this program, write to the Free Software Foundation, Inc.,
18 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ###########################################################################
23 # The same as /usr/bin/which - in order to make "which" available before
29 if [ -x "$i/$1" ]; then
61 Usage: setupcon [OPTION] [VARIANT]
62 Sets up the font and the keyboard on Linux console.
64 -k, --keyboard-only setup the keyboard only, do not setup the font
65 -f, --font-only setup the font only, do not setup the keyboard
66 --force do not check whether we are on the console
67 -v, --verbose explain what is being doing, try it if s.t. goes wrong
68 --save copy the font and the console map in /etc/console-setup,
69 update /etc/console-setup/cached.kmap.gz
70 --save-only only save; don't setup keyboard/font immediately
72 -h, --help display this help and exit
74 If VARIANT is not specified setupcon looks for the configuration files
75 (in this order) ~/.console-setup and if this doesn't exist then the
76 combination/etc/default/keyboard + /etc/default/console-setup. When
77 a VARIANT is specified then setupcon looks for the configuration files
78 ~/.console-setup.VARIANT and /etc/default/console-setup.VARIANT.
83 echo "setupcon: Unrecognised option $1" >&2
87 if [ -z "$VARIANT" ]; then
90 echo "setupcon: Two variants specified: $VARIANT and $1" >&2
98 if [ "$VARIANT" ]; then
99 USER_CONFIG=${HOME}/.console-setup."$VARIANT"
100 MAIN_CONFIG=/etc/default/keyboard."$VARIANT"
101 MAIN_CONFIG2=/etc/default/console-setup."$VARIANT"
103 USER_CONFIG=${HOME}/.console-setup
104 MAIN_CONFIG=/etc/default/keyboard
105 MAIN_CONFIG2=/etc/default/console-setup
108 if [ -f "$USER_CONFIG" ]; then
109 CONFIG="$USER_CONFIG"
112 elif [ -f "$MAIN_CONFIG" ]; then
113 CONFIG="$MAIN_CONFIG"
114 CONFIG2="$MAIN_CONFIG2"
116 echo "setupcon: None of $MAIN_CONFIG nor $USER_CONFIG exists." >&2
120 if [ "$CONFIG2" -a -f "$CONFIG2" ]; then
125 if [ "$verbose_option" = yes ]; then
128 if [ "$VERBOSE_OUTPUT" = yes ]; then
131 verbose='>/dev/null 2>&1'
134 if which ckbcomp-mini >/dev/null; then
136 if [ "$VERBOSE_OUTPUT" = yes -a "$CHARMAP" != UTF-8 ]; then
137 echo Only UTF-8 is supported by console-setup-mini
141 if [ "$force" != yes ]; then
142 case `readlink /proc/self/fd/2` in
143 /dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
146 echo We are not on the Linux console, the console is left unconfigured.
152 ACTIVE_CONSOLES=${ACTIVE_CONSOLES:-/dev/tty[1-6]}
153 CHARMAP=${CHARMAP:-UTF-8}
154 CODESET=${CODESET:-Uni2}
155 CONSOLE_MAP=${CONSOLE_MAP:-$ACM}
157 #-----------------------#
159 #-----------------------#
161 if [ "$keyboard_only" != yes ] && [ "$ACTIVE_CONSOLES" ]; then
162 # Setup unicode/non-unicode mode
163 if [ "$save_only" != yes ]; then
164 for console in $ACTIVE_CONSOLES; do
165 [ -w $console ] || continue
167 [ "$CHARMAP" = UTF-8 ] || [ -z "$CONSOLE_MAP$CHARMAP" ]
169 printf '\033%%G' >$console
171 printf '\033%%@' >$console
177 if [ -z "$FONT" ]; then
179 if which ckbcomp-mini >/dev/null; then
180 FONT=$(echo `ls /usr/share/consolefonts/$CODESET-*.psf* \
181 /etc/console-setup/$CODESET-*.psf* 2>/dev/null`)
183 if [ "$FONTFACE" ] || [ "$FONTSIZE" ]; then
184 eval echo setupcon: Warning: ignoring the FONTFACE and FONTSIZE specifications! $verbose
186 elif [ "$FONTFACE" ] && [ "$FONTSIZE" ]; then
187 FONT="$CODESET-$FONTFACE$FONTSIZE.psf.gz"
201 LOADFONTS="$LOADFONTS $f"
205 /usr/local/share/consolefonts \
206 /usr/share/consolefonts \
210 if [ -f "$dir/${f##*/}" ]; then
211 LOADFONTS="$LOADFONTS $dir/${f##*/}"
213 elif [ -f "$dir/${fdec##*/}" ]; then
214 LOADFONTS="$LOADFONTS $dir/${fdec##*/}"
217 if [ "$dir" = FONT_IS_MISSING ]; then
218 echo setupcon: Warning: the font ${f##*/} does not exist! >&2
224 for f in $FONT_MAP; do
225 [ -z "$LOADFONT_MAP" ] || break # only one unicode map
227 LOADFONT_MAP="$LOADFONT_MAP $f"
230 /usr/local/share/consoletrans \
231 /usr/share/consoletrans \
235 if [ -f "$dir/${f##*/}" ]; then
236 LOADFONT_MAP="$LOADFONT_MAP $dir/${f##*/}"
239 if [ "$dir" = FONT_MAP_IS_MISSING ]; then
240 echo setupcon: Warning: the unicode map ${f##*/} does not exist! >&2
246 for f in $LOADFONTS; do
249 && [ "${f%/*}" != /etc/console-setup ]
252 if [ "$fdec" = "$f" ]; then
253 cp "$f" /etc/console-setup/
255 gunzip -c "$f" >"/etc/console-setup/${fdec##*/}"
257 rm -f "/etc/console-setup/${fdec##*/}.gz"
260 for f in $LOADFONT_MAP; do
263 && [ "${f%/*}" != /etc/console-setup ]
265 cp "$f" /etc/console-setup/
269 # Due to bug in splashy and usplash: do not load fonts (#540314)
271 pidof splashy > /dev/null \
272 || pidof usplash > /dev/null
277 if [ "$save_only" != yes ] && [ "$LOADFONTS" ]; then
278 for console in $ACTIVE_CONSOLES; do
279 [ -w $console ] || continue
280 if which consolechars >/dev/null; then
281 if [ "$bigfont" = yes ]; then
282 echo "setupcon: The consolechars utility from the console-setup font can load only fonts with 8 pixel width matrix. Please install the setfont utility from the kbd package." >&2
284 if [ "$LOADFONT_MAP" ]; then
285 eval consolechars -v --tty=$console -f $LOADFONTS -u "$LOADFONT_MAP" $verbose
287 eval consolechars -v --tty=$console -f $LOADFONTS $verbose
289 elif which setfont >/dev/null; then
290 if [ "$LOADFONT_MAP" ]; then
291 eval setfont -v -C $console $LOADFONTS -u "$LOADFONT_MAP" $verbose
293 eval setfont -v -C $console $LOADFONTS $verbose
300 if [ ! -f "$CONSOLE_MAP" ]; then
302 /usr/local/share/consoletrans \
303 /usr/share/consoletrans \
306 if [ -f "$dir/$CHARMAP.acm.gz" ]; then
307 CONSOLE_MAP="$dir/$CHARMAP.acm.gz"
309 elif [ -f "$dir/$CHARMAP.acm" ]; then
310 ACM="$dir/$CHARMAP.acm"
315 if [ -f "$CONSOLE_MAP" ]; then
318 && [ "${CONSOLE_MAP%/*}" != /etc/console-setup ]
320 console_map_dec="${CONSOLE_MAP%.gz}"
321 if [ "$console_map_dec" = "$CONSOLE_MAP" ]; then
322 cp "$CONSOLE_MAP" /etc/console-setup/
324 gunzip -c "$CONSOLE_MAP" >"/etc/console-setup/${console_map_dec##*/}"
326 rm -f "/etc/console-setup/${console_map_dec##*/}.gz"
329 CONSOLE_MAP="$CHARMAP.acm.gz"
332 [ "$save_only" != yes ] && [ "$CHARMAP" != UTF-8 ] && [ "$LOADFONTS" ]
334 for console in $ACTIVE_CONSOLES; do
335 [ -w $console ] || continue
336 if which consolechars >/dev/null; then
337 eval consolechars -v --tty=$console --acm "$CONSOLE_MAP" $verbose
338 elif which setfont >/dev/null; then
339 eval setfont -v -C $console -m "$CONSOLE_MAP" $verbose
345 [ -z "$SCREEN_WIDTH" ] || STTY="$STTY cols $SCREEN_WIDTH"
346 [ -z "$SCREEN_HEIGHT" ] || STTY="$STTY rows $SCREEN_HEIGHT"
350 for console in $ACTIVE_CONSOLES; do
351 [ -r $console ] || continue
352 stty $STTY < $console
357 #-----------------------#
359 #-----------------------#
361 if [ "$font_only" != yes ] && [ "$XKBMODEL" != unknown ] && \
362 [ "$ACTIVE_CONSOLES" ]; then
363 # On Mac PPC machines, we may need to set kernel vars first. We need
364 # to mount /proc to do that, but we need it set up before sulogin may
365 # be run in checkroot, which will need the keyboard to log in...
366 # This code was borrowed from the keymap.sh script of console-common
367 # Copyright © 2001 Yann Dirson
368 # Copyright © 2001 Alcove http://www.alcove.fr/
369 if [ "$save_only" != yes ] && \
370 [ -x /sbin/sysctl ] && [ -r /etc/sysctl.conf ]; then
371 if grep -v '^\#' /etc/sysctl.conf | grep -q keycodes ; then
372 grep keycodes /etc/sysctl.conf | grep -v "^#" \
374 /sbin/sysctl -w $d 2> /dev/null || true
379 if [ "$save_only" != yes ]; then
380 for console in $ACTIVE_CONSOLES; do
381 [ -w $console ] || continue
382 if which kbd_mode >/dev/null; then
383 if [ "$CHARMAP" = UTF-8 ] || [ -z "$CONSOLE_MAP" ]; then
384 kbd_mode -u <$console
386 kbd_mode -a <$console
392 if which loadkeys >/dev/null && [ "$XKBMODEL" != SKIP ]; then
393 if [ "$CHARMAP" != UTF-8 ]; then
394 acm_option="-charmap $CHARMAP"
399 if [ "$XKBRULES" ]; then
400 rules_option="-rules $XKBRULES"
406 [ "$VARIANT" = '' ] \
407 && which gzip >/dev/null \
408 && [ -d /usr/share ] # /usr is mounted
411 [ ! -f /etc/console-setup/cached.kmap.gz ] \
412 || [ /etc/console-setup/cached.kmap.gz \
413 -ot /etc/default/keyboard ] \
416 ckbcomp $acm_option $rules_option -model "$XKBMODEL" \
417 "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
418 | gzip -9 2>/dev/null >/etc/console-setup/cached.kmap.gz
419 # avoid warnings when /etc is mounted read-only
423 if [ "$save_only" != yes ]; then
424 if [ "$KMAP" -a -f "$KMAP" ]; then
425 eval loadkeys "$KMAP" $verbose
428 [ "$VARIANT" = '' ] && [ "$CONFIG" != "$USER_CONFIG" ] \
429 && [ -f /etc/console-setup/cached.kmap.gz ] \
430 && [ ! /etc/console-setup/cached.kmap.gz \
431 -ot /etc/default/keyboard ]
433 eval loadkeys /etc/console-setup/cached.kmap.gz $verbose
435 if [ -d /usr/share ]; then
436 ckbcomp $acm_option $rules_option \
438 "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
439 | eval loadkeys $verbose
440 elif [ -f /etc/console-setup/cached.kmap.gz ]; then
441 eval loadkeys /etc/console-setup/cached.kmap.gz $verbose