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

« back to all changes in this revision

Viewing changes to setupcon

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-01-05 17:02:40 UTC
  • mfrom: (3.2.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110105170240-2i4fqtyjjikwlnit
Tags: 1.57ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Use keymapper to generate decision trees for a restricted subset of
    the pc105 model.
  - 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.
  - Reset keyboard-configuration/toggle to the default if it's set to "No
    toggling" and you select a non-Latin layout.
  - Change the default font from Fixed to VGA for Lat15; while it's not
    entirely complete, it looks better and is largely good enough.
  - 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.
  - Set keymap and font in the initramfs if possible and sensible.
  - Set default variant for French to oss.
  - Set default for Dutch to us(intl), not just us.
  - Set default layout for Vietnam to 'us'.
  - Set default layout for Kurdish to tr(ku).
  - Stop running debconf-updatepo on clean.
  - Update for new layouts and variants for Montenegro and Serbia, and
    migrate configuration files from the old layouts.
  - Add a "Do not configure keyboard; keep kernel keymap" model option,
    preseedable by keyboard-configuration/modelcode=SKIP.
  - Drop the layout/variant priority to high on fresh installs.
  - Honour OVERRIDE_ALLOW_PRESEEDING environment variable when deciding
    whether to allow preseeding, which is ordinarily only allowed in d-i.
  - 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.
  - Add an apport hook.
  - Generate a locale locally for translating keyboard names in
    kbdnames-maker.
  - Replace usplash detection code with Plymouth detection code.
  - 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.
  - Depend on kbd (>= 1.15-1ubuntu3) for a valuable loadkeys improvement.
  - Don't try to call update-rc.d if it doesn't exist, such as in d-i.
  - 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.
  - Remove iconv transliteration.  We don't use non-UTF-8 locales, and it
    breaks ubiquity as we haven't generated the configured locale by the
    time we hit console-setup.
* Go back to always asking layout before variant.
* Migrate from old console-setup/* to new keyboard-configuration/*
  question names.
* Use the default keyboard model if an existing configuration file sets
  XKBMODEL="".
* Exit cleanly from initramfs hook if /etc/default/keyboard or
  /etc/default/console-setup don't exist for some reason (LP: #634402).
* Fix description of upstart job to not incorrectly claim that it sets the
  font (LP: #632366).

Show diffs side-by-side

added added

removed removed

Lines of Context:
65
65
  -f, --font-only      setup the font only, do not setup the keyboard
66
66
      --force          do not check whether we are on the console
67
67
  -v, --verbose        explain what is being doing, try it if s.t. goes wrong
68
 
      --save           copy the font and the ACM in /etc/console-setup,
 
68
      --save           copy the font and the console map in /etc/console-setup,
69
69
                         update /etc/console-setup/cached.kmap.gz
70
70
      --save-only      only save; don't setup keyboard/font immediately
71
71
                         (implies --force)
72
72
  -h, --help           display this help and exit
73
73
 
74
74
If VARIANT is not specified setupcon looks for the configuration files
75
 
(in this order) ~/.console-setup and /etc/default/console-setup.  When
 
75
(in this order) ~/.console-setup and if this doesn't exist then the
 
76
combination/etc/default/keyboard + /etc/default/console-setup.  When
76
77
a VARIANT is specified then setupcon looks for the configuration files
77
78
~/.console-setup.VARIANT and /etc/default/console-setup.VARIANT.
78
79
EOF
96
97
 
97
98
if [ "$VARIANT" ]; then
98
99
    USER_CONFIG=${HOME}/.console-setup."$VARIANT"
99
 
    MAIN_CONFIG=/etc/default/console-setup."$VARIANT"
 
100
    MAIN_CONFIG=/etc/default/keyboard."$VARIANT"
 
101
    MAIN_CONFIG2=/etc/default/console-setup."$VARIANT"
100
102
else
101
103
    USER_CONFIG=${HOME}/.console-setup
102
 
    MAIN_CONFIG=/etc/default/console-setup
 
104
    MAIN_CONFIG=/etc/default/keyboard
 
105
    MAIN_CONFIG2=/etc/default/console-setup
103
106
fi
104
107
 
105
108
if [ -f "$USER_CONFIG" ]; then
106
109
    CONFIG="$USER_CONFIG"
 
110
    CONFIG2=''
107
111
    save=
108
112
elif [ -f "$MAIN_CONFIG" ]; then
109
113
    CONFIG="$MAIN_CONFIG"
 
114
    CONFIG2="$MAIN_CONFIG2"
110
115
else
111
116
    echo "setupcon: None of $MAIN_CONFIG nor $USER_CONFIG exists." >&2
112
117
    exit 1
113
118
fi
114
119
 
 
120
if [ "$CONFIG2" -a -f "$CONFIG2" ]; then
 
121
    . "$CONFIG2"
 
122
fi
115
123
. "$CONFIG"
116
124
 
117
 
if [ -d /lib/debian-installer ]; then
118
 
    CHARMAP=UTF-8
119
 
fi
120
 
 
121
125
if [ "$verbose_option" = yes ]; then
122
126
    VERBOSE_OUTPUT=yes
123
127
fi
127
131
    verbose='>/dev/null 2>&1'
128
132
fi
129
133
 
130
 
if which ckbcomp-mini >/dev/null && [ "$CHARMAP" != UTF-8 ]; then
 
134
if which ckbcomp-mini >/dev/null; then
131
135
    CHARMAP=UTF-8
132
 
    if [ "$VERBOSE_OUTPUT" = yes ]; then
 
136
    if [ "$VERBOSE_OUTPUT" = yes -a "$CHARMAP" != UTF-8 ]; then
133
137
        echo Only UTF-8 is supported by console-setup-mini
134
138
    fi
135
139
fi
139
143
        /dev/tty[0-9]*|/dev/vc/[0-9]*|/dev/console)
140
144
            ;;
141
145
        *)
142
 
            if [ "$VERBOSE_OUTPUT" = yes ]; then
143
 
                echo We are not on the Linux console, exiting.
144
 
            fi
 
146
            echo We are not on the Linux console, the console is left unconfigured.
145
147
            exit 0 
146
148
            ;;
147
149
    esac
148
150
fi
149
151
 
 
152
ACTIVE_CONSOLES=${ACTIVE_CONSOLES:-/dev/tty[1-6]}
 
153
CHARMAP=${CHARMAP:-UTF-8}
 
154
CODESET=${CODESET:-Uni2}
 
155
CONSOLE_MAP=${CONSOLE_MAP:-$ACM}
 
156
 
150
157
#-----------------------#
151
158
#       OUTPUT          #
152
159
#-----------------------#
156
163
    if [ "$save_only" != yes ]; then
157
164
        for console in $ACTIVE_CONSOLES; do
158
165
            [ -w $console ] || continue
159
 
            if [ "$CHARMAP" = UTF-8 ] || [ -z "$ACM$CHARMAP" ]; then
 
166
            if \
 
167
                [ "$CHARMAP" = UTF-8 ] || [ -z "$CONSOLE_MAP$CHARMAP" ]
 
168
            then
160
169
                printf '\033%%G' >$console
161
170
            else
162
171
                printf '\033%%@' >$console
166
175
    
167
176
    # Load the font
168
177
    if [ -z "$FONT" ]; then
 
178
        FONT_MAP=''
169
179
        if which ckbcomp-mini >/dev/null; then
170
 
            FONT=$(echo `ls /usr/share/consolefonts/$CODESET-*.psf.gz \
171
 
                2>/dev/null`)
 
180
            FONT=$(echo `ls /usr/share/consolefonts/$CODESET-*.psf* \
 
181
                            /etc/console-setup/$CODESET-*.psf* 2>/dev/null`)
172
182
            FONT=${FONT%% *}
 
183
            if [ "$FONTFACE" ] || [ "$FONTSIZE" ]; then
 
184
                eval echo setupcon: Warning: ignoring the FONTFACE and FONTSIZE specifications! $verbose
 
185
            fi
173
186
        elif [ "$FONTFACE" ] && [ "$FONTSIZE" ]; then
174
187
            FONT="$CODESET-$FONTFACE$FONTSIZE.psf.gz"
175
188
            case "$FONTSIZE" in
202
215
                    break
203
216
                fi
204
217
                if [ "$dir" = FONT_IS_MISSING ]; then
205
 
                    echo setupcon: Warning: the font ${f##*/} does not exists! >&2
 
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
206
241
                fi
207
242
            done
208
243
        fi
222
257
            rm -f "/etc/console-setup/${fdec##*/}.gz"
223
258
        fi
224
259
    done
225
 
    
226
 
    
 
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
 
227
277
    if [ "$save_only" != yes ] && [ "$LOADFONTS" ]; then
228
278
        for console in $ACTIVE_CONSOLES; do
229
279
            [ -w $console ] || continue
231
281
                if [ "$bigfont" = yes ]; then
232
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
233
283
                fi
234
 
                eval consolechars -v --tty=$console -f $LOADFONTS $verbose
 
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
235
289
            elif which setfont >/dev/null; then
236
 
                eval setfont -v -C $console $LOADFONTS $verbose
 
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
237
295
            fi
238
296
        done
239
297
    fi
240
298
    
241
299
    # Load the ACM
242
 
    if [ ! -f "$ACM" ]; then
 
300
    if [ ! -f "$CONSOLE_MAP" ]; then
243
301
        for dir in \
244
302
            /usr/local/share/consoletrans \
245
303
            /usr/share/consoletrans \
246
304
            /etc/console-setup 
247
305
        do
248
306
            if [ -f "$dir/$CHARMAP.acm.gz" ]; then
249
 
                ACM="$dir/$CHARMAP.acm.gz"
 
307
                CONSOLE_MAP="$dir/$CHARMAP.acm.gz"
250
308
                break
251
309
            elif [ -f "$dir/$CHARMAP.acm" ]; then
252
310
                ACM="$dir/$CHARMAP.acm"
254
312
            fi
255
313
        done
256
314
    fi
257
 
    if [ -f "$ACM" ]; then
 
315
    if [ -f "$CONSOLE_MAP" ]; then
258
316
        if \
259
317
            [ "$save" = yes ] \
260
 
            && [ "${ACM%/*}" != /etc/console-setup ]
 
318
            && [ "${CONSOLE_MAP%/*}" != /etc/console-setup ]
261
319
        then
262
 
            acmdec="${ACM%.gz}"
263
 
            if [ "$acmdec" = "$ACM" ]; then
264
 
                cp "$ACM" /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/
265
323
            else
266
 
                gunzip -c "$ACM" >"/etc/console-setup/${acmdec##*/}"
 
324
                gunzip -c "$CONSOLE_MAP" >"/etc/console-setup/${console_map_dec##*/}"
267
325
            fi
268
 
            rm -f "/etc/console-setup/${acmdec##*/}.gz"
 
326
            rm -f "/etc/console-setup/${console_map_dec##*/}.gz"
269
327
        fi
270
328
    else
271
 
        ACM="$CHARMAP.acm.gz"
 
329
        CONSOLE_MAP="$CHARMAP.acm.gz"
272
330
    fi
273
 
    if [ "$save_only" != yes ] && [ "$CHARMAP" != UTF-8 ]; then
 
331
    if \
 
332
        [ "$save_only" != yes ] && [ "$CHARMAP" != UTF-8 ] && [ "$LOADFONTS" ]
 
333
    then
274
334
        for console in $ACTIVE_CONSOLES; do
275
335
            [ -w $console ] || continue
276
336
            if which consolechars >/dev/null; then
277
 
                eval consolechars -v --tty=$console --acm "$ACM" $verbose
 
337
                eval consolechars -v --tty=$console --acm "$CONSOLE_MAP" $verbose
278
338
            elif which setfont >/dev/null; then
279
 
                eval setfont -v -C $console -m "$ACM" $verbose
 
339
                eval setfont -v -C $console -m "$CONSOLE_MAP" $verbose
280
340
            fi      
281
341
        done
282
342
    fi
 
343
 
 
344
    STTY=""
 
345
    [ -z "$SCREEN_WIDTH"  ] || STTY="$STTY cols $SCREEN_WIDTH"
 
346
    [ -z "$SCREEN_HEIGHT" ] || STTY="$STTY rows $SCREEN_HEIGHT"
 
347
 
 
348
    if [ -n "$STTY" ]
 
349
    then
 
350
        for console in $ACTIVE_CONSOLES; do
 
351
            [ -r $console ] || continue
 
352
            stty $STTY < $console
 
353
        done
 
354
    fi
283
355
fi
284
356
 
285
357
#-----------------------#
286
358
#        INPUT          #
287
359
#-----------------------#
288
360
 
289
 
if [ "$font_only" != yes ] && [ "$ACTIVE_CONSOLES" ]; then
 
361
if [ "$font_only" != yes ] && [ "$XKBMODEL" != unknown ] && \
 
362
   [ "$ACTIVE_CONSOLES" ]; then
290
363
    # On Mac PPC machines, we may need to set kernel vars first.  We need
291
364
    # to mount /proc to do that, but we need it set up before sulogin may
292
365
    # be run in checkroot, which will need the keyboard to log in...
307
380
        for console in $ACTIVE_CONSOLES; do
308
381
            [ -w $console ] || continue
309
382
            if which kbd_mode >/dev/null; then
310
 
                if [ "$CHARMAP" = UTF-8 ] || [ -z "$ACM" ]; then
 
383
                if [ "$CHARMAP" = UTF-8 ] || [ -z "$CONSOLE_MAP" ]; then
311
384
                    kbd_mode -u <$console
312
385
                else
313
386
                    kbd_mode -a <$console
316
389
        done
317
390
    fi
318
391
    
319
 
    if which loadkeys >/dev/null; then
320
 
        if [ "$XKBMODEL" != SKIP ] && which ckbcomp >/dev/null; then
321
 
            if [ "$CHARMAP" != UTF-8 ]; then
322
 
                acm_option="-charmap $CHARMAP"
323
 
            else
324
 
                acm_option=''
325
 
            fi
326
 
 
327
 
            if [ "$XKBRULES" ]; then
328
 
                rules_option="-rules $XKBRULES"
329
 
            else
330
 
                rules_option=''
331
 
            fi
332
 
 
 
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/X11/xkb ] # /usr is mounted
 
409
        then
333
410
            if \
334
 
                [ "$VARIANT" = '' ] \
335
 
                && which gzip >/dev/null \
336
 
                && [ -d /usr/share/X11/xkb ] # /usr is mounted
 
411
                [ ! -f /etc/console-setup/cached.kmap.gz ] \
 
412
                || [ /etc/console-setup/cached.kmap.gz \
 
413
                     -ot /etc/default/keyboard ] \
 
414
                || [ "$save" = yes ]
337
415
            then
338
 
                if \
339
 
                    [ ! -f /etc/console-setup/cached.kmap.gz ] \
340
 
                    || [ /etc/console-setup/cached.kmap.gz \
341
 
                           -ot /etc/default/console-setup ]
342
 
                then
343
 
                    ckbcomp $acm_option $rules_option -model "$XKBMODEL" \
344
 
                        "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
345
 
                        | gzip -9 >/etc/console-setup/cached.kmap.gz
346
 
                fi
 
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
347
420
            fi
348
 
 
349
 
            if [ "$save_only" != yes ]; then
 
421
        fi
 
422
        
 
423
        if [ "$save_only" != yes ]; then
 
424
            if [ "$KMAP" -a -f "$KMAP" ]; then
 
425
                eval loadkeys "$KMAP" $verbose
 
426
            else                    
350
427
                if \
351
428
                    [ "$VARIANT" = '' ] && [ "$CONFIG" != "$USER_CONFIG" ] \
352
429
                    && [ -f /etc/console-setup/cached.kmap.gz ] \
353
430
                    && [ ! /etc/console-setup/cached.kmap.gz \
354
 
                           -ot /etc/default/console-setup ]
 
431
                           -ot /etc/default/keyboard ]
355
432
                then
356
433
                    eval loadkeys /etc/console-setup/cached.kmap.gz $verbose
357
434
                else
358
 
                    ckbcomp $acm_option $rules_option -model "$XKBMODEL" \
359
 
                        "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
360
 
                        | eval loadkeys $verbose
 
435
                    if [ -d /usr/share/X11/xkb ]; 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
361
443
                fi
362
444
            fi
363
 
            if which gzip >/dev/null && [ "$save" = yes ]; then
364
 
                ckbcomp $acm_option $rules_option -model "$XKBMODEL" \
365
 
                    "$XKBLAYOUT" "$XKBVARIANT" "$XKBOPTIONS" \
366
 
                    | gzip -9 >/etc/console-setup/cached.kmap.gz
367
 
            fi
368
 
        elif [ "$save_only" != yes ] && \
369
 
             [ -f /etc/console-setup/cached.kmap.gz ]; then
370
 
            eval loadkeys /etc/console-setup/cached.kmap.gz $verbose
371
445
        fi
372
446
    fi
373
447
fi
374