~eugenenuke/ubuntu/wily/console-setup/fix-for-1565542

« back to all changes in this revision

Viewing changes to setupcon

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre, Steve Langasek, Mathieu Trudel-Lapierre
  • Date: 2015-02-27 16:36:52 UTC
  • mfrom: (3.2.59 sid)
  • Revision ID: package-import@ubuntu.com-20150227163652-9sxmh6sbwqseysa0
Tags: 1.108ubuntu1
[ Steve Langasek ]
* Merge from Debian unstable, remaining changes: (LP: #1426721)
  - Don't gzip font or ACM files in /etc/console-setup/.  The space saving
    is negligible, and it's more efficient not to need to uncompress them
    at boot time.
  - Include pc105.tree for ubiquity.
  - Move boot tasks to a combination of two udev rules and a single
    Upstart job, ensuring that they're run at points when we are able to
    satisfy the constraints on the relevant ioctls.
  - Stop running debconf-updatepo on clean.
  - Set keymap and font in the initramfs if possible and sensible.
  - Add an apport hook.
  - Use keymapper to generate decision trees for a restricted subset of
    the pc105 model.
  - Depend on kbd (>= 1.15-1ubuntu3) for a valuable loadkeys improvement.
  - Include support for translated keyboard names.
  - Depend on debconf instead of pre-depending, because pre-depends have
    no effect on config scripts.
  - debian/vtrgb, debian/vtrgb.vga,
    debian/console-setup-linux.setvtrgb.upstart, debian/rules,
    debian/console-setup-linux.postinst: use Ubuntu's virtual terminal color
    scheme by default, with a VGA color scheme available as an alternative.
  - Make setupcon explicitly exit 0, so that postinsts don't fail in the
    event that loadkeys can't find a console.
  - Update for new layouts and variants for Montenegro and Serbia, and
    migrate configuration files from the old layouts.
  - Generate a locale locally for translating keyboard names in
    kbdnames-maker.
  - Don't copy keyboard-configuration questions to /target in OEM mode.
    oem-config will ask them later, and copying these confuses it.
  - Change the default font from Fixed to VGA for Lat15; while it's not
    entirely complete, it looks better and is largely good enough.
  - If the detect-keyboard debconf plugin is available
    (cdebconf-newt-detect-keys in the installer), then offer to use it to
    detect the keyboard layout.
  - Fix default keyboard selection for language/country combinations
    lacking a proper combined locale.
  - Drop the layout/variant priority to high on fresh installs.
  - Set default for Dutch to us(intl), not just us.
  - Set default layout for Vietnam to 'us'.
  - Set default variant for French to oss.
  - Set default layout for Simplified Chinese to 'cn'.
  - Don't use the default keyboard variant if the layout is overridden by
    preseeding.
  - If keyboard-configuration/layoutcode is preseeded but not marked as
    seen, then set the default layout but don't lower the layout question
    priority or preseed console-setup/ask_detect.
  - Use the default keyboard model if an existing configuration file sets
    XKBMODEL="".
  - Go back to always asking layout before variant.
  - Fix keyboard layout detection to set the layout properly.
  - Reset keyboard-configuration/toggle to the default if it's set to "No
    toggling" and you select a non-Latin layout.
  - Automatically save the font and keymap to /etc in
    /etc/init.d/console-setup if it isn't being run from init. Similarly,
    ensure that the font and keymap are saved to /etc during initial
    installation.
  - Replace usplash detection code with Plymouth detection code.
  - Load the new keyboard configuration immediately when running
    'dpkg-reconfigure keyboard-configuration' in an installed system.
  - Don't fail to configure keyboard-configuration if setxkbmap fails to
    talk to the X display.
  - Tolerate absence of setupcon in keyboard-configuration.postinst.
  - Drop the simplified keyboard-configuration/xkb-keymap question.
  - Fix command injection in ckbcomp.
  - debian/console-setup.console-font.upstart: Add Upstart job that sets up
    console font when plymouth-splash is starting.
  - Override description of the ch layout from "German (Switzerland)" to
    just "Switzerland".
  - Map ppc64el/* to XKBMODEL=pc105.
* Dropped changes, included in Debian:
  - "Do not configure keyboard; keep kernel keymap" model option,
    preseedable by keyboard-configuration/modelcode=SKIP: this is now
    supported upstream with either "unknown" or an empty string as the
    model.
  - Run kbd_mode on each tty in ACTIVE_CONSOLES rather than on the current
    tty, since the current tty might belong to X and changing X's tty out
    of raw mode is a very bad idea.
  - Include Terminus font in the compiled packages.  Do not depend, but
    conflict/provide/replace console-terminus.  New upstream version of
    the Terminus font (4.32).
  - Explicitly build-depend on liblocale-gettext-perl for kbdnames-maker,
    and likewise have keyboard-configuration depend on
    liblocale-gettext-perl.
  - Weaken test for whether /usr is mounted; testing for /usr/share is
    sufficient, and fixes operation in d-i.
  - Make keyboard-configuration replace old console-setup/console-setup-mini
    versions as well as conflicting with them.
  - Set default layout for Kurdish to tr(ku).
* Dropped changes, no longer needed:
  - Cope with systems installed with console-setup-udeb (<< 1.53) (which
    predates Ubuntu 12.04 and Debian wheezy).
  - Drop ancient handling of an empty codeset in the config file.
  - Drop vtrgb upgrade handling from natty
  - Drop upstart job transition from lucid
* setupcon: Map XKBMODEL=SKIP to '' for compatibility with existing
  configs.
* debian/rules: revert hard-coding of a list of "debconf-selectable"
  layouts for the udebs, since we don't use this debconf question in Ubuntu
  and all layouts are selectable.
* setupcon: revert ridiculous upstream twiddling of keymap cache filenames:
  - the variables are taken from a config file which, if changed,
    invalidates the cache.
  - there is only ever one keyboard map per system.
  - the system should not have to resolve filenames to find the keymap cache
    on boot.
* Move vtrgb handling to console-setup-linux package, since this is clearly
  Linux-specific.
* Add missing console-setup-linux.prerm to remove /etc/vtrgb alternatives
* Keyboard/kbdcompiler: fix bug in filtering of unsupported variants that
  breaks generation of the pc105.tree for d-i keyboard detection.
* debian/keyboard-configuration.postinst: udpkg is not part of an installed
  Debian system; don't fail to configure if it's absent and the script is
  called outside of an installer context.
* Don't make debian/copyright a symlink to COPYRIGHT, this is disallowed
  by the Ubuntu archive installer.

[ Mathieu Trudel-Lapierre ]
* debian/keyboard-configuration.config: fix typo in model check for SKIP;
  even when looking up the layout/variant, we need to check for the model
  as XKBMODEL, since $model doesn't exist.
* debian/preprocessor: revert the removal of keyboard names (for size) of
  console-setup-udeb: we do need those, since we don't use the simplified
  xkb-keymap template from Debian just yet: this way we can still show
  country/language names when selecting a keyboard, layout or variant.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
2
 
3
3
#     setupcon -- setup the font and keyboard on the Linux console
4
 
#     Copyright © 1999,2000,2001,2002,2003,2006 Anton Zinoviev
5
 
 
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.
10
 
 
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.
15
 
 
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
 
4
#     Copyright (C) 2011 Anton Zinoviev <anton@lml.bas.bg>
 
5
 
 
6
#     Permission is hereby granted, free of charge, to any person
 
7
#     obtaining a copy of this file (the "Program"), to deal in the
 
8
#     Program without restriction, including without limitation the
 
9
#     rights to use, copy, modify, merge, publish, distribute,
 
10
#     sublicense, and/or sell copies of the Program, and to permit
 
11
#     persons to whom the Program is furnished to do so, subject to
 
12
#     the following conditions: The above copyright notice and this
 
13
#     permission notice shall be included in all copies or substantial
 
14
#     portions of the Program.
 
15
 
 
16
#     THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
17
#     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
18
#     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
19
#     NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
20
#     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
21
#     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
22
#     FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR
 
23
#     OTHER DEALINGS IN THE PROGRAM.
19
24
 
20
25
###########################################################################
21
26
 
 
27
do_font=yes     # configure font
 
28
do_kbd=yes      # configure keyboard
 
29
do_check=yes    # test whether we are on the console
 
30
do_verbose=''   # explain what is being doing
 
31
do_save=''      # save the required files in /etc/console-setup
 
32
savekbdfile=''  # save the keyboard map in $savekbdfile
 
33
setupdir=''     # directory for --setup-dir
 
34
SETUP=''
22
35
 
23
36
# The same as /usr/bin/which - in order to make "which" available before
24
37
# /usr is mounted
26
39
    local IFS
27
40
    IFS=:
28
41
    for i in $PATH; do
29
 
        if [ -x "$i/$1" ]; then
 
42
        if [ -f "$i/$1" -a -x "$i/$1" ]; then
30
43
            echo "$i/$1"
31
44
            return 0
32
45
        fi
34
47
    return 1
35
48
}
36
49
 
 
50
# Create a temporary file name and set TMPFILE to its name.  Early in
 
51
# the boot process /tmp is mounted read-only, so lets have some other
 
52
# options...  I am not sure all non-GNU versions of mktemp understand
 
53
# the -q option so redirections of stderr are used instead.
 
54
TMPFILE=''
 
55
tempfile () {
 
56
    local tmp
 
57
    tmp="$TMPFILE"
 
58
    if \
 
59
        TMPFILE=`mktemp /tmp/tmpkbd.XXXXXX 2>/dev/null` \
 
60
            || TMPFILE=`mktemp /run/tmpkbd.XXXXXX 2>/dev/null` \
 
61
            || TMPFILE=`mktemp /dev/.tmpkbd.XXXXXX 2>/dev/null` \
 
62
            || TMPFILE=`mktemp /lib/init/rw/tmpkbd.XXXXXX 2>/dev/null` \
 
63
            || TMPFILE=`mktemp 2>/dev/null`
 
64
    then
 
65
        if [ -z "$tmp" ]; then
 
66
            trap 'rm -f "$TMPFILE" >/dev/null 2>&1' 0
 
67
            trap "exit 2" 1 2 3 13 15
 
68
        fi
 
69
        return 0
 
70
    else
 
71
        TMPFILE=''
 
72
        return 1
 
73
    fi
 
74
}
 
75
 
 
76
# Print the arguments to stderr if $do_verbose is yes
 
77
report () {
 
78
    if [ "$do_verbose" ]; then
 
79
        echo "$@" >&2
 
80
    fi
 
81
}
 
82
 
 
83
# Execute a command on every console terminal screen specified in
 
84
# $ACTIVE_CONSOLES.
 
85
#
 
86
# 1st argument: plain=execute only once with no tty change,
 
87
# out=execute with standard output redirected to the tty, in=the same
 
88
# but the standard input is being redirected, 'other argument'=do not
 
89
# redirect the standard input or output but use this as a tty option.
 
90
#
 
91
# 2rd argument: option(s) for verbose output; 3nd argument: command to
 
92
# run; other arguments: other options
 
93
#
 
94
# Example: run '-C ' -v setfont font.psf
 
95
# If ACTIVE_CONSOLES='/dev/tty1 /dev/tty2 /dev/tty3', then this results in
 
96
#
 
97
# setfont -C /dev/tty1 font.psf -v
 
98
# setfont -C /dev/tty2 font.psf -v
 
99
# setfont -C /dev/tty3 font.psf -v
 
100
#
 
101
# or
 
102
#
 
103
# setfont -C /dev/tty1 font.psf >/dev/null 2>&1
 
104
# setfont -C /dev/tty2 font.psf >/dev/null 2>&1
 
105
# setfont -C /dev/tty3 font.psf >/dev/null 2>&1
 
106
#
 
107
# depending on the value of $do_verbose
 
108
 
 
109
run () {
 
110
    local ttyarg cmd verbose tty x
 
111
    ttyarg="$1"
 
112
    verbose="$2"
 
113
    cmd="$3"
 
114
    shift; shift; shift
 
115
    if [ -z "$ACTIVE_CONSOLES" ]; then
 
116
        ttyarg=plain
 
117
    fi
 
118
    case "$ttyarg" in
 
119
        plain)
 
120
            if [ "$setupdir" ]; then
 
121
                SETUP="$SETUP$cmd $@
 
122
"
 
123
            elif [ "$do_verbose" ]; then
 
124
                case "$verbose" in
 
125
                    ECHO)
 
126
                        report Executing $cmd "$@".
 
127
                        $cmd "$@"
 
128
                        ;;
 
129
                    *)
 
130
                        $cmd "$@" $verbose
 
131
                        ;;
 
132
                esac
 
133
            else
 
134
                $cmd "$@" >/dev/null 2>&1
 
135
            fi
 
136
            ;;
 
137
        in)
 
138
            for tty in $ACTIVE_CONSOLES; do
 
139
                if [ -r $tty ]; then
 
140
                    if [ "$setupdir" ]; then
 
141
                        # keep the space between < and $tty
 
142
                        SETUP="$SETUP$cmd $@ < $tty
 
143
"
 
144
                    else
 
145
                        report For $tty:
 
146
                        run plain "$verbose" "$cmd" "$@" <$tty
 
147
                    fi
 
148
                else
 
149
                    report No read access from $tty. Can not execute $cmd.
 
150
                fi
 
151
            done
 
152
            ;;
 
153
        *)
 
154
            for tty in $ACTIVE_CONSOLES; do
 
155
                x="${ttyarg}$tty"
 
156
                run plain "$verbose" "$cmd" $x "$@"
 
157
            done
 
158
            ;;
 
159
    esac
 
160
}
 
161
 
 
162
# Search a file and return the full file name if found.
 
163
# The filename may include wildcards and may not include space.
 
164
# Example: findfile share/consolefonts Uni3-*.psf.gz
 
165
# Result: /usr/share/consolefonts/Uni3-Fixed13.psf.gz
 
166
findfile () {
 
167
    local x
 
168
    case "$2" in
 
169
        /*)
 
170
            if [ -f "$2" ]; then
 
171
                echo "$2"
 
172
                return 0
 
173
            fi
 
174
            ;;
 
175
    esac
 
176
    x=`(ls "$installdir"/$1/$2 /usr/local/$1/$2 \
 
177
           /usr/$1/$2 /etc/console-setup/$2 \
 
178
           "$installdir"/etc/console-setup/$2) 2>/dev/null`
 
179
    x=`echo $x`
 
180
    [ "${x%% *}" ] || report Unable to find "$2".
 
181
    echo "${x%% *}"
 
182
}
 
183
 
 
184
# Usage: utf_start /dev/tty5
 
185
# Configure a console for unicode output
 
186
utf_start () {
 
187
    if [ -w "$1" ]; then
 
188
        report Configuring "$1" in Unicode mode.
 
189
        printf '\033%%G' >"$1"
 
190
    else
 
191
        report No write access to $tty. Can not configure Unicode mode.
 
192
    fi
 
193
}
 
194
 
 
195
# Usage: utf_stop /dev/tty5
 
196
# Configure a console for non-unicode output
 
197
utf_stop () {
 
198
    if [ -w "$1" ]; then
 
199
        report Configuring "$1" in non-Unicode mode.
 
200
        printf '\033%%@' >"$1"
 
201
    else
 
202
        report No write access to $tty. Can not configure non-Unicode mode.
 
203
    fi
 
204
}
 
205
 
 
206
# Return code 0: we are on the console; 1: we are not on the console
 
207
test_console () {
 
208
    local ok
 
209
    ok=0
 
210
    if which tty >/dev/null; then
 
211
        case "`tty`" in
 
212
            /dev/tty[1-9]*|/dev/vc/[0-9]*|/dev/console|/dev/ttyv[0-9]*)
 
213
                return 0
 
214
                ;;
 
215
        esac
 
216
        ok=1
 
217
    fi
 
218
 
 
219
    if which kbd_mode >/dev/null; then
 
220
        mode="`(LC_ALL=C; export LC_ALL; kbd_mode) 2>&1`"
 
221
        mode=${mode#The keyboard is in }
 
222
        case "$mode" in
 
223
            Unicode*|default*|xlate*) return 0 ;;
 
224
        esac
 
225
        ok=1
 
226
    fi
 
227
 
 
228
    if which vidcontrol >/dev/null; then
 
229
        if vidcontrol -i adapter >&- 2>&-; then
 
230
            return 0
 
231
        fi
 
232
        ok=1
 
233
    fi
 
234
 
 
235
    return $ok
 
236
}
 
237
 
 
238
###########################################################################
 
239
### PROCESS THE COMMAND LINE ARGUMENTS
 
240
###########################################################################
 
241
 
37
242
while [ "$1" ]; do
38
243
    case "$1" in
39
244
        -k|--keyboard-only)
40
 
            keyboard_only=yes
 
245
            do_font=''
41
246
            ;;
42
247
        -f|--font-only)
43
 
            font_only=yes
 
248
            do_kbd=''
44
249
            ;;
45
250
        -v|--verbose)
46
 
            verbose_option=yes
 
251
            do_verbose=yes
47
252
            ;;
48
253
        --force)
49
 
            force=yes
 
254
            do_check=''
50
255
            ;;
51
256
        --save)
52
 
            save=yes
 
257
            do_save=yes
53
258
            ;;
54
259
        --save-only)
55
 
            force=yes
56
 
            save=yes
57
 
            save_only=yes
 
260
            do_save=yes
 
261
            do_kbd=''
 
262
            do_font=''
 
263
            do_check=''
58
264
            ;;
 
265
        --save-keyboard)
 
266
            shift
 
267
            savekbdfile="$1"
 
268
            do_kbd=''
 
269
            do_font=''
 
270
            do_check=''
 
271
            ;;
 
272
        --setup-dir)
 
273
            shift
 
274
            setupdir="$1"
 
275
            do_check=''
 
276
            ;;
59
277
        -h|--help)
60
278
            cat >&2 <<EOF
61
279
Usage: setupcon [OPTION] [VARIANT]
66
284
      --force          do not check whether we are on the console
67
285
  -v, --verbose        explain what is being doing, try it if s.t. goes wrong
68
286
      --save           copy the font and the console map in /etc/console-setup,
69
 
                         update /etc/console-setup/cached.kmap.gz
 
287
                         update /etc/console-setup/cached.*
70
288
      --save-only      only save; don't setup keyboard/font immediately
71
289
                         (implies --force)
72
290
  -h, --help           display this help and exit
95
313
    shift
96
314
done
97
315
 
 
316
# installdir
 
317
installdir=${0%/*}
 
318
case "$installdir" in
 
319
    */bin) installdir=${installdir%/bin} ;;
 
320
    *) installdir=$installdir/.. ;;
 
321
esac
 
322
[ -n "$installdir" -a -d "$installdir"/bin ] || installdir=/usr
 
323
 
 
324
 
 
325
###########################################################################
 
326
### READ THE CONFIGURATION FILES
 
327
###########################################################################
 
328
 
98
329
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"
102
 
else
103
 
    USER_CONFIG=${HOME}/.console-setup
104
 
    MAIN_CONFIG=/etc/default/keyboard
105
 
    MAIN_CONFIG2=/etc/default/console-setup
 
330
    VARIANT=".$VARIANT"
106
331
fi
107
332
 
 
333
USER_CONFIG=${HOME}/.console-setup"$VARIANT"
 
334
USER_CONFIG2=${HOME}/.keyboard"$VARIANT"
 
335
MAIN_CONFIG=/etc/default/keyboard"$VARIANT"
 
336
[ -f "$MAIN_CONFIG" ] \
 
337
    || MAIN_CONFIG="$installdir"/etc/default/keyboard"$VARIANT"
 
338
MAIN_CONFIG2=/etc/default/console-setup"$VARIANT"
 
339
[ -f "$MAIN_CONFIG2" ] \
 
340
    || MAIN_CONFIG2="$installdir"/etc/default/console-setup"$VARIANT"
 
341
 
108
342
if [ -f "$USER_CONFIG" ]; then
109
343
    CONFIG="$USER_CONFIG"
110
 
    CONFIG2=''
111
 
    save=
 
344
    CONFIG2="$USER_CONFIG2"
112
345
elif [ -f "$MAIN_CONFIG" ]; then
113
346
    CONFIG="$MAIN_CONFIG"
114
347
    CONFIG2="$MAIN_CONFIG2"
117
350
    exit 1
118
351
fi
119
352
 
120
 
if [ "$CONFIG2" -a -f "$CONFIG2" ]; then
 
353
if [ -f "$CONFIG2" ]; then
121
354
    . "$CONFIG2"
 
355
else
 
356
    # in order to permit "if [ cached.kmap.gz -ot $CONFIG2 ]; then ... fi"
 
357
    CONFIG2="$CONFIG"
122
358
fi
123
359
. "$CONFIG"
124
360
 
125
 
if [ "$verbose_option" = yes ]; then
126
 
    VERBOSE_OUTPUT=yes
127
 
fi
 
361
###########################################################################
 
362
### INITIALIZATION AND DEFAULT VALUES
 
363
###########################################################################
 
364
 
 
365
# do_verbose
 
366
# The variable VERBOSE_OUTPUT is obsoleted in favour of the option --verbose
128
367
if [ "$VERBOSE_OUTPUT" = yes ]; then
129
 
    verbose=''
 
368
    do_verbose=yes
 
369
fi
 
370
 
 
371
# kernel
 
372
kernel=unknown
 
373
if which uname >/dev/null; then
 
374
    case "`uname`" in
 
375
        *Linux*) kernel=linux ;;
 
376
        *FreeBSD*) kernel=freebsd ;;
 
377
        *)
 
378
            echo 'Unknown kernel (only Linux and FreeBSD are supported).' >&2
 
379
            exit 1
 
380
            ;;
 
381
    esac
 
382
fi
 
383
 
 
384
# do_save
 
385
if [ -n "$do_save" ]; then
 
386
    if [ ! -d /usr/share ]; then
 
387
        echo It seems /usr is not mounted.  Will not save files in /etc. >&2
 
388
        do_save=''
 
389
    elif [ ! -w /etc/console-setup/ ]; then
 
390
        echo /etc/console-setup is not writable.  No files will be saved there. >&2
 
391
        do_save=''
 
392
    fi
 
393
fi
 
394
 
 
395
# ACTIVE_CONSOLES
 
396
# When ACTIVE_CONSOLES=guess the following will result in ACTIVE_CONSOLES=''
 
397
ACTIVE_CONSOLES=$(
 
398
    for tty in $ACTIVE_CONSOLES; do
 
399
        if [ -e $tty ]; then
 
400
            echo $tty
 
401
        fi
 
402
    done
 
403
)
 
404
if [ -z "$ACTIVE_CONSOLES" ]; then
 
405
    # Some crude guess
 
406
    #  Conf. files:
 
407
    #    BSD:        /etc/ttys
 
408
    #    Sys V init: /etc/inittab
 
409
    #    Upstart:    /etc/init/*
 
410
    #  Devices:
 
411
    #    Linux:   /dev/tty[1-9][0-9]*
 
412
    #    FreeBSD: /dev/ttyv[0-9a-f]
 
413
    for tty in \
 
414
        $(cat /etc/inittab /etc/init/* /etc/ttys 2>/dev/null \
 
415
        | grep getty \
 
416
        | egrep '([[:blank:]]|^)tty([1-9][0-9]*|v[0-9a-f])([[:blank:]]|$)' \
 
417
        | sed -e '/^ *#/d' \
 
418
              -e 's/.*[[:blank:]]\(tty[1-9][0-9]*\).*/\1/' \
 
419
              -e 's/.*[[:blank:]]\(ttyv[0-9a-f]\).*/\1/')
 
420
    do
 
421
        if [ -e /dev/$tty ]; then
 
422
            ACTIVE_CONSOLES="$ACTIVE_CONSOLES /dev/$tty"
 
423
        fi
 
424
    done
 
425
fi
 
426
if [ -z "$ACTIVE_CONSOLES" ]; then
 
427
    case "$kernel" in
 
428
        linux) ACTIVE_CONSOLES=$(ls /dev/tty[1-6] 2>/dev/null) ;;
 
429
        freebsd) ACTIVE_CONSOLES=$(ls /dev/ttyv[0-3] 2>/dev/null) ;;
 
430
    esac
 
431
    report Can not find the active virtual consoles, \
 
432
        assuming ACTIVE_CONSOLES=\"$ACTIVE_CONSOLES\" >&2
130
433
else
131
 
    verbose='>/dev/null 2>&1'
 
434
    report Configuring $ACTIVE_CONSOLES
132
435
fi
133
436
 
134
 
if which ckbcomp-mini >/dev/null; then
135
 
    CHARMAP=UTF-8
136
 
    if [ "$VERBOSE_OUTPUT" = yes -a "$CHARMAP" != UTF-8 ]; then
137
 
        echo Only UTF-8 is supported by console-setup-mini
 
437
# CHARMAP
 
438
if [ "$CHARMAP" = guess -o -z "$CHARMAP" ]; then
 
439
    CHARMAP=''
 
440
    if which locale >/dev/null; then
 
441
        CHARMAP=`locale charmap`
138
442
    fi
139
443
fi
140
 
 
141
 
if [ "$force" != yes ]; then
142
 
    case `readlink /proc/self/fd/2` in
143
 
        /dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
144
 
            ;;
145
 
        *)
146
 
            echo We are not on the Linux console, the console is left unconfigured.
147
 
            exit 0 
148
 
            ;;
149
 
    esac
150
 
fi
151
 
 
152
 
ACTIVE_CONSOLES=${ACTIVE_CONSOLES:-/dev/tty[1-6]}
153
444
CHARMAP=${CHARMAP:-UTF-8}
154
 
CODESET=${CODESET:-Uni2}
 
445
# FreeBSD uses ISO8859-1, GNU uses ISO-8859-1, we use the GNU names
 
446
case "$CHARMAP" in
 
447
    ISO8859-*) CHARMAP="ISO-8859-${CHARMAP#ISO8859-}" ;;
 
448
    US-ASCII|ANSI*) CHARMAP=ISO-8859-1 ;;
 
449
esac
 
450
report The charmap is $CHARMAP
 
451
 
 
452
# unicode
 
453
if \
 
454
    [ "$CHARMAP" = UTF-8 ]
 
455
then
 
456
    unicode=yes
 
457
else
 
458
    unicode=''
 
459
fi
 
460
 
 
461
# do_font
 
462
if [ "$do_font" ]; then
 
463
    case "$kernel" in
 
464
        linux)
 
465
            if which consolechars >/dev/null ; then
 
466
                do_font=linuxct
 
467
            elif which setfont >/dev/null ; then
 
468
                do_font=linuxkbd
 
469
            else
 
470
                echo "Neither setfont nor consolechars is accessible. No font will be configured." >&2
 
471
                do_font=''
 
472
            fi
 
473
            ;;
 
474
        freebsd)
 
475
            if which vidcontrol >/dev/null ; then
 
476
                do_font=freebsd
 
477
            else
 
478
                echo "vidcontrol is not accessible. No font will be configured." >&2
 
479
                do_font=''
 
480
            fi
 
481
            ;;
 
482
    esac
 
483
fi
 
484
# Due to bug in splashy and usplash: do not load fonts (#540314)
 
485
if which pidof >/dev/null; then
 
486
    if pidof splashy > /dev/null || pidof usplash > /dev/null; then
 
487
        do_font=''
 
488
    fi
 
489
fi
 
490
 
 
491
# CODESET
 
492
[ "$CODESET" != guess ] || CODESET=''
 
493
if [ -z "$CODESET" ]; then
 
494
    case "$CHARMAP" in
 
495
        UTF-8)            CODESET=Uni2;;
 
496
        ARMSCII-8)        CODESET=Armenian ;;
 
497
        CP1251)           CODESET=CyrSlav ;;
 
498
        CP1255)           CODESET=Hebrew ;;
 
499
        CP1256)           CODESET=Arabic ;;
 
500
        GEORGIAN-ACADEMY) CODESET=Georgian ;;
 
501
        GEORGIAN-PS)      CODESET=Georgian ;;
 
502
        IBM1133)          CODESET=Lao ;;
 
503
        ISIRI-3342)       CODESET=Arabic ;;
 
504
        ISO-8859-1)       CODESET=Lat15 ;;
 
505
        ISO-8859-2)       CODESET=Lat2 ;;
 
506
        ISO-8859-3)       CODESET=Lat38 ;;
 
507
        ISO-8859-4)       CODESET=Lat7 ;; # sometimes Lat15
 
508
        ISO-8859-5)       CODESET=CyrSlav ;;
 
509
        ISO-8859-6)       CODESET=Arabic ;;
 
510
        ISO-8859-7)       CODESET=Greek ;;
 
511
        ISO-8859-8)       CODESET=Hebrew ;;
 
512
        ISO-8859-9)       CODESET=Lat15 ;;
 
513
        ISO-8859-10)      CODESET=Lat15 ;;
 
514
        ISO-8859-11)      CODESET=Thai ;;
 
515
        ISO-8859-13)      CODESET=Lat7 ;;
 
516
        ISO-8859-14)      CODESET=Lat38 ;;
 
517
        ISO-8859-15)      CODESET=Lat15 ;;
 
518
        ISO-8859-16)      CODESET=Lat2 ;;
 
519
        KOI8-R)           CODESET=CyrKoi ;;
 
520
        KOI8-U)           CODESET=CyrKoi ;;
 
521
        TIS-620)          CODESET=Thai ;;
 
522
        VISCII)           CODESET=Vietnamese ;;
 
523
        *)
 
524
            if [ "$do_font" ]; then
 
525
                echo Unsupported charmap $CHARMAP >&2
 
526
                exit 1
 
527
            fi
 
528
            ;;
 
529
    esac
 
530
    if [ "$kernel" = freebsd ]; then
 
531
        # 512 character fonts are not supported on FreeBSD
 
532
        case "$CODESET" in
 
533
            Uni*|Vietnamese|Arabic|Ethiopian) CODESET=Lat15 ;;
 
534
        esac
 
535
    fi
 
536
fi
 
537
if [ "$CHARMAP" != UTF-8 -a "$kernel" = freebsd ]; then
 
538
    if \
 
539
        [ -z "`findfile share/syscons/scrnmaps ${CHARMAP}_${CODESET}.scm`" ]
 
540
    then
 
541
        report "Ignoring the CODESET specification ($CODESET)."
 
542
        CODESET=`findfile share/syscons/scrnmaps ${CHARMAP}_*.scm`
 
543
        if [ -n "$do_font" -a -z "$CODESET" ]; then
 
544
            echo Unsupported charmap $CHARMAP >&2
 
545
            exit 1
 
546
        fi
 
547
        CODESET=${CODESET%%*/}
 
548
        CODESET=${CODESET#.scm*}
 
549
        CODESET=${CODESET%*_}
 
550
        report Using $CODESET instead.
 
551
    fi
 
552
fi
 
553
 
 
554
# FONTSIZE
 
555
if [ -z "$FONTSIZE" -o "$FONTSIZE" = guess ]; then
 
556
    FONTSIZE=16
 
557
fi
 
558
case "$FONTSIZE" in
 
559
    8x*)
 
560
        FONTSIZE=${FONTSIZE#*x}
 
561
        ;;
 
562
    *x8)
 
563
        FONTSIZE=${FONTSIZE%x*}
 
564
        ;;
 
565
    *x*)
 
566
        a=${FONTSIZE%x*}
 
567
        b=${FONTSIZE#*x}
 
568
        if [ "$a" -lt "$b" ]; then
 
569
            FONTSIZE=${b}x${a}
 
570
        fi
 
571
        ;;
 
572
esac
 
573
 
 
574
# mapdir, fontdir, stdfont, stdfontfallback
 
575
case "$kernel" in
 
576
    linux)
 
577
        mapdir=share/consoletrans
 
578
        stdmap=$CHARMAP.acm.gz
 
579
        fontdir=share/consolefonts
 
580
        stdfont=$CODESET-$FONTFACE$FONTSIZE.psf.gz
 
581
        # [A-WXYZa-wyz] is a funny way to say [A-Za-wyz].  In some locales 
 
582
        # [A-Z] includes x and we don't want this.
 
583
        stdfontfallback=$CODESET-*[A-WXYZa-wyz]$FONTSIZE.psf.gz
 
584
        ;;
 
585
    freebsd)
 
586
        mapdir=share/syscons/scrnmaps
 
587
        stdmap=${CHARMAP}_${CODESET}.scm
 
588
        fontdir=share/syscons/fonts
 
589
        stdfont16=$CODESET-${FONTFACE}16.fnt
 
590
        stdfont14=$CODESET-${FONTFACE}14.fnt
 
591
        stdfont8=$CODESET-${FONTFACE}8.fnt
 
592
        stdfontfallback16=$CODESET-*[A-WXYZa-wyz]16.fnt
 
593
        stdfontfallback14=$CODESET-*[A-WXYZa-wyz]14.fnt
 
594
        stdfontfallback8=$CODESET-*[A-WXYZa-wyz]8.fnt
 
595
        ;;
 
596
esac
 
597
 
 
598
# CONSOLE_MAP
155
599
CONSOLE_MAP=${CONSOLE_MAP:-$ACM}
156
 
 
157
 
#-----------------------#
158
 
#       OUTPUT          #
159
 
#-----------------------#
160
 
 
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
166
 
            if \
167
 
                [ "$CHARMAP" = UTF-8 ] || [ -z "$CONSOLE_MAP$CHARMAP" ]
168
 
            then
169
 
                printf '\033%%G' >$console
170
 
            else
171
 
                printf '\033%%@' >$console
172
 
            fi
173
 
        done
174
 
    fi
175
 
    
176
 
    # Load the font
177
 
    if [ -z "$FONT" ]; then
178
 
        FONT_MAP=''
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`)
182
 
            FONT=${FONT%% *}
183
 
            if [ "$FONTFACE" ] || [ "$FONTSIZE" ]; then
184
 
                eval echo setupcon: Warning: ignoring the FONTFACE and FONTSIZE specifications! $verbose
185
 
            fi
186
 
        elif [ "$FONTFACE" ] && [ "$FONTSIZE" ]; then
187
 
            FONT="$CODESET-$FONTFACE$FONTSIZE.psf.gz"
188
 
            case "$FONTSIZE" in
189
 
                *x*)
190
 
                    bigfont=yes
191
 
                    ;;
192
 
                *)
193
 
                    bigfont=no
194
 
                    ;;
195
 
            esac
196
 
        fi
197
 
    fi
198
 
    LOADFONTS=''
 
600
[ -z "$CONSOLE_MAP" ] || CONSOLE_MAP=`findfile $mapdir "$CONSOLE_MAP"`
 
601
[ -n "$CONSOLE_MAP" -o "$CHARMAP" = UTF-8 ] || CONSOLE_MAP=`findfile $mapdir $stdmap`
 
602
[ -n "$CONSOLE_MAP" -o "$CHARMAP" = UTF-8 ] || CONSOLE_MAP=`findfile $mapdir ${stdmap%.gz}`
 
603
 
 
604
# FONTFILES
 
605
FONTFILES=''
 
606
if [ "$FONT" ]; then
199
607
    for f in $FONT; do
200
 
        if [ -f "$f" ]; then
201
 
            LOADFONTS="$LOADFONTS $f"
202
 
        else
203
 
            fdec="${f%.gz}"
204
 
            for dir in \
205
 
                /usr/local/share/consolefonts \
206
 
                /usr/share/consolefonts \
207
 
                /etc/console-setup \
208
 
                FONT_IS_MISSING
209
 
            do
210
 
                if [ -f "$dir/${f##*/}" ]; then
211
 
                    LOADFONTS="$LOADFONTS $dir/${f##*/}"
212
 
                    break
213
 
                elif [ -f "$dir/${fdec##*/}" ]; then
214
 
                    LOADFONTS="$LOADFONTS $dir/${fdec##*/}"
215
 
                    break
216
 
                fi
217
 
                if [ "$dir" = FONT_IS_MISSING ]; then
218
 
                    echo setupcon: Warning: the font ${f##*/} does not exist! >&2
219
 
                fi
220
 
            done
221
 
        fi
222
 
    done
223
 
    LOADFONT_MAP=''
224
 
    for f in $FONT_MAP; do
225
 
        [ -z "$LOADFONT_MAP" ] || break # only one unicode map
226
 
        if [ -f "$f" ]; then
227
 
            LOADFONT_MAP="$LOADFONT_MAP $f"
228
 
        else
229
 
            for dir in \
230
 
                /usr/local/share/consoletrans \
231
 
                /usr/share/consoletrans \
232
 
                /etc/console-setup \
233
 
                FONT_MAP_IS_MISSING
234
 
            do
235
 
                if [ -f "$dir/${f##*/}" ]; then
236
 
                    LOADFONT_MAP="$LOADFONT_MAP $dir/${f##*/}"
237
 
                    break
238
 
                fi
239
 
                if [ "$dir" = FONT_MAP_IS_MISSING ]; then
240
 
                    echo setupcon: Warning: the unicode map ${f##*/} does not exist! >&2
241
 
                fi
242
 
            done
243
 
        fi
244
 
    done
245
 
    
246
 
    for f in $LOADFONTS; do
247
 
        if \
248
 
            [ "$save" = yes ] \
249
 
            && [ "${f%/*}" != /etc/console-setup ]
250
 
        then
251
 
            fdec="${f%.gz}"
252
 
            if [ "$fdec" = "$f" ]; then
253
 
                cp "$f" /etc/console-setup/
254
 
            else
255
 
                gunzip -c "$f" >"/etc/console-setup/${fdec##*/}"
256
 
            fi
257
 
            rm -f "/etc/console-setup/${fdec##*/}.gz"
258
 
        fi
259
 
    done
260
 
    for f in $LOADFONT_MAP; do
261
 
        if \
262
 
            [ "$save" = yes ] \
263
 
            && [ "${f%/*}" != /etc/console-setup ]
264
 
        then
265
 
            cp "$f" /etc/console-setup/
266
 
        fi
267
 
    done
268
 
    
269
 
    # Due to bug in splashy and usplash: do not load fonts (#540314)
270
 
    if \
271
 
        pidof splashy > /dev/null \
272
 
        || pidof usplash > /dev/null
273
 
    then
274
 
        LOADFONTS=''
275
 
    fi
276
 
 
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
283
 
                fi
284
 
                if [ "$LOADFONT_MAP" ]; then
285
 
                    eval consolechars -v --tty=$console -f $LOADFONTS -u "$LOADFONT_MAP" $verbose
286
 
                else
287
 
                    eval consolechars -v --tty=$console -f $LOADFONTS $verbose
288
 
                fi
289
 
            elif which setfont >/dev/null; then
290
 
                if [ "$LOADFONT_MAP" ]; then
291
 
                    eval setfont -v -C $console $LOADFONTS -u "$LOADFONT_MAP" $verbose
292
 
                else
293
 
                    eval setfont -v -C $console $LOADFONTS $verbose
294
 
                fi
295
 
            fi
296
 
        done
297
 
    fi
298
 
    
299
 
    # Load the ACM
300
 
    if [ ! -f "$CONSOLE_MAP" ]; then
301
 
        for dir in \
302
 
            /usr/local/share/consoletrans \
303
 
            /usr/share/consoletrans \
304
 
            /etc/console-setup 
305
 
        do
306
 
            if [ -f "$dir/$CHARMAP.acm.gz" ]; then
307
 
                CONSOLE_MAP="$dir/$CHARMAP.acm.gz"
308
 
                break
309
 
            elif [ -f "$dir/$CHARMAP.acm" ]; then
310
 
                ACM="$dir/$CHARMAP.acm"
311
 
                break
312
 
            fi
313
 
        done
314
 
    fi
315
 
    if [ -f "$CONSOLE_MAP" ]; then
316
 
        if \
317
 
            [ "$save" = yes ] \
318
 
            && [ "${CONSOLE_MAP%/*}" != /etc/console-setup ]
319
 
        then
320
 
            console_map_dec="${CONSOLE_MAP%.gz}"
321
 
            if [ "$console_map_dec" = "$CONSOLE_MAP" ]; then
322
 
                cp "$CONSOLE_MAP" /etc/console-setup/
323
 
            else
324
 
                gunzip -c "$CONSOLE_MAP" >"/etc/console-setup/${console_map_dec##*/}"
325
 
            fi
326
 
            rm -f "/etc/console-setup/${console_map_dec##*/}.gz"
327
 
        fi
328
 
    else
329
 
        CONSOLE_MAP="$CHARMAP.acm.gz"
330
 
    fi
331
 
    if \
332
 
        [ "$save_only" != yes ] && [ "$CHARMAP" != UTF-8 ] && [ "$LOADFONTS" ]
333
 
    then
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
340
 
            fi      
341
 
        done
342
 
    fi
343
 
 
344
 
    STTY=""
 
608
        RES=`findfile $fontdir $f`
 
609
        if [ -z "$RES" ]; then
 
610
            fdec="${f%.gz}"
 
611
            RES=`findfile $fontdir $fdec`
 
612
        fi
 
613
        FONTFILES="$FONTFILES $RES"
 
614
    done
 
615
fi
 
616
FONTFILES=`echo $FONTFILES` # remove extra spaces
 
617
if [ -n "$FONTFACE" -a -z "$FONTFILES" ]; then
 
618
    case "$kernel" in
 
619
        linux)
 
620
            # the following will fail if FONTFACE=guess ($stdfont will
 
621
            # match nothing)
 
622
            FONTFILES=`findfile $fontdir $stdfont`
 
623
            [ "$FONTFILES" ] || FONTFILES=`findfile $fontdir $stdfontfallback`
 
624
            case "$FONTFILES" in
 
625
                *[0-9]x[1-9]*.psf.gz)
 
626
                    if which consolechars >/dev/null; then
 
627
                        echo "\
 
628
The consolechars utility from the \"console-tools\" package can load only fonts
 
629
with 8 pixel width matrix.  Please install the setfont utility from the package
 
630
\"kbd\" or reconfigure the font size." >&2
 
631
                    fi
 
632
                    ;;
 
633
            esac
 
634
            ;;
 
635
        freebsd)
 
636
            FONTFILES=`findfile $fontdir $stdfont16`
 
637
            [ "$FONTFILES" ] || FONTFILES=`findfile $fontdir $stdfontfallback16`
 
638
            font=`findfile $fontdir $stdfont14`
 
639
            [ "$font" ] || font=`findfile $fontdir $stdfontfallback14`
 
640
            [ -z "$font" ] || FONTFILES="$FONTFILES $font"
 
641
            font=`findfile $fontdir $stdfont8`
 
642
            [ "$font" ] || font=`findfile $fontdir $stdfontfallback8`
 
643
            [ -z "$font" ] || FONTFILES="$FONTFILES $font"
 
644
            ;;
 
645
    esac
 
646
    if [ -n "$do_font" -a -z "$FONTFILES" ]; then
 
647
        echo Unable to find the required font.  No font will be configured. >&2
 
648
        do_font=''
 
649
    fi
 
650
fi
 
651
 
 
652
# FONTMAPFILE
 
653
FONTMAPFILE=''
 
654
if [ "$kernel" = linux -a -n "$FONT_MAP" ]; then
 
655
    FONTMAPFILE=`findfile share/consoletrans "$FONT_MAP"`
 
656
fi
 
657
 
 
658
# XKBMODEL
 
659
if [ -n "$do_kbd$do_save$savekbdfile$setupdir" -a "$XKBMODEL" = unknown ]; then
 
660
    echo The keyboard model is unknown.  Keyboard will not be configured. >&2
 
661
    XKBMODEL=''
 
662
fi
 
663
[ -n "$XKBMODEL" -o -z "$savekbdfile" ] || exit 1
 
664
 
 
665
# Backwards-compatibility with Ubuntu-specific preseeding
 
666
if [ "$XKBMODEL" = SKIP ]; then
 
667
    XKBMODEL=
 
668
fi
 
669
 
 
670
# do_kbd
 
671
[ "$XKBMODEL" ] || do_kbd=''
 
672
if [ "$do_kbd" ]; then
 
673
    case "$kernel" in
 
674
        linux)
 
675
            if which loadkeys >/dev/null; then
 
676
                do_kbd=linux
 
677
            else
 
678
                echo loadkeys is not accessible. Keyboard will not be configured.>&2
 
679
                do_kbd=''
 
680
            fi
 
681
            ;;
 
682
        freebsd)
 
683
            if which kbdcontrol >/dev/null; then
 
684
                do_kbd=freebsd
 
685
            else
 
686
                echo kbdcontrol is not accessible. Keyboard will not be configured.>&2
 
687
                do_kbd=''
 
688
            fi
 
689
            ;;
 
690
    esac
 
691
fi
 
692
 
 
693
# acm_option
 
694
if [ "$CHARMAP" != UTF-8 ]; then
 
695
    acm_option="-charmap $CHARMAP"
 
696
elif [ "$kernel" = freebsd ]; then
 
697
    acm_option='-charmap ISO-8859-1'
 
698
else
 
699
    acm_option=''
 
700
fi
 
701
 
 
702
# rules_option
 
703
if [ "$XKBRULES" ]; then
 
704
    rules_option="-rules $XKBRULES"
 
705
else
 
706
    rules_option=''
 
707
fi
 
708
 
 
709
# backspace
 
710
case "$kernel" in
 
711
    linux) backspace='del' ;;
 
712
    freebsd) backspace='bs' ;;
 
713
esac
 
714
case \
 
715
    "`(stty -a \
 
716
          | egrep '(^| )erase *=' \
 
717
          | sed -e 's/.* erase *= *//' -e 's/^erase *= *//' -e 's/[; ].*//') \
 
718
      2>/dev/null`"
 
719
in
 
720
    ^\?) backspace='del' ;;
 
721
    ^h|^H) backspace='bs' ;;
 
722
esac
 
723
case "$BACKSPACE" in
 
724
    del) backspace='del' ;;
 
725
    bs) backspace='bs' ;;
 
726
esac
 
727
case "$backspace" in
 
728
    del) report BackSpace is ^? ;;
 
729
    bs) report BackSpace is ^h ;;
 
730
    *) echo Wrong BackSpace option >&2 ;;
 
731
esac
 
732
 
 
733
# cached
 
734
case "$kernel" in
 
735
    linux)
 
736
        cached=/etc/console-setup/cached$VARIANT.kmap.gz
 
737
        ;;
 
738
    freebsd)
 
739
        cached=/etc/console-setup/cached$VARIANT.kbd
 
740
        ;;
 
741
esac
 
742
 
 
743
# savekbdfile
 
744
if \
 
745
    [ -z "$savekbdfile" -a -n "$do_save" ] \
 
746
    && [ ! -f "$cached" \
 
747
         -o ! "$CONFIG" -ot "$cached" \
 
748
         -o ! "$CONFIG2" -ot "$cached" ]
 
749
then
 
750
    savekbdfile="$cached"
 
751
fi
 
752
if [ -z "$savekbdfile" -a -n "$setupdir" ]; then
 
753
    mkdir -p "$setupdir"/etc/console-setup
 
754
    case "$kernel" in
 
755
        linux) savekbdfile="$setupdir"/etc/console-setup/cached.kmap.gz ;;
 
756
        freebsd) savekbdfile="$setupdir"/etc/console-setup/cached.kbd ;;
 
757
    esac
 
758
fi
 
759
[ "$XKBMODEL" ] || savekbdfile=''
 
760
if [ "$kernel" = linux ] && ! which gzip >/dev/null; then
 
761
    savekbdfile=''
 
762
    echo gzip is not accessible.  Will not save cached keyboard map. >&2
 
763
fi
 
764
 
 
765
# KMAP
 
766
if [ -n "$KMAP" -a ! -f "$KMAP" ]; then
 
767
    echo $KMAP does not exist. >&2
 
768
    KMAP=''
 
769
fi
 
770
 
 
771
 
 
772
###########################################################################
 
773
### SAVE THE FILES IN /etc
 
774
###########################################################################
 
775
 
 
776
if [ -n "$do_save" ]; then
 
777
    case "$CONSOLE_MAP" in
 
778
        /etc/console-setup/*) ;;
 
779
        ?*)
 
780
            console_map_dec="${CONSOLE_MAP%.gz}"
 
781
            if [ "$console_map_dec" = "$CONSOLE_MAP" ]; then
 
782
                cp "$CONSOLE_MAP" /etc/console-setup/
 
783
            else
 
784
                gunzip -c "$CONSOLE_MAP" >"/etc/console-setup/${console_map_dec##*/}"
 
785
            fi
 
786
            rm -f "/etc/console-setup/${console_map_dec##*/}.gz"
 
787
            ;;
 
788
    esac
 
789
    for font in $FONTFILES; do
 
790
        case "$font" in
 
791
            /etc/console-setup/*) ;;
 
792
            ?*) cp "$font" /etc/console-setup/ ;;
 
793
        esac
 
794
    done
 
795
    case "$FONTMAPFILE" in
 
796
        /etc/console-setup/*) ;;
 
797
        ?*) cp "$FONTMAPFILE" /etc/console-setup/ ;;
 
798
    esac
 
799
fi
 
800
 
 
801
if [ "$savekbdfile" ]; then
 
802
    case "$kernel" in
 
803
        linux)
 
804
            tempfile || { echo Can not create temporary file >&2; exit 1; }
 
805
            {
 
806
                $installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
 
807
                    $rules_option -model "$XKBMODEL" \
 
808
                    "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE \
 
809
                    && gzip -9 <$TMPFILE >"$savekbdfile"
 
810
            } || exit 1
 
811
            rm $TMPFILE
 
812
            ;;
 
813
        freebsd)
 
814
            $installdir/bin/ckbcomp -freebsd -backspace "$backspace" \
 
815
                $acm_option $rules_option -model "$XKBMODEL" \
 
816
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >"$savekbdfile" \
 
817
                || exit 1
 
818
            ;;
 
819
    esac
 
820
fi
 
821
 
 
822
 
 
823
###########################################################################
 
824
### ARE WE ON THE CONSOLE?
 
825
###########################################################################
 
826
 
 
827
if [ "$do_check" ]; then
 
828
    if ! test_console; then
 
829
        echo We are not on the console, the console is left unconfigured. >&2
 
830
        exit 0
 
831
    fi
 
832
fi
 
833
 
 
834
 
 
835
###########################################################################
 
836
### OUTPUT
 
837
###########################################################################
 
838
 
 
839
# Video mode
 
840
if [ "$VIDEOMODE" ]; then
 
841
    case "$do_font" in
 
842
        freebsd)
 
843
            run in ECHO vidcontrol "$VIDEOMODE"
 
844
            ;;
 
845
        linux*)
 
846
            # this is a bit pointless as vesafb doesn't support changing mode
 
847
            if which fbset >/dev/null; then
 
848
                run plain ECHO fbset -a "$VIDEOMODE"
 
849
            else
 
850
                report fbset is not installed
 
851
            fi
 
852
            ;;
 
853
    esac
 
854
fi
 
855
 
 
856
# Setup unicode/non-unicode mode
 
857
case "$do_font" in
 
858
    # So far the FreeBSD kernel doesn't support changes of the mode from
 
859
    # utf to 8-bit and vice versa (its a compile time option).
 
860
    linux*)
 
861
        if [ "$unicode" ]; then
 
862
            run '' ECHO utf_start
 
863
        else
 
864
            run '' ECHO utf_stop
 
865
        fi
 
866
        ;;
 
867
esac
 
868
 
 
869
# Load the font(s)
 
870
if [ "$FONTFILES" ]; then
 
871
    case "$do_font" in
 
872
        freebsd)
 
873
            if [ -z "$unicode" ]; then
 
874
                for font in $FONTFILES; do
 
875
                    run plain ECHO vidcontrol -f $font
 
876
                done
 
877
            fi
 
878
            ;;
 
879
        linuxkbd)
 
880
            if [ "$FONTMAPFILE" ]; then
 
881
                run '-C ' -v setfont $FONTFILES -u "$FONTMAPFILE"
 
882
            else
 
883
                run '-C ' -v setfont $FONTFILES
 
884
            fi
 
885
            ;;
 
886
        linuxct)
 
887
            if [ "$FONTMAPFILE" ]; then
 
888
                run --tty= -v consolechars -f ${FONTFILES%% *} -u "$FONTMAPFILE"
 
889
            else
 
890
                run --tty= -v consolechars -f ${FONTFILES%% *}
 
891
            fi
 
892
            ;;
 
893
    esac
 
894
fi
 
895
 
 
896
# Load the console map
 
897
if [ "$CONSOLE_MAP" ]; then
 
898
    case "$do_font" in
 
899
        freebsd)
 
900
            if [ -z "$unicode" ]; then
 
901
                run plain ECHO vidcontrol -l "$CONSOLE_MAP"
 
902
            fi
 
903
            ;;
 
904
        linuxkbd)
 
905
            run '-C ' -v setfont -m "$CONSOLE_MAP"
 
906
            ;;
 
907
        linuxct)
 
908
            run --tty= -v consolechars --acm "$CONSOLE_MAP"
 
909
            ;;
 
910
    esac
 
911
fi
 
912
 
 
913
# Setup the terminal width and height
 
914
if [ "$do_font" ]; then
 
915
    STTY=''
345
916
    [ -z "$SCREEN_WIDTH"  ] || STTY="$STTY cols $SCREEN_WIDTH"
346
917
    [ -z "$SCREEN_HEIGHT" ] || STTY="$STTY rows $SCREEN_HEIGHT"
347
918
 
348
 
    if [ -n "$STTY" ]
349
 
    then
350
 
        for console in $ACTIVE_CONSOLES; do
351
 
            [ -r $console ] || continue
352
 
            stty $STTY < $console
353
 
        done
 
919
    if [ "$STTY" ]; then
 
920
        run in ECHO stty $STTY
354
921
    fi
355
922
fi
356
923
 
357
 
#-----------------------#
358
 
#        INPUT          #
359
 
#-----------------------#
360
 
 
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
 
924
 
 
925
###########################################################################
 
926
### INPUT
 
927
###########################################################################
 
928
 
 
929
# On Mac PPC machines, we may need to set kernel vars first.  We need
 
930
# to mount /proc to do that, but we need it set up before sulogin may
 
931
# be run in checkroot, which will need the keyboard to log in...
 
932
# This code was borrowed from the keymap.sh script of console-common
 
933
# Copyright © 2001 Yann Dirson
 
934
# Copyright © 2001 Alcove http://www.alcove.fr/
 
935
if [ "$do_kbd" = linux ]; then
 
936
    if [ -x /sbin/sysctl -a -r /etc/sysctl.conf ]; then
371
937
        if grep -v '^\#' /etc/sysctl.conf | grep -q keycodes ; then
372
938
            grep keycodes /etc/sysctl.conf | grep -v "^#" \
373
939
                | while read d ; do
374
 
                      /sbin/sysctl -w $d 2> /dev/null || true
375
 
                  done
376
 
        fi
377
 
    fi
378
 
    
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
385
 
                else
386
 
                    kbd_mode -a <$console
387
 
                fi
388
 
            fi
389
 
        done
390
 
    fi
391
 
    
392
 
    if which loadkeys >/dev/null && [ "$XKBMODEL" != SKIP ]; then
393
 
        if [ "$CHARMAP" != UTF-8 ]; then
394
 
            acm_option="-charmap $CHARMAP"
395
 
        else
396
 
            acm_option=''
397
 
        fi
398
 
        
399
 
        if [ "$XKBRULES" ]; then
400
 
            rules_option="-rules $XKBRULES"
401
 
        else
402
 
            rules_option=''
403
 
        fi
404
 
        
405
 
        if \
406
 
            [ "$VARIANT" = '' ] \
407
 
            && which gzip >/dev/null \
408
 
            && [ -d /usr/share ] # /usr is mounted
409
 
        then
410
 
            if \
411
 
                [ ! -f /etc/console-setup/cached.kmap.gz ] \
412
 
                || [ /etc/console-setup/cached.kmap.gz \
413
 
                     -ot /etc/default/keyboard ] \
414
 
                || [ "$save" = yes ]
415
 
            then
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
420
 
            fi
421
 
        fi
422
 
        
423
 
        if [ "$save_only" != yes ]; then
424
 
            if [ "$KMAP" -a -f "$KMAP" ]; then
425
 
                eval loadkeys "$KMAP" $verbose
426
 
            else                    
427
 
                if \
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 ]
432
 
                then
433
 
                    eval loadkeys /etc/console-setup/cached.kmap.gz $verbose
434
 
                else
435
 
                    if [ -d /usr/share ]; then
436
 
                        ckbcomp $acm_option $rules_option \
437
 
                            -model "$XKBMODEL" \
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
442
 
                    fi
443
 
                fi
444
 
            fi
445
 
        fi
446
 
    fi
 
940
                /sbin/sysctl -w $d 2> /dev/null || true
 
941
            done
 
942
        fi
 
943
    fi
 
944
fi
 
945
 
 
946
# Setup unicode/non-unicode mode
 
947
if [ "$do_kbd" = linux ]; then
 
948
    if which kbd_mode >/dev/null; then
 
949
        if [ "$unicode" ]; then
 
950
            run in ECHO kbd_mode -u
 
951
        else
 
952
            run in ECHO kbd_mode -a
 
953
        fi
 
954
    else
 
955
        report kbd_mode is not accessible.  Unable to setup unicode/non-unicode keyboard mode.
 
956
    fi
 
957
fi
 
958
 
 
959
if \
 
960
    [ -z "$KMAP" -a -f "$cached" ] \
 
961
    && [ "$CONFIG" -ot "$cached" -a "$CONFIG2" -ot "$cached" ]
 
962
then
 
963
    KMAP="$cached"
 
964
fi
 
965
 
 
966
if [ "$KMAP" ]; then
 
967
    case "$do_kbd" in
 
968
        linux) run plain '' loadkeys "$KMAP" ;;
 
969
        freebsd) run in ECHO kbdcontrol -l "$KMAP" ;;
 
970
    esac
 
971
else
 
972
    tempfile || { echo Can not create temporary file >&2; exit 1; }
 
973
    case "$do_kbd" in
 
974
        linux)
 
975
            $installdir/bin/ckbcomp -backspace "$backspace" $acm_option \
 
976
                $rules_option -model "$XKBMODEL" \
 
977
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE
 
978
            run plain ECHO loadkeys $TMPFILE
 
979
            ;;
 
980
        freebsd)
 
981
            $installdir/bin/ckbcomp -freebsd -backspace "$backspace" \
 
982
                $acm_option $rules_option -model "$XKBMODEL" \
 
983
                "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" >$TMPFILE
 
984
            run in ECHO kbdcontrol -l $TMPFILE
 
985
            run in ECHO kbdcontrol -f 70 "`printf '\033[3~'`"
 
986
            ;;
 
987
    esac
 
988
    rm $TMPFILE
 
989
fi
 
990
 
 
991
 
 
992
###########################################################################
 
993
### SETUPDIR
 
994
###########################################################################
 
995
 
 
996
 
 
997
 
 
998
if [ "$setupdir" ]; then
 
999
 
 
1000
    filearg () {
 
1001
        case "$1" in
 
1002
            *.kmap.gz|*.kbd|*/tmpkbd.*)
 
1003
                echo -n "/etc/console-setup/${savekbdfile##*/} "
 
1004
                ;;
 
1005
            /*)
 
1006
                if [ -e "$1" ]; then
 
1007
                    if [ ! -e "$setupdir/etc/console-setup/${1##*/}" ]; then
 
1008
                        cp -a "$1" "$setupdir/etc/console-setup/${1##*/}"
 
1009
                    fi
 
1010
                    echo -n "/etc/console-setup/${1##*/} "
 
1011
                else
 
1012
                    echo -n "$1 "
 
1013
                fi
 
1014
                ;;
 
1015
            *)
 
1016
                echo -n "$1 "
 
1017
                ;;
 
1018
        esac
 
1019
    }
 
1020
 
 
1021
    mkdir -p "$setupdir"/bin
 
1022
 
 
1023
    echo '#!/bin/sh' >"$setupdir"/bin/setupcon
 
1024
    echo '# A micro-version of setupcon with static configuration.' >>"$setupdir"/bin/setupcon
 
1025
    chmod +x "$setupdir"/bin/setupcon
 
1026
    tempfile || { echo Can not create temporary file >&2; exit 1; }
 
1027
    echo "$SETUP" |
 
1028
    while read cmd args; do
 
1029
        case "$cmd $args" in
 
1030
            utf_start*)
 
1031
                echo -n printf \'\\\\'033%%G'\'' >' # not for FreeBSD
 
1032
                filearg "${args%% *}"
 
1033
                echo
 
1034
                ;;
 
1035
            utf_stop*)
 
1036
                echo -n printf \'\\\\'033%%@'\'' >' # not for FreeBSD
 
1037
                filearg "${args%% *}"
 
1038
                echo
 
1039
                ;;
 
1040
            kbdcontrol?-f?70*)
 
1041
                echo kbdcontrol -f 70 \"\`printf \'\\\\033[3~\'\`\"
 
1042
                ;;
 
1043
            *)
 
1044
                which "$cmd" >>$TMPFILE || true
 
1045
                echo -n "$cmd "
 
1046
                for arg in $args; do
 
1047
                    filearg "$arg"
 
1048
                done
 
1049
                echo
 
1050
                ;;
 
1051
        esac
 
1052
    done >>"$setupdir"/bin/setupcon
 
1053
    echo exit 0 >>"$setupdir"/bin/setupcon
 
1054
    sort $TMPFILE | uniq >"$setupdir"/morefiles
 
1055
    rm $TMPFILE
447
1056
fi
448
1057
 
449
1058
exit 0