#!/bin/bash

#     Copyright © 2005 Anton Zinoviev <anton@lml.bas.bg>

#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.

#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.

#     If you have not received a copy of the GNU General Public License
#     along with this program, write to the Free Software Foundation, Inc.,
#     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

#                        ----------
#                         CONTENTS
#                        ----------
#
# 1. Initialise $fontsets, $charmaps and $kbdnames with the supported
#    fontsets, charmaps, keyboard models, layouts and variants.  These
#    lists can not be computed because the config script is invoked
#    during the preconfiguration phase and the available fonts, ACM,
#    etc. are not yet unpacked.
#
# 2. Function ask_debconf.  Ask user to choose amongst the options
#    listed in $fontsets, $charmaps and $kbdnames.
#
# 3. Function guess_arch - detect the architecture and subarchitecture
#
# 4. Function available_fontsets - lists all fontfaces that can be
#    used with $codeset.
#
# 5. Function available_fontsizes - lists all font sizes that can be
#    used with the $codeset-$fontface combination.
#
# 6. Set $locale.  Set $default_codeset and $codeset_priority acording
#    to $locale.
#
# 7. Set $default_layout and acording to $locale. default_variant=''
#
# 8. Set $default_charmap and $charmap_priority acording to $locale.
#
# 9. Set $arch.  Set $default_model and $model_priority acording to
#    $arch.
#
# 10. Read /etc/default/console-setup and store values into debconf
#     db.  Four very long case instructions in order to translate
#     options like "grp:caps_toggle" to human-readable strings like
#     "Caps Lock".
#
# 11. Ask the Debconf questions starting from STATE=1 and ending after
#     STATE=9.  Again four long case instructions in STATE=4 to
#     translate "Caps Lock" to "grp:caps_toggle".

# This script would be simpler and faster if written in Perl but with
# Shell it can be used in the Installer

set -e

. /usr/share/debconf/confmodule

CONFIGFILE=/etc/default/console-setup

default_ttys=''
default_charmap=''
default_codeset=''
default_fontface=''
default_fontsize=''
default_toggle=''
default_switch=''
default_altgr=''
default_compose=''
default_model=''
default_layout=''
default_variant=''
ACTIVE_CONSOLES=''
CHARMAP=''
CODESET=''
FONTFACE=''
FONTSIZE=''
XKBMODEL=''
XKBLAYOUT=''
XKBVARIANT=''
XKBOPTIONS=''


package=console-setup
# package=console-setup

fontsets='Arabic-Fixed15
Arabic-Fixed16
Arabic-VGA14
Arabic-VGA16
Arabic-VGA8
Armenian-Fixed13
Armenian-Fixed14
Armenian-Fixed15
Armenian-Fixed16
Armenian-Fixed18
CyrAsia-Fixed13
CyrAsia-Fixed14
CyrAsia-Fixed15
CyrAsia-Fixed16
CyrAsia-Fixed18
CyrAsia-Terminus12x6
CyrAsia-Terminus14
CyrAsia-Terminus16
CyrAsia-Terminus20x10
CyrAsia-Terminus24x12
CyrAsia-Terminus28x14
CyrAsia-Terminus32x16
CyrAsia-TerminusBold14
CyrAsia-TerminusBold16
CyrAsia-TerminusBold20x10
CyrAsia-TerminusBold24x12
CyrAsia-TerminusBold28x14
CyrAsia-TerminusBold32x16
CyrAsia-TerminusBoldVGA14
CyrAsia-TerminusBoldVGA16
CyrKoi-Fixed13
CyrKoi-Fixed14
CyrKoi-Fixed15
CyrKoi-Fixed16
CyrKoi-Fixed18
CyrKoi-Terminus12x6
CyrKoi-Terminus14
CyrKoi-Terminus16
CyrKoi-Terminus20x10
CyrKoi-Terminus24x12
CyrKoi-Terminus28x14
CyrKoi-Terminus32x16
CyrKoi-TerminusBold14
CyrKoi-TerminusBold16
CyrKoi-TerminusBold20x10
CyrKoi-TerminusBold24x12
CyrKoi-TerminusBold28x14
CyrKoi-TerminusBold32x16
CyrKoi-TerminusBoldVGA14
CyrKoi-TerminusBoldVGA16
CyrKoi-VGA14
CyrKoi-VGA16
CyrKoi-VGA8
CyrSlav-Fixed13
CyrSlav-Fixed14
CyrSlav-Fixed15
CyrSlav-Fixed16
CyrSlav-Fixed18
CyrSlav-Terminus12x6
CyrSlav-Terminus14
CyrSlav-Terminus16
CyrSlav-Terminus20x10
CyrSlav-Terminus24x12
CyrSlav-Terminus28x14
CyrSlav-Terminus32x16
CyrSlav-TerminusBold14
CyrSlav-TerminusBold16
CyrSlav-TerminusBold20x10
CyrSlav-TerminusBold24x12
CyrSlav-TerminusBold28x14
CyrSlav-TerminusBold32x16
CyrSlav-TerminusBoldVGA14
CyrSlav-TerminusBoldVGA16
CyrSlav-VGA14
CyrSlav-VGA16
CyrSlav-VGA8
Ethiopian-Fixed15
Ethiopian-Fixed18
Ethiopian-Goha12
Ethiopian-Goha14
Ethiopian-Goha16
Ethiopian-GohaClassic12
Ethiopian-GohaClassic14
Ethiopian-GohaClassic16
Georgian-Fixed13
Georgian-Fixed14
Georgian-Fixed15
Georgian-Fixed16
Georgian-Fixed18
Greek-Fixed13
Greek-Fixed14
Greek-Fixed15
Greek-Fixed16
Greek-Fixed18
Greek-Terminus12x6
Greek-Terminus14
Greek-Terminus16
Greek-Terminus20x10
Greek-Terminus24x12
Greek-Terminus28x14
Greek-Terminus32x16
Greek-TerminusBold14
Greek-TerminusBold16
Greek-TerminusBold20x10
Greek-TerminusBold24x12
Greek-TerminusBold28x14
Greek-TerminusBold32x16
Greek-TerminusBoldVGA14
Greek-TerminusBoldVGA16
Greek-VGA14
Greek-VGA16
Greek-VGA8
Hebrew-Fixed13
Hebrew-Fixed14
Hebrew-Fixed15
Hebrew-Fixed16
Hebrew-Fixed18
Hebrew-VGA14
Hebrew-VGA16
Hebrew-VGA8
Lao-Fixed14
Lao-Fixed15
Lao-Fixed16
Lat15-Fixed13
Lat15-Fixed14
Lat15-Fixed15
Lat15-Fixed16
Lat15-Fixed18
Lat15-Terminus12x6
Lat15-Terminus14
Lat15-Terminus16
Lat15-Terminus20x10
Lat15-Terminus24x12
Lat15-Terminus28x14
Lat15-Terminus32x16
Lat15-TerminusBold14
Lat15-TerminusBold16
Lat15-TerminusBold20x10
Lat15-TerminusBold24x12
Lat15-TerminusBold28x14
Lat15-TerminusBold32x16
Lat15-TerminusBoldVGA14
Lat15-TerminusBoldVGA16
Lat15-VGA14
Lat15-VGA16
Lat15-VGA8
Lat2-Fixed13
Lat2-Fixed14
Lat2-Fixed15
Lat2-Fixed16
Lat2-Fixed18
Lat2-Terminus12x6
Lat2-Terminus14
Lat2-Terminus16
Lat2-Terminus20x10
Lat2-Terminus24x12
Lat2-Terminus28x14
Lat2-Terminus32x16
Lat2-TerminusBold14
Lat2-TerminusBold16
Lat2-TerminusBold20x10
Lat2-TerminusBold24x12
Lat2-TerminusBold28x14
Lat2-TerminusBold32x16
Lat2-TerminusBoldVGA14
Lat2-TerminusBoldVGA16
Lat2-VGA14
Lat2-VGA16
Lat2-VGA8
Lat38-Fixed13
Lat38-Fixed14
Lat38-Fixed15
Lat38-Fixed16
Lat38-Fixed18
Lat38-VGA14
Lat38-VGA16
Lat38-VGA8
Lat7-Fixed13
Lat7-Fixed14
Lat7-Fixed15
Lat7-Fixed16
Lat7-Fixed18
Lat7-Terminus12x6
Lat7-Terminus14
Lat7-Terminus16
Lat7-Terminus20x10
Lat7-Terminus24x12
Lat7-Terminus28x14
Lat7-Terminus32x16
Lat7-TerminusBold14
Lat7-TerminusBold16
Lat7-TerminusBold20x10
Lat7-TerminusBold24x12
Lat7-TerminusBold28x14
Lat7-TerminusBold32x16
Lat7-TerminusBoldVGA14
Lat7-TerminusBoldVGA16
Lat7-VGA14
Lat7-VGA16
Lat7-VGA8
Thai-Fixed13
Thai-Fixed14
Thai-Fixed15
Thai-Fixed16
Thai-Fixed18
Uni1-Fixed15
Uni1-Fixed16
Uni1-VGA14
Uni1-VGA16
Uni1-VGA8
Uni2-Fixed13
Uni2-Fixed14
Uni2-Fixed15
Uni2-Fixed16
Uni2-Fixed18
Uni2-Terminus12x6
Uni2-Terminus14
Uni2-Terminus16
Uni2-Terminus20x10
Uni2-Terminus24x12
Uni2-Terminus28x14
Uni2-Terminus32x16
Uni2-TerminusBold14
Uni2-TerminusBold16
Uni2-TerminusBold20x10
Uni2-TerminusBold24x12
Uni2-TerminusBold28x14
Uni2-TerminusBold32x16
Uni2-TerminusBoldVGA14
Uni2-TerminusBoldVGA16
Uni2-VGA14
Uni2-VGA16
Uni2-VGA8
Uni3-Fixed13
Uni3-Fixed14
Uni3-Fixed15
Uni3-Fixed16
Uni3-Fixed18
Uni3-Terminus12x6
Uni3-Terminus14
Uni3-Terminus16
Uni3-Terminus20x10
Uni3-Terminus24x12
Uni3-Terminus28x14
Uni3-Terminus32x16
Uni3-TerminusBold14
Uni3-TerminusBold16
Uni3-TerminusBold20x10
Uni3-TerminusBold24x12
Uni3-TerminusBold28x14
Uni3-TerminusBold32x16
Uni3-TerminusBoldVGA14
Uni3-TerminusBoldVGA16
Vietnamese-Fixed13
Vietnamese-Fixed14
Vietnamese-Fixed15
Vietnamese-Fixed16
Vietnamese-Fixed18
'
# fontsets='Arabic-Fixed15
# Arabic-Fixed16
# Arabic-vga14
# ... 
# Vietnamese-Fixed18
# '

charmaps='ARMSCII-8
CP1251
CP1255
CP1256
GEORGIAN-ACADEMY
GEORGIAN-PS
IBM1133
ISIRI-3342
ISO-8859-1
ISO-8859-10
ISO-8859-11
ISO-8859-13
ISO-8859-14
ISO-8859-15
ISO-8859-16
ISO-8859-2
ISO-8859-3
ISO-8859-4
ISO-8859-5
ISO-8859-6
ISO-8859-7
ISO-8859-8
ISO-8859-9
KOI8-R
KOI8-U
TIS-620
VISCII
UTF-8'

# charmaps='ARMSCII-8
# CP1251
# CP1255
# ...
# UTF-8'

all_kbdnames () {
 cat <<'EOF' 
C*model*logidinovo*Logitech diNovo Keyboard
C*model*amiga*Amiga
C*model*acer_c300*Acer C300
C*model*yahoo*Yahoo! Internet Keyboard
C*model*macintosh*Macintosh
C*model*dell101*Dell 101-key PC
C*model*mx2500*Memorex MX2500 EZ-Access Keyboard
C*model*geniuscomfy2*Genius Comfy KB-21e-Scroll
C*model*pc98*PC-98xx Series
C*model*dell*Dell
C*model*logiinkseusb*Logitech iTouch Internet Navigator Keyboard SE (USB)
C*model*ipaq*Compaq iPaq Keyboard
C*model*compalfl90*FL90
C*model*sk1300*SK-1300
C*model*thinkpad60*IBM ThinkPad R60/T60/R61/T61
C*model*vsonku306*ViewSonic KU-306 Internet Keyboard
C*model*tm2030USB*TypeMatrix EZ-Reach 2030 USB
C*model*mx2750*Memorex MX2750
C*model*logitech_g15*Logitech G15 extra keys via G15daemon
C*model*scorpius*Advance Scorpius KI
C*model*compaqik18*Compaq Internet Keyboard (18 keys)
C*model*applealu_ansi*Apple Aluminium Keyboard (ANSI)
C*model*brother*Brother Internet Keyboard
C*model*acpi*ACPI Standard
C*model*pc105*Generic 105-key (Intl) PC
C*model*applealu_iso*Apple Aluminium Keyboard (ISO)
C*model*btc9019u*BTC 9019U
C*model*gyration*Gyration
C*model*tm2030USB-102*TypeMatrix EZ-Reach 2030 USB (102/105:EU mode)
C*model*acer_ferrari4k*Acer Ferrari 4000
C*model*qtronix*QTronix Scorpius 98N+
C*model*fscaa1667g*Fujitsu-Siemens Computers AMILO laptop
C*model*microsoftccurve2k*Microsoft Comfort Curve Keyboard 2000
C*model*hpxt1000*Hewlett-Packard Omnibook XT1000
C*model*macintosh_hhk*Happy Hacking Keyboard for Mac
C*model*acer_laptop*Acer Laptop
C*model*microsoftelite*Microsoft Natural Keyboard Elite
C*model*btc9116u*BTC 9116U Mini Wireless Internet and Gaming
C*model*hhk*Happy Hacking Keyboard
C*model*diamond*Diamond 9801 / 9802 series
C*model*hpxe3gc*Hewlett-Packard Omnibook XE3 GC
C*model*samsung4510*Samsung SDM 4510P
C*model*pc104*Generic 104-key PC
C*model*sven303*SVEN Slim 303
C*model*emachines*Laptop/notebook eMachines m68xx
C*model*thinkpadz60*IBM ThinkPad Z60m/Z60t/Z61m/Z61t
C*model*oretec*Ortek MCK-800 MM/Internet keyboard
C*model*btc6301urf*BTC 6301URF
C*model*trustda*Trust Direct Access Keyboard
C*model*genius*Genius Comfy KB-16M / Genius MM Keyboard KWD-910
C*model*btc5090*BTC 5090
C*model*dellm65*Dell Precision M65
C*model*dexxa*Dexxa Wireless Desktop Keyboard
C*model*logiex110*Logitech Cordless Desktop EX110
C*model*geniuskb19e*Genius KB-19e NB
C*model*btc5126t*BTC 5126T
C*model*classmate*Classmate PC
C*model*rapidaccess*IBM Rapid Access
C*model*trust_slimline*Trust Slimline
C*model*chicony9885*Chicony KB-9885
C*model*logii350*Logitech Internet 350 Keyboard
C*model*thinkpad*IBM ThinkPad 560Z/600/600E/A22E
C*model*olpc*OLPC
C*model*hpnx9020*Hewlett-Packard nx9020
C*model*dellsk8125*Dell SK-8125
C*model*trust*Trust Wireless Keyboard Classic
C*model*asus_laptop*Asus Laptop
C*model*mx1998*Memorex MX1998
C*model*sk7100*SK-7100
C*model*btc5113rf*BTC 5113RF Multimedia
C*model*microsoftprousb*Microsoft Natural Keyboard Pro USB / Microsoft Internet Keyboard Pro
C*model*hpdv5*Hewlett-Packard Pavilion dv5
C*model*btc9000*BTC 9000
C*model*sp_inet*Super Power Multimedia Keyboard
C*model*macbook79*MacBook/MacBook Pro (Intl)
C*model*hpi6*Hewlett-Packard Internet Keyboard
C*model*macintosh_old*Macintosh Old
C*model*hp6000*Hewlett-Packard Omnibook 6000/6100
C*model*logicdpa2*Logitech Cordless Desktop Pro (alternate option 2)
C*model*btc9001ah*BTC 9001AH
C*model*logicink*Logitech Internet Navigator Keyboard
C*model*omnikey101*Northgate OmniKey 101
C*model*cherrycyboard*Cherry CyBo@rd USB-Hub
C*model*armada*Laptop/notebook Compaq (eg. Armada) Laptop Keyboard
C*model*macbook78*MacBook/MacBook Pro
C*model*ibm_spacesaver*IBM Space Saver
C*model*microsoftmult*Microsoft Wireless Multimedia Keyboard 1.0A
C*model*pc101*Generic 101-key PC
C*model*logicd_opt*Logitech Cordless Desktop Optical
C*model*logiultraxc*Logitech Ultra-X Cordless Media Desktop Keyboard
C*model*microsoftprose*Microsoft Internet Keyboard Pro, Swedish
C*model*itouch*Logitech iTouch
C*model*hpzt11xx*Hewlett-Packard Pavilion ZT11xx
C*model*geniuscomfy*Genius Comfy KB-12e
C*model*logiultrax*Logitech Ultra-X Keyboard
C*model*cherryblueb*Cherry CyMotion Master XPress
C*model*chicony0420*Chicony KU-0420
C*model*hp5xx*Hewlett-Packard Omnibook 5xx
C*model*tm2020*TypeMatrix EZ-Reach 2020
C*model*apple*Apple
C*model*hpmini110*Hewlett-Packard Mini 110 Notebook
C*model*microsoftinet*Microsoft Internet Keyboard
C*model*samsung4500*Samsung SDM 4500P
C*model*microsoft7000*Microsoft Natural Wireless Ergonomic Keyboard 7000
C*model*logiik*Logitech Internet Keyboard
C*model*cherryblue*Cherry Blue Line CyBo@rd
C*model*chicony*Chicony Internet Keyboard
C*model*tm2030USB-106*TypeMatrix EZ-Reach 2030 USB (106:JP mode)
C*model*a4_rfkb23*A4Tech Wireless Desktop RFKB-23
C*model*compaqik13*Compaq Internet Keyboard (13 keys)
C*model*ataritt*Atari TT
C*model*silvercrest*SILVERCREST Multimedia Wireless Keyboard
C*model*targa_v811*Targa Visionary 811
C*model*propeller*Propeller Voyager (KTEZ-1000)
C*model*dellsk8135*Dell SK-8135
C*model*benqx*BenQ X-Touch
C*model*hp500fa*Hewlett-Packard Omnibook 500 FA
C*model*symplon*Symplon PaceBook (tablet PC)
C*model*microsoft*Microsoft Natural
C*model*precision_m*Dell Laptop/notebook Precision M series
C*model*logicd*Logitech Cordless Desktop
C*model*benqx730*BenQ X-Touch 730
C*model*logiinkse*Logitech iTouch Internet Navigator Keyboard SE
C*model*latitude*Dell Latitude series laptop
C*model*ennyah_dkb1008*Ennyah DKB-1008
C*model*pc102*Generic 102-key (Intl) PC
C*model*logiitc*Logitech iTouch Cordless Keyboard (model Y-RB6)
C*model*sk6200*SK-6200
C*model*cymotionlinux*Cherry CyMotion Master Linux
C*model*logidinovoedge*Logitech diNovo Edge Keyboard
C*model*everex*Everex STEPnote
C*model*a4techKB21*A4Tech KB-21
C*model*compaqik7*Compaq Internet Keyboard (7 keys)
C*model*apple_laptop*Apple Laptop
C*model*winbook*Winbook Model XP5
C*model*logitech_base*Logitech Generic Keyboard
C*model*inspiron*Dell Laptop/notebook Inspiron 6xxx/8xxx
C*model*logiclx300*Logitech Cordless Desktop LX-300
C*model*logicdn*Logitech Cordless Desktop Navigator
C*model*rapidaccess2*IBM Rapid Access II
C*model*sun4*Sun Type 4
C*model*presario*Laptop/notebook Compaq (eg. Presario) Internet Keyboard
C*model*cherrycmexpert*Cherry CyMotion Expert
C*model*microsoftoffice*Microsoft Office Keyboard
C*model*evdev*Evdev-managed keyboard
C*model*cherrybunlim*Cherry B.UNLIMITED
C*model*honeywell_euroboard*Honeywell Euroboard
C*model*dtk2000*DTK2000
C*model*logicfn*Logitech Cordless Freedom/Desktop Navigator
C*model*sun6*Sun Type 5/6
C*model*logimel*Logitech Media Elite Keyboard
C*model*toshiba_s3000*Toshiba Satellite S3000
C*model*airkey*Acer AirKey V
C*model*sk2500*SK-2500
C*model*azonaRF2300*Azona RF2300 wireless Internet Keyboard
C*model*tm2030PS2*TypeMatrix EZ-Reach 2030 PS2
C*model*hpxe3gf*Hewlett-Packard Omnibook XE3 GF
C*model*hp250x*Hewlett-Packard SK-250x Multimedia Keyboard
C*model*unitekkb1925*Unitek KB-1925
C*model*microsoftprooem*Microsoft Natural Keyboard Pro OEM
C*model*benqx800*BenQ X-Touch 800
C*model*sun5*Sun Type 5
C*model*logiaccess*Logitech Access Keyboard
C*model*btc9000a*BTC 9000A
C*model*microsoftpro*Microsoft Natural Keyboard Pro / Microsoft Internet Keyboard Pro
C*model*SKIP*Do not configure keyboard; keep kernel keymap
C*model*applealu_jis*Apple Aluminium Keyboard (JIS)
C*model*cherrybluea*Cherry Blue Line CyBo@rd (alternate option)
C*model*geniuskkb2050hs*Genius KKB-2050HS
C*model*intelligent_keyboard_k04*Intelligent Keyboard K04
C*model*logicd_it*Logitech Cordless Desktop iTouch
C*model*chicony0108*Chicony KU-0108
C*model*dellusbmm*Dell USB Multimedia Keyboard
C*model*creativedw7000*Creative Desktop Wireless 7000
C*model*a4techKBS8*A4Tech KBS-8
C*model*sven*SVEN Ergonomic 2500
C*model*compaqeak8*Compaq Easy Access Keyboard
C*model*flexpro*Keytronic FlexPro
C*model*logicda*Logitech Cordless Desktop (alternate option)
C*layout*sy*Syria
C*variant*sy**Syria
C*variant*sy*syc_phonetic*Syria - Syriac phonetic
C*variant*sy*syc*Syria - Syriac
C*variant*sy*ku*Syria - Kurdish, Latin Q
C*variant*sy*ku_alt*Syria - Kurdish, Latin Alt-Q
C*variant*sy*ku_f*Syria - Kurdish, (F)
C*layout*se*Sweden
C*variant*se**Sweden
C*variant*se*svdvorak*Sweden - Svdvorak
C*variant*se*dvorak*Sweden - Dvorak
C*variant*se*nodeadkeys*Sweden - Eliminate dead keys
C*variant*se*rus*Sweden - Russian phonetic
C*variant*se*smi*Sweden - Northern Saami
C*variant*se*rus_nodeadkeys*Sweden - Russian phonetic, eliminate dead keys
C*variant*se*mac*Sweden - Macintosh
C*layout*mn*Mongolia
C*variant*mn**Mongolia
C*layout*hu*Hungary
C*variant*hu**Hungary
C*variant*hu*101_qwerty_comma_dead*Hungary - 101/qwerty/comma/Dead keys
C*variant*hu*102_qwerty_dot_dead*Hungary - 102/qwerty/dot/Dead keys
C*variant*hu*101_qwertz_dot_dead*Hungary - 101/qwertz/dot/Dead keys
C*variant*hu*101_qwertz_comma_dead*Hungary - 101/qwertz/comma/Dead keys
C*variant*hu*101_qwertz_dot_nodead*Hungary - 101/qwertz/dot/Eliminate dead keys
C*variant*hu*101_qwerty_comma_nodead*Hungary - 101/qwerty/comma/Eliminate dead keys
C*variant*hu*101_qwerty_dot_dead*Hungary - 101/qwerty/dot/Dead keys
C*variant*hu*101_qwertz_comma_nodead*Hungary - 101/qwertz/comma/Eliminate dead keys
C*variant*hu*nodeadkeys*Hungary - Eliminate dead keys
C*variant*hu*102_qwertz_dot_nodead*Hungary - 102/qwertz/dot/Eliminate dead keys
C*variant*hu*102_qwerty_dot_nodead*Hungary - 102/qwerty/dot/Eliminate dead keys
C*variant*hu*102_qwerty_comma_nodead*Hungary - 102/qwerty/comma/Eliminate dead keys
C*variant*hu*102_qwerty_comma_dead*Hungary - 102/qwerty/comma/Dead keys
C*variant*hu*standard*Hungary - Standard
C*variant*hu*102_qwertz_comma_nodead*Hungary - 102/qwertz/comma/Eliminate dead keys
C*variant*hu*101_qwerty_dot_nodead*Hungary - 101/qwerty/dot/Eliminate dead keys
C*variant*hu*102_qwertz_dot_dead*Hungary - 102/qwertz/dot/Dead keys
C*variant*hu*qwerty*Hungary - qwerty
C*variant*hu*102_qwertz_comma_dead*Hungary - 102/qwertz/comma/Dead keys
C*layout*np*Nepal
C*variant*np**Nepal
C*layout*pk*Pakistan
C*variant*pk**Pakistan
C*variant*pk*ara*Pakistan - Arabic
C*variant*pk*urd-nla*Pakistan - NLA
C*variant*pk*urd-crulp*Pakistan - CRULP
C*layout*gn*Guinea
C*variant*gn**Guinea
C*layout*lk*Sri Lanka
C*variant*lk**Sri Lanka
C*variant*lk*tam_TAB*Sri Lanka - Tamil TAB Typewriter
C*variant*lk*tam_unicode*Sri Lanka - Tamil Unicode
C*layout*kr*Korea, Republic of
C*variant*kr**Korea, Republic of
C*variant*kr*kr104*Korea, Republic of - 101/104 key Compatible
C*layout*cn*China
C*variant*cn**China
C*variant*cn*tib_asciinum*China - Tibetan (with ASCII numerals)
C*variant*cn*tib*China - Tibetan
C*layout*ee*Estonia
C*variant*ee**Estonia
C*variant*ee*dvorak*Estonia - Dvorak
C*variant*ee*nodeadkeys*Estonia - Eliminate dead keys
C*variant*ee*us*Estonia - US keyboard with Estonian letters
C*layout*et*Ethiopia
C*variant*et**Ethiopia
C*layout*za*South Africa
C*variant*za**South Africa
C*layout*mao*Maori
C*variant*mao**Maori
C*layout*am*Armenia
C*variant*am**Armenia
C*variant*am*eastern-alt*Armenia - Alternative Eastern
C*variant*am*western*Armenia - Western
C*variant*am*phonetic-alt*Armenia - Alternative Phonetic
C*variant*am*eastern*Armenia - Eastern
C*variant*am*phonetic*Armenia - Phonetic
C*layout*tm*Turkmenistan
C*variant*tm**Turkmenistan
C*variant*tm*alt*Turkmenistan - Alt-Q
C*layout*latam*Latin American
C*variant*latam**Latin American
C*variant*latam*deadtilde*Latin American - Include dead tilde
C*variant*latam*sundeadkeys*Latin American - Sun dead keys
C*variant*latam*nodeadkeys*Latin American - Eliminate dead keys
C*layout*nec_vndr/jp*Japan (PC-98xx Series)
C*variant*nec_vndr/jp**Japan (PC-98xx Series)
C*layout*ie*Ireland
C*variant*ie**Ireland
C*variant*ie*ogam_is434*Ireland - Ogham IS434
C*variant*ie*CloGaelach*Ireland - CloGaelach
C*variant*ie*ogam*Ireland - Ogham
C*variant*ie*UnicodeExpert*Ireland - UnicodeExpert
C*layout*pt*Portugal
C*variant*pt**Portugal
C*variant*pt*sundeadkeys*Portugal - Sun dead keys
C*variant*pt*nativo-epo*Portugal - Nativo for Esperanto
C*variant*pt*mac_sundeadkeys*Portugal - Macintosh, Sun dead keys
C*variant*pt*mac_nodeadkeys*Portugal - Macintosh, eliminate dead keys
C*variant*pt*nodeadkeys*Portugal - Eliminate dead keys
C*variant*pt*nativo-us*Portugal - Nativo for USA keyboards
C*variant*pt*nativo*Portugal - Nativo
C*variant*pt*mac*Portugal - Macintosh
C*layout*ng*Nigeria
C*variant*ng**Nigeria
C*variant*ng*igbo*Nigeria - Igbo
C*variant*ng*yoruba*Nigeria - Yoruba
C*variant*ng*hausa*Nigeria - Hausa
C*layout*lv*Latvia
C*variant*lv**Latvia
C*variant*lv*tilde*Latvia - Tilde (~) variant
C*variant*lv*fkey*Latvia - F-letter (F) variant
C*variant*lv*apostrophe*Latvia - Apostrophe () variant
C*layout*tr*Turkey
C*variant*tr**Turkey
C*variant*tr*sundeadkeys*Turkey - Sun dead keys
C*variant*tr*ku*Turkey - Kurdish, Latin Q
C*variant*tr*alt*Turkey - Alt-Q
C*variant*tr*ku_alt*Turkey - Kurdish, Latin Alt-Q
C*variant*tr*f*Turkey - (F)
C*variant*tr*ku_f*Turkey - Kurdish, (F)
C*variant*tr*crh_alt*Turkey - Crimean Tatar (Turkish Alt-Q)
C*variant*tr*intl*Turkey - International (with dead keys)
C*variant*tr*crh*Turkey - Crimean Tatar (Turkish Q)
C*variant*tr*crh_f*Turkey - Crimean Tatar (Turkish F)
C*layout*is*Iceland
C*variant*is**Iceland
C*variant*is*dvorak*Iceland - Dvorak
C*variant*is*Sundeadkeys*Iceland - Sun dead keys
C*variant*is*nodeadkeys*Iceland - Eliminate dead keys
C*variant*is*mac*Iceland - Macintosh
C*layout*rs*Serbia
C*variant*rs**Serbia
C*variant*rs*latinyz*Serbia - Latin qwerty
C*variant*rs*latin*Serbia - Latin
C*variant*rs*alternatequotes*Serbia - With guillemets
C*variant*rs*yz*Serbia - Z and ZHE swapped
C*variant*rs*latinunicodeyz*Serbia - Latin Unicode qwerty
C*variant*rs*latinalternatequotes*Serbia - Latin with guillemets
C*variant*rs*latinunicode*Serbia - Latin Unicode
C*layout*gh*Ghana
C*variant*gh**Ghana
C*variant*gh*hausa*Ghana - Hausa
C*variant*gh*ewe*Ghana - Ewe
C*variant*gh*generic*Ghana - Multilingual
C*variant*gh*ga*Ghana - Ga
C*variant*gh*fula*Ghana - Fula
C*variant*gh*akan*Ghana - Akan
C*layout*ma*Morocco
C*variant*ma**Morocco
C*variant*ma*tifinagh-phonetic*Morocco - Tifinagh Phonetic
C*variant*ma*tifinagh-extended-phonetic*Morocco - Tifinagh Extended Phonetic
C*variant*ma*tifinagh-extended*Morocco - Tifinagh Extended
C*variant*ma*tifinagh*Morocco - Tifinagh
C*variant*ma*french*Morocco - French
C*variant*ma*tifinagh-alt-phonetic*Morocco - Tifinagh Alternative Phonetic
C*variant*ma*tifinagh-alt*Morocco - Tifinagh Alternative
C*layout*fo*Faroe Islands
C*variant*fo**Faroe Islands
C*variant*fo*nodeadkeys*Faroe Islands - Eliminate dead keys
C*layout*mv*Maldives
C*variant*mv**Maldives
C*layout*bd*Bangladesh
C*variant*bd**Bangladesh
C*variant*bd*probhat*Bangladesh - Probhat
C*layout*nl*Netherlands
C*variant*nl**Netherlands
C*variant*nl*sundeadkeys*Netherlands - Sun dead keys
C*variant*nl*std*Netherlands - Standard
C*variant*nl*mac*Netherlands - Macintosh
C*layout*br*Brazil
C*variant*br**Brazil
C*variant*br*dvorak*Brazil - Dvorak
C*variant*br*nativo-us*Brazil - Nativo for USA keyboards
C*variant*br*nativo-epo*Brazil - Nativo for Esperanto
C*variant*br*nodeadkeys*Brazil - Eliminate dead keys
C*variant*br*nativo*Brazil - Nativo
C*layout*jp*Japan
C*variant*jp**Japan
C*variant*jp*kana*Japan - Kana
C*variant*jp*OADG109A*Japan - OADG 109A
C*variant*jp*mac*Japan - Macintosh
C*layout*sk*Slovakia
C*variant*sk**Slovakia
C*variant*sk*qwerty*Slovakia - qwerty
C*variant*sk*bksl*Slovakia - Extended Backslash
C*variant*sk*qwerty_bksl*Slovakia - qwerty, extended Backslash
C*layout*cd*Congo, Democratic Republic of the
C*variant*cd**Congo, Democratic Republic of the
C*layout*tj*Tajikistan
C*variant*tj**Tajikistan
C*variant*tj*legacy*Tajikistan - Legacy
C*layout*ml*Mali
C*variant*ml**Mali
C*variant*ml*fr-oss*Mali - Français (France Alternative)
C*variant*ml*us-intl*Mali - English (USA International)
C*variant*ml*us-mac*Mali - English (USA Macintosh)
C*layout*hr*Croatia
C*variant*hr**Croatia
C*variant*hr*unicodeus*Croatia - US keyboard with Croatian digraphs
C*variant*hr*unicode*Croatia - Use Croatian digraphs
C*variant*hr*alternatequotes*Croatia - Use guillemets for quotes
C*variant*hr*us*Croatia - US keyboard with Croatian letters
C*layout*pl*Poland
C*variant*pl**Poland
C*variant*pl*ru_phonetic_dvorak*Poland - Russian phonetic Dvorak
C*variant*pl*csb*Poland - Kashubian
C*variant*pl*dvorak*Poland - Dvorak
C*variant*pl*dvorak_altquotes*Poland - Dvorak, Polish quotes on key 1
C*variant*pl*dvp*Poland - Programmer Dvorak
C*variant*pl*qwertz*Poland - qwertz
C*variant*pl*dvorak_quotes*Poland - Dvorak, Polish quotes on quotemark key
C*layout*si*Slovenia
C*variant*si**Slovenia
C*variant*si*us*Slovenia - US keyboard with Slovenian letters
C*variant*si*alternatequotes*Slovenia - Use guillemets for quotes
C*layout*il*Israel
C*variant*il**Israel
C*variant*il*biblical*Israel - Biblical Hebrew (Tiro)
C*variant*il*lyx*Israel - lyx
C*variant*il*phonetic*Israel - Phonetic
C*layout*in*India
C*variant*in**India
C*variant*in*urd-phonetic*India - Urdu, Phonetic
C*variant*in*guru*India - Gurmukhi
C*variant*in*guj*India - Gujarati
C*variant*in*bolnagri*India - Hindi Bolnagri
C*variant*in*tam_keyboard_with_numerals*India - Tamil Keyboard with Numerals
C*variant*in*urd-phonetic3*India - Urdu, Alternative phonetic
C*variant*in*jhelum*India - Gurmukhi Jhelum
C*variant*in*kan*India - Kannada
C*variant*in*mal*India - Malayalam
C*variant*in*mal_lalitha*India - Malayalam Lalitha
C*variant*in*tam_unicode*India - Tamil Unicode
C*variant*in*tam*India - Tamil
C*variant*in*ben*India - Bengali
C*variant*in*tam_TSCII*India - Tamil TSCII Typewriter
C*variant*in*tel*India - Telugu
C*variant*in*hin-wx*India - Hindi Wx
C*variant*in*urd-winkeys*India - Urdu, Winkeys
C*variant*in*ori*India - Oriya
C*variant*in*tam_TAB*India - Tamil TAB Typewriter
C*variant*in*ben_probhat*India - Bengali Probhat
C*layout*mt*Malta
C*variant*mt**Malta
C*variant*mt*us*Malta - Maltese keyboard with US layout
C*layout*es*Spain
C*variant*es**Spain
C*variant*es*deadtilde*Spain - Include dead tilde
C*variant*es*dvorak*Spain - Dvorak
C*variant*es*sundeadkeys*Spain - Sun dead keys
C*variant*es*nodeadkeys*Spain - Eliminate dead keys
C*variant*es*cat*Spain - Catalan variant with middle-dot L
C*variant*es*mac*Spain - Macintosh
C*variant*es*ast*Spain - Asturian variant with bottom-dot H and bottom-dot L
C*layout*tw*Taiwan
C*variant*tw**Taiwan
C*variant*tw*saisiyat*Taiwan - Saisiyat
C*variant*tw*indigenous*Taiwan - Indigenous
C*layout*mk*Macedonia
C*variant*mk**Macedonia
C*variant*mk*nodeadkeys*Macedonia - Eliminate dead keys
C*layout*gb*United Kingdom
C*variant*gb**United Kingdom
C*variant*gb*dvorakukp*United Kingdom - Dvorak (UK Punctuation)
C*variant*gb*dvorak*United Kingdom - Dvorak
C*variant*gb*intl*United Kingdom - International (with dead keys)
C*variant*gb*colemak*United Kingdom - Colemak
C*variant*gb*mac*United Kingdom - Macintosh
C*variant*gb*extd*United Kingdom - Extended - Winkeys
C*layout*ch*Switzerland
C*variant*ch**Switzerland
C*variant*ch*fr_sundeadkeys*Switzerland - French, Sun dead keys
C*variant*ch*fr_mac*Switzerland - French (Macintosh)
C*variant*ch*fr*Switzerland - French
C*variant*ch*fr_nodeadkeys*Switzerland - French, eliminate dead keys
C*variant*ch*de_sundeadkeys*Switzerland - German, Sun dead keys
C*variant*ch*de_nodeadkeys*Switzerland - German, eliminate dead keys
C*variant*ch*de_mac*Switzerland - German (Macintosh)
C*variant*ch*legacy*Switzerland - Legacy
C*layout*az*Azerbaijan
C*variant*az**Azerbaijan
C*variant*az*cyrillic*Azerbaijan - Cyrillic
C*layout*bg*Bulgaria
C*variant*bg**Bulgaria
C*variant*bg*bas_phonetic*Bulgaria - New phonetic
C*variant*bg*phonetic*Bulgaria - Traditional phonetic
C*layout*la*Laos
C*variant*la**Laos
C*variant*la*stea*Laos - Laos - STEA (proposed standard layout)
C*variant*la*basic*Laos - Laos
C*layout*lt*Lithuania
C*variant*lt**Lithuania
C*variant*lt*us*Lithuania - US keyboard with Lithuanian letters
C*variant*lt*lekp*Lithuania - LEKP
C*variant*lt*lekpa*Lithuania - LEKPa
C*variant*lt*std*Lithuania - Standard
C*variant*lt*ibm*Lithuania - IBM (LST 1205-92)
C*layout*no*Norway
C*variant*no**Norway
C*variant*no*mac_nodeadkeys*Norway - Macintosh, eliminate dead keys
C*variant*no*dvorak*Norway - Dvorak
C*variant*no*smi_nodeadkeys*Norway - Northern Saami, eliminate dead keys
C*variant*no*nodeadkeys*Norway - Eliminate dead keys
C*variant*no*smi*Norway - Northern Saami
C*variant*no*mac*Norway - Macintosh
C*layout*ca*Canada
C*variant*ca**Canada
C*variant*ca*multi*Canada - Multilingual, first part
C*variant*ca*fr-dvorak*Canada - French Dvorak
C*variant*ca*eng*Canada - English
C*variant*ca*shs*Canada - Secwepemctsin
C*variant*ca*kut*Canada - Ktunaxa
C*variant*ca*multix*Canada - Multilingual
C*variant*ca*multi-2gr*Canada - Multilingual, second part
C*variant*ca*ike*Canada - Inuktitut
C*variant*ca*fr-legacy*Canada - French (legacy)
C*layout*iq*Iraq
C*variant*iq**Iraq
C*variant*iq*ku*Iraq - Kurdish, Latin Q
C*variant*iq*ku_ara*Iraq - Kurdish, Arabic-Latin
C*variant*iq*ku_alt*Iraq - Kurdish, Latin Alt-Q
C*variant*iq*ku_f*Iraq - Kurdish, (F)
C*layout*me*Montenegro
C*variant*me**Montenegro
C*variant*me*cyrillic*Montenegro - Cyrillic
C*variant*me*latinunicode*Montenegro - Latin unicode
C*variant*me*latinyz*Montenegro - Latin qwerty
C*variant*me*latinalternatequotes*Montenegro - Latin with guillemets
C*variant*me*cyrillicyz*Montenegro - Cyrillic, Z and ZHE swapped
C*variant*me*latinunicodeyz*Montenegro - Latin unicode qwerty
C*variant*me*cyrillicalternatequotes*Montenegro - Cyrillic with guillemets
C*layout*th*Thailand
C*variant*th**Thailand
C*variant*th*pat*Thailand - Pattachote
C*variant*th*tis*Thailand - TIS-820.2538
C*layout*ara*Arabic
C*variant*ara**Arabic
C*variant*ara*qwerty*Arabic - qwerty
C*variant*ara*azerty*Arabic - azerty
C*variant*ara*azerty_digits*Arabic - azerty/digits
C*variant*ara*buckwalter*Arabic - Buckwalter
C*variant*ara*qwerty_digits*Arabic - qwerty/digits
C*variant*ara*digits*Arabic - digits
C*layout*epo*Esperanto
C*variant*epo**Esperanto
C*variant*epo*legacy*Esperanto - displaced semicolon and quote (obsolete)
C*layout*ir*Iran
C*variant*ir**Iran
C*variant*ir*ku*Iran - Kurdish, Latin Q
C*variant*ir*ku_ara*Iran - Kurdish, Arabic-Latin
C*variant*ir*pes_keypad*Iran - Persian, with Persian Keypad
C*variant*ir*ku_alt*Iran - Kurdish, Latin Alt-Q
C*variant*ir*ku_f*Iran - Kurdish, (F)
C*layout*by*Belarus
C*variant*by**Belarus
C*variant*by*latin*Belarus - Latin
C*variant*by*legacy*Belarus - Legacy
C*layout*vn*Vietnam
C*variant*vn**Vietnam
C*layout*kg*Kyrgyzstan
C*variant*kg**Kyrgyzstan
C*variant*kg*phonetic*Kyrgyzstan - Phonetic
C*layout*ua*Ukraine
C*variant*ua**Ukraine
C*variant*ua*crh_alt*Ukraine - Crimean Tatar (Turkish Alt-Q)
C*variant*ua*winkeys*Ukraine - Winkeys
C*variant*ua*rstu_ru*Ukraine - Standard RSTU on Russian layout
C*variant*ua*typewriter*Ukraine - Typewriter
C*variant*ua*crh*Ukraine - Crimean Tatar (Turkish Q)
C*variant*ua*crh_f*Ukraine - Crimean Tatar (Turkish F)
C*variant*ua*rstu*Ukraine - Standard RSTU
C*variant*ua*phonetic*Ukraine - Phonetic
C*variant*ua*legacy*Ukraine - Legacy
C*variant*ua*homophonic*Ukraine - Homophonic
C*layout*ru*Russia
C*variant*ru**Russia
C*variant*ru*os_winkeys*Russia - Ossetian, Winkeys
C*variant*ru*legacy*Russia - Legacy
C*variant*ru*phonetic_winkeys*Russia - Phonetic Winkeys
C*variant*ru*dos*Russia - DOS
C*variant*ru*tt*Russia - Tatar
C*variant*ru*os_legacy*Russia - Ossetian, legacy
C*variant*ru*cv_latin*Russia - Chuvash Latin
C*variant*ru*udm*Russia - Udmurt
C*variant*ru*kom*Russia - Komi
C*variant*ru*cv*Russia - Chuvash
C*variant*ru*phonetic*Russia - Phonetic
C*variant*ru*xal*Russia - Kalmyk
C*variant*ru*bak*Russia - Bashkirian
C*variant*ru*srp*Russia - Serbian
C*variant*ru*typewriter*Russia - Typewriter
C*variant*ru*sah*Russia - Yakut
C*variant*ru*typewriter-legacy*Russia - Typewriter, legacy
C*layout*fi*Finland
C*variant*fi**Finland
C*variant*fi*classic*Finland - Classic
C*variant*fi*nodeadkeys*Finland - Eliminate dead keys
C*variant*fi*smi*Finland - Northern Saami
C*variant*fi*mac*Finland - Macintosh
C*layout*tz*Tanzania
C*variant*tz**Tanzania
C*layout*ro*Romania
C*variant*ro**Romania
C*variant*ro*std_cedilla*Romania - Standard (Cedilla)
C*variant*ro*crh_alt*Romania - Crimean Tatar (Turkish Alt-Q)
C*variant*ro*winkeys*Romania - Winkeys
C*variant*ro*crh_dobruca2*Romania - Crimean Tatar (Dobruca-2 Q)
C*variant*ro*std*Romania - Standard
C*variant*ro*crh_f*Romania - Crimean Tatar (Turkish F)
C*variant*ro*crh_dobruca1*Romania - Crimean Tatar (Dobruca-1 Q)
C*variant*ro*cedilla*Romania - Cedilla
C*layout*kz*Kazakhstan
C*variant*kz**Kazakhstan
C*variant*kz*kazrus*Kazakhstan - Kazakh with Russian
C*variant*kz*ruskaz*Kazakhstan - Russian with Kazakh
C*layout*gr*Greece
C*variant*gr**Greece
C*variant*gr*extended*Greece - Extended
C*variant*gr*nodeadkeys*Greece - Eliminate dead keys
C*variant*gr*simple*Greece - Simple
C*variant*gr*polytonic*Greece - Polytonic
C*layout*it*Italy
C*variant*it**Italy
C*variant*it*nodeadkeys*Italy - Eliminate dead keys
C*variant*it*us*Italy - US keyboard with Italian letters
C*variant*it*mac*Italy - Macintosh
C*variant*it*geo*Italy - Georgian
C*layout*de*Germany
C*variant*de**Germany
C*variant*de*dvorak*Germany - Dvorak
C*variant*de*sundeadkeys*Germany - Sun dead keys
C*variant*de*deadgraveacute*Germany - Dead grave acute
C*variant*de*ro*Germany - Romanian keyboard with German letters
C*variant*de*neo*Germany - Neo 2
C*variant*de*deadacute*Germany - Dead acute
C*variant*de*ro_nodeadkeys*Germany - Romanian keyboard with German letters, eliminate dead keys
C*variant*de*mac_nodeadkeys*Germany - Macintosh, eliminate dead keys
C*variant*de*nodeadkeys*Germany - Eliminate dead keys
C*variant*de*dsb*Germany - Lower Sorbian
C*variant*de*qwerty*Germany - qwerty
C*variant*de*dsb_qwertz*Germany - Lower Sorbian (qwertz)
C*variant*de*mac*Germany - Macintosh
C*layout*bt*Bhutan
C*variant*bt**Bhutan
C*layout*be*Belgium
C*variant*be**Belgium
C*variant*be*oss_latin9*Belgium - Alternative, latin-9 only
C*variant*be*sundeadkeys*Belgium - Sun dead keys
C*variant*be*nodeadkeys*Belgium - Eliminate dead keys
C*variant*be*wang*Belgium - Wang model 724 azerty
C*variant*be*iso-alternate*Belgium - ISO Alternate
C*variant*be*oss*Belgium - Alternative
C*variant*be*oss_sundeadkeys*Belgium - Alternative, Sun dead keys
C*layout*brai*Braille
C*variant*brai**Braille
C*variant*brai*left_hand*Braille - Left hand
C*variant*brai*right_hand*Braille - Right hand
C*layout*uz*Uzbekistan
C*variant*uz**Uzbekistan
C*variant*uz*crh_alt*Uzbekistan - Crimean Tatar (Turkish Alt-Q)
C*variant*uz*latin*Uzbekistan - Latin
C*variant*uz*crh*Uzbekistan - Crimean Tatar (Turkish Q)
C*variant*uz*crh_f*Uzbekistan - Crimean Tatar (Turkish F)
C*layout*us*USA
C*variant*us**USA
C*variant*us*dvorak*USA - Dvorak
C*variant*us*alt-intl*USA - Alternative international (former us_intl)
C*variant*us*dvp*USA - Programmer Dvorak
C*variant*us*colemak*USA - Colemak
C*variant*us*dvorak-classic*USA - Classic Dvorak
C*variant*us*dvorak-intl*USA - Dvorak international
C*variant*us*euro*USA - With EuroSign on 5
C*variant*us*olpc2*USA - Group toggle on multiply/divide key
C*variant*us*altgr-intl*USA - International (AltGr dead keys)
C*variant*us*srp*USA - Serbian
C*variant*us*rus*USA - Russian phonetic
C*variant*us*intl*USA - International (with dead keys)
C*variant*us*dvorak-l*USA - Left handed Dvorak
C*variant*us*dvorak-r*USA - Right handed Dvorak
C*variant*us*mac*USA - Macintosh
C*variant*us*chr*USA - Cherokee
C*layout*cz*Czechia
C*variant*cz**Czechia
C*variant*cz*qwerty*Czechia - qwerty
C*variant*cz*ucw*Czechia - UCW layout (accented letters only)
C*variant*cz*qwerty_bksl*Czechia - qwerty, extended Backslash
C*variant*cz*bksl*Czechia - With <\|> key
C*variant*cz*dvorak-ucw*Czechia - US Dvorak with CZ UCW support
C*layout*mm*Myanmar
C*variant*mm**Myanmar
C*layout*fr*France
C*variant*fr**France
C*variant*fr*dvorak*France - Dvorak
C*variant*fr*oss_latin9*France - Alternative, latin-9 only
C*variant*fr*sundeadkeys*France - Sun dead keys
C*variant*fr*oss_nodeadkeys*France - Alternative, eliminate dead keys
C*variant*fr*bepo*France - Bepo, ergonomic, Dvorak way
C*variant*fr*latin9_nodeadkeys*France - (Legacy) Alternative, eliminate dead keys
C*variant*fr*geo*France - Georgian AZERTY Tskapo
C*variant*fr*bepo_latin9*France - Bepo, ergonomic, Dvorak way, latin-9 only
C*variant*fr*nodeadkeys*France - Eliminate dead keys
C*variant*fr*latin9*France - (Legacy) Alternative
C*variant*fr*latin9_sundeadkeys*France - (Legacy) Alternative, Sun dead keys
C*variant*fr*bre*France - Breton
C*variant*fr*oss*France - Alternative
C*variant*fr*oci*France - Occitan
C*variant*fr*oss_sundeadkeys*France - Alternative, Sun dead keys
C*variant*fr*mac*France - Macintosh
C*layout*ba*Bosnia and Herzegovina
C*variant*ba**Bosnia and Herzegovina
C*variant*ba*unicode*Bosnia and Herzegovina - Use Bosnian digraphs
C*variant*ba*us*Bosnia and Herzegovina - US keyboard with Bosnian letters
C*variant*ba*unicodeus*Bosnia and Herzegovina - US keyboard with Bosnian digraphs
C*variant*ba*alternatequotes*Bosnia and Herzegovina - Use guillemets for quotes
C*layout*ge*Georgia
C*variant*ge**Georgia
C*variant*ge*ru*Georgia - Russian
C*variant*ge*mess*Georgia - MESS
C*variant*ge*ergonomic*Georgia - Ergonomic
C*variant*ge*os*Georgia - Ossetian
C*layout*kh*Cambodia
C*variant*kh**Cambodia
C*layout*af*Afghanistan
C*variant*af**Afghanistan
C*variant*af*olpc-ps*Afghanistan - OLPC Pashto
C*variant*af*ps*Afghanistan - Pashto
C*variant*af*olpc-uz*Afghanistan - OLPC Southern Uzbek
C*variant*af*uz*Afghanistan - Southern Uzbek
C*variant*af*olpc-fa*Afghanistan - OLPC Dari
C*layout*dk*Denmark
C*variant*dk**Denmark
C*variant*dk*mac_nodeadkeys*Denmark - Macintosh, eliminate dead keys
C*variant*dk*dvorak*Denmark - Dvorak
C*variant*dk*nodeadkeys*Denmark - Eliminate dead keys
C*variant*dk*mac*Denmark - Macintosh
C*layout*sn*Senegal
C*variant*sn**Senegal
C*layout*ad*Andorra
C*variant*ad**Andorra
C*layout*al*Albania
C*variant*al**Albania
EOF
 [ ! -f /usr/share/console-setup-mini/kbdnames.gz ] || zcat /usr/share/console-setup-mini/kbdnames.gz 
}

# kbdnames='model*logicdp*Logitech Cordless Desktop Pro
# model*omnikey101*Northgate OmniKey 101
# ...
# layout*el*Greek
# ...
# variant*it*nodeadkeys*Eliminate dead keys'

## CODESETS ##

codesets='Arabic*. Arabic
Armenian*# Armenian
CyrKoi*# Cyrillic - KOI8-R and KOI8-U
CyrAsia*# Cyrillic - non-Slavic languages
CyrSlav*# Cyrillic - Slavic languages (also Bosnian and Serbian Latin)
Ethiopian*. Ethiopic
Georgian*# Georgian
Greek*# Greek
Hebrew*# Hebrew
Lao*# Lao
Lat15*# Latin1 and Latin5 - western Europe and Turkic languages
Lat2*# Latin2 - central Europe and Romanian
Lat38*# Latin3 and Latin8 - Chichewa; Esperanto; Irish; Maltese and Welsh
Lat7*# Latin7 - Lithuanian; Latvian; Maori and Marshallese
Vietnamese*. Latin - Vietnamese
Thai*# Thai
Uni1*. Combined - Latin; Slavic Cyrillic; Hebrew; basic Arabic
Uni2*. Combined - Latin; Slavic Cyrillic; Greek
Uni3*. Combined - Latin; Slavic and non-Slavic Cyrillic'

db_capb backup
CAPB="$RET"
detect_keyboard=false
case $CAPB in
    *plugin-detect-keyboard*)
	detect_keyboard=:
	;;
esac

# Set default value for a question only if it is not seen by the user and
# the value is non-empty
db_default () {
    if \
	[ -f $CONFIGFILE ] \
	|| { db_fget $1 seen && [ "$RET" = false ]; }
    then
	if [ "$2" ]; then
	    db_set $1 "$2"
	fi
    fi
}

# A high level function to ask questions about the keyboard model,
# layout and variant
ask_debconf () {
    local template priority prefix default_code default_description choices

    template=$1     # The template to ask
    priority=$2     # The priority for the question
    prefix=$3       # The prefix for $kbdnames
    default_code=$4 # The default choice (optional)
    choices=`echo "$kbdnames" | grep "^$prefix\*" | 
        sed -e "s/^$prefix\*[^\*]*\*//" -e 's/,/\\\\,/g' | LC_ALL=C sort |
        sed -e 's/$/,/'`
    choices=`echo $choices | sed 's/, *$//'`

    db_subst $template CHOICES "$choices"
    default_description=`echo "$kbdnames" |  
        grep "^$prefix\*${default_code}\*" |
        sed -e "s/^$prefix\*${default_code}\*//"`
    if [ -z "$default_description" ]; then
	# For XkbVariant the empty string is usualy a sensible default
	default_description=`echo "$kbdnames" |  
            grep "^$prefix\*\*" |
            sed -e "s/^$prefix\*\*//"`
    fi
    if [ -n "$default_description" ]; then
	db_default $template "$default_description"
    elif [ -n "$default_code" ]; then
	# A default was requested, but we couldn't resolve it to a
	# description, so we'd better ask.
	priority=critical
    fi

    db_input $priority $template || true
    db_go || return 255
    db_get $template
    RET=`echo "$kbdnames" | grep "^$prefix\*[^\*]*\*" |
             sed 's/  */ /g' |
             grep "\*$RET\$" |
             sed -e "s/^$prefix\*\([^\*]*\)\*.*/\1/" `
    return 0
}

# The guess arch code is taken from "console-data.conf"
# (translated from Perl to shell)

# SUBARCH	KEYMAP SET	DETECTION
# m68k/atari	atari		"Model: Atari"
# m68k/amiga	amiga		"Model: Amiga"
# m68k/mac	mac		"Model: Macintosh"
# m68k/mvme	pc		"Model: Motorola"
# m68k/bvme	pc		"Model: BVME[46]000"
# m68k/{sun,apollo,next,q40,hp300} Not supported by Debian

# ppc/apus	amiga		"machine: Amiga"
# ppc/chrp	pc,mac		"machine: CHRP"
# ppc/pmac	mac		"machine: PowerMac|[Pp]ower[Bb]ook*|Power|iMac*|PowerMac1*"
# ppc/prep	pc		"machine: PReP"
# ppc/ps3	pc		"platform: PS3"
# ppc/cell	pc		"platform: Cell"
# ppc/{bbox,mbx,ppc64,82xx,8xx} Not yet supported by Debian

# arm/*		pc		(refered to as 'arm' only)

guess_arch () {
    local arch subarch line

    if which archdetect >/dev/null; then
	archdetect
	return 0
    fi

    arch=`dpkg --print-architecture`
    
    if [ "$arch" = 'powerpc' -o "$arch" = 'm68k' ]; then
	if [ "$arch" = powerpc ]; then
	    line=`sed -n 's/^platform.*: *//p' /proc/cpuinfo`
	    if [ "$line" = PS3 ] || [ "$line" = Cell ]; then
		subarch=`echo $line|tr A-Z a-z`
	    else
		line=`sed -n 's/^machine.*: *//p' /proc/cpuinfo`
		if [ "$line" = '' ]; then
		    echo unknown
		    return 0
		fi
		subarch=`echo $line|tr A-Z a-z`
	    fi
	elif [ "$arch" = m68k ]; then
	    line=`sed -n 's/^Model.*: *//p' /proc/hardware`
	    if [ "$line" = '' ]; then
		echo unknown
		return 0
	    fi
	    subarch=`echo $line|tr A-Z a-z`
	fi
	case "$subarch" in
	    *amiga*)
		subarch=amiga
		;;
	    *chrp*)
		subarch=chrp
		;;
	    *prep*)
		subarch=prep
		;;
	    *macintosh*|*powermac*|*powerbook*|*power*|*imac*|*powermac1*)
		subarch=mac
		;;
	    *atari*)
		subarch=atari
		;;
	    *motorola*)
		subarch=mvme
		;;
	    *bvme*)
		subarch=bvme
		;;
	    *)
		subarch=`echo $subarch|sed  's/^\s*//'`
		;;
	esac
	arch="$arch/$subarch"
    fi
    echo $arch
    return 0
}

available_fontfaces () {
    echo "$fontsets" | LC_ALL=C sort | \
	grep "^$codeset-" | \
	sed -e "s/^$codeset-//" \
	    -e 's/[0-9][0-9]*x[0-9][0-9]*$//' \
	    -e 's/[0-9]*$//' | \
	uniq
}

available_fontsizes () {
    echo "$fontsets" | LC_ALL=C sort | \
	grep "^$codeset-$fontface[0-9]" | \
	sed -e "s/^$codeset-$fontface//" | \
	uniq
}

decode_codeset () {
    pattern="^$(echo "$*" | sed 's/[^ #()0-9;A-Za-z-]/\\&/g')\\*"
    echo "$codesets" | \
	grep "$pattern" | \
	sed 's/.*[*]//'
}

encode_codeset () {
    pattern="\\*$(echo "$*" | sed 's/[^ #()0-9;A-Za-z-]/\\&/g')\$"
    echo "$codesets" | \
	grep "$pattern" | \
	sed 's/[*].*//'
}

if which locale >/dev/null; then
    eval `locale`
fi

if [ "$LC_CTYPE"  -a "$LC_CTYPE" != C ]; then
    locale=$LC_CTYPE
elif db_get debian-installer/locale && [ "$RET" ]; then
    locale="$RET"
else
    locale=C
fi

if [ "$LC_MESSAGES"  -a "$LC_MESSAGES" != C ]; then
    messages=$LC_MESSAGES
elif db_get debian-installer/locale && [ "$RET" ]; then
    messages="$RET"
else
    messages=C
fi

messages_lang=$(echo $messages | sed 's/_.*//')
messages_country=$(echo $messages | sed 's/.*_//;s/\..*//;s/@.*//')
messages_modif=
echo $messages | grep -v -q @ || messages_modif=$(echo $messages | sed 's/.*@//')

lang_kbdnames () {
    all_kbdnames | \
        grep "^$1[*]" | \
        sed "s/^$1[*]//"
}

kbdnames=$(lang_kbdnames ${messages_lang}_${messages_country}__${messages_modif})
[ -n "$kbdnames" ] || kbdnames=$(lang_kbdnames ${messages_lang}_${messages_country}__${messages_modif})
[ -n "$kbdnames" ] || kbdnames=$(lang_kbdnames ${messages_lang}_${messages_country})
[ -n "$kbdnames" ] || kbdnames=$(lang_kbdnames ${messages_lang})
[ -n "$kbdnames" ] || kbdnames=$(lang_kbdnames C)

case "$locale" in
    *KOI8*|*koi8*)
	default_codeset=CyrKoi
	codeset_priority=low
	;;
    aa_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    af_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    am_*)
	default_codeset=Ethiopic
	codeset_priority=low
	;;
    an_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    ar_*)
	default_codeset=Arabic
	codeset_priority=low
	;;
    ast_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    az_*)
	default_codeset=Uni3
	codeset_priority=low
	;;
    be_*)
	default_codeset=CyrSlav
	codeset_priority=low
	;;
    bg_*)
	default_codeset=CyrSlav
	codeset_priority=low
	;;
    bn_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    br_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    bs_*)
	default_codeset=Uni3
	codeset_priority=low
	;;
    byn_*)
	default_codeset=Ethiopian
	codeset_priority=low
	;;
    ca_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    cs_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    cy_*)
	default_codeset=Lat38
	codeset_priority=low
	;;
    da_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    de_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    el_*)
	default_codeset=Greek
	codeset_priority=low
	;;
    en_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    eo|eo.*|eo_*|eo\@*)
	default_codeset=Lat38
	codeset_priority=low
	;;
    es_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    et_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    eu_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    fa_*)
	default_codeset=Arabic
	codeset_priority=low
	;;
    fi_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    fo_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    fr_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    ga_*)
	default_codeset=Lat38
	codeset_priority=low
	;;
    gd_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    gez_*)
	default_codeset=Ethiopian
	codeset_priority=low
	;;
    gl_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    gu_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    gv_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    he_*)
	default_codeset=Hebrew
	codeset_priority=low
	;;
    hi_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    hr_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    hu_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    hy_*)
	default_codeset=Armenian
	codeset_priority=low
	;;
    id_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    is_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    it_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    iw_*)
	default_codeset=Hebrew
	codeset_priority=low
	;;
    ja_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    ka_*)
	default_codeset=Georgian
	codeset_priority=low
	;;
    kl_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    kn_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    ko_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    kw_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    lg_*)
	default_codeset=Lat15 # TODO: This must be ISO-8859-10 (Latin6)
	codeset_priority=low
	;;
    lo_*)
	default_codeset=Lao
	codeset_priority=low
	;;
    lt_*)
	default_codeset=Lat7
	codeset_priority=low
	;;
    lv_*)
	default_codeset=Lat7
	codeset_priority=low
	;;
    mi_*)
	default_codeset=Lat7
	codeset_priority=low
	;;
    mk_*)
	default_codeset=CyrSlav
	codeset_priority=low
	;;
    ml_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    mn_*)
	default_codeset=CyrAsia
	codeset_priority=low
	;;
    mr_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    ms_*)
	default_codeset=Lat15 # TODO: Is this correct? (Malay language)
	codeset_priority=low
	;;
    mt_*)
	default_codeset=Lat38
	codeset_priority=low
	;;
    nb_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    ne_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    nl_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    nn_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    oc_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    om_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    pa_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    pl_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    pt_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    ro_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    ru_*)
	default_codeset=CyrSlav
	codeset_priority=low
	;;
    se_*)
	default_codeset=Uni1
	codeset_priority=low
	;;
    sid_*)
	default_codeset=Lat15 # TODO: Is this correct? (Sidama language)
	codeset_priority=low
	;;
    sk_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    sl_*)
	default_codeset=Lat2
	codeset_priority=low
	;;
    so_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    sq_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    sr_*)
	default_codeset=CyrSlav
	codeset_priority=low
	;;
    st_*)
	default_codeset=Lat15 # TODO: Is this correct? (Sotho language)
	codeset_priority=low
	;;
    sv_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    ta_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    te_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    tg_*)
	default_codeset=CyrAsia
	codeset_priority=low
	;;
    th_*)
	default_codeset=Thai
	codeset_priority=low
	;;
    ti_*)
	default_codeset=Ethiopian
	codeset_priority=low
	;;
    tig_*)
	default_codeset=Ethiopian
	codeset_priority=low
	;;
    tl_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    tr_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    tt_*)
	default_codeset=Lat15 # TODO: Is this correct? (Tatar language)
	codeset_priority=low
	;;
    uk_*)
	default_codeset=CyrSlav
	codeset_priority=low
	;;
    ur_*)
	default_codeset=Arabic
	codeset_priority=low
	;;
    uz_*)
	default_codeset=Lat15 # TODO: Is this correct? (Uzbek language)
	codeset_priority=low
	;;
    uz_*\@cyrillic)
	default_codeset=CyrAsia
	codeset_priority=low
	;;
    vi_*)
	default_codeset=Vietnamese
	codeset_priority=low
	;;
    wa_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    xh_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    yi_*)
	default_codeset=Hebrew
	codeset_priority=low
	;;
    zh_*)
	default_codeset=unsupported
	codeset_priority=low
	;;
    zu_*)
	default_codeset=Lat15
	codeset_priority=low
	;;
    *)
	default_codeset=Uni1
	codeset_priority=high
	;;
esac
if [ "$default_codeset" = unsupported ]; then
    default_codeset=Uni1
fi

default_codeset="`decode_codeset $default_codeset`"
if [ -z "$default_codeset" ]; then
    default_codeset=Uni1
    codeset_priority=high
fi

default_layout=''
default_variant=''
if [ -e /etc/console/boottime.kmap.gz ]; then
    # Upgrade from pre-console-setup; we need to ask if autodetection fails.
    layout_priority=critical
else
    # Probably a fresh installation. If the installation is being automated,
    # then in the worst case selecting a "us" layout won't break the system,
    # so drop the priority a little bit.
    layout_priority=high
fi
case "$locale" in
    # Keyboards for countries
    *_AL*)
	default_layout=al  # Albania
	;;
    *_AZ*)
	default_layout=az  # Azerbaijan
	;;
    *_BD*)
	default_layout=bd  # Bangladesh
	;;
    *_BE*)
	default_layout=be  # Belgium
	;;
    *_BG*)
	default_layout=bg  # Bulgaria
	layout_priority=critical
	;;
    *_BR*)
	default_layout=br  # Brazil
	;;
    *_BY*)
	default_layout=by  # Belarus
	;;
    fr_CA*)
	default_layout=ca  # Canada
	;;
    *_CA*)
	default_layout=us  # U.S. English
	;;
    fr_CH*)
	default_layout=ch  # Switzerland
	default_variant=fr # French
	;;
    *_CH*)
	default_layout=ch  # Switzerland
	layout_priority=critical
	;;
    *_CZ*)
	default_layout=cz  # Czechia
	layout_priority=critical
	;;
    *_DK*)
	default_layout=dk  # Denmark
	;;
    *_EE*)
	default_layout=ee  # Estonia
	;;
    ast_ES*)
	default_layout=es  # Spain
	default_variant=ast # Asturian
	;;
    ca_ES*)
	default_layout=es  # Spain
	default_variant=cat # Catalan
	;;
    *_ES*)
	default_layout=es  # Spain
	;;
    se_FI*)
	default_layout=fi  # Finland
	default_variant=smi # Northern Saami
	;;
    *_FI*)
	default_layout=fi  # Finland
	default_variant=fi # Finland
	;;
    *_GB*)
	default_layout=gb  # United Kingdom
	;;
    *_GG*)
	default_layout=gb  # United Kingdom
	;;
    *_HU*)
	default_layout=hu  # Hungary
	;;
    *_IE*)
	default_layout=ie  # Ireland
	;;
    *_IL*)
	default_layout=il  # Israel
	layout_priority=critical
	;;
    *_IM*)
	default_layout=gb  # United Kingdom
	;;
    *_IR*)
	default_layout=ir  # Iran
	;;
    *_IS*)
	default_layout=is  # Iceland
	;;
    *_IT*)
	default_layout=it  # Italy
	;;
    *_JE*)
	default_layout=gb  # United Kingdom
	;;
    *_JP*)
	default_layout=jp  # Japan
	;;
    *_LT*)
	default_layout=lt  # Lithuania
	layout_priority=critical
	;;
    *_LV*)
	default_layout=lv  # Latvia
	;;
    *_MA*)
	default_layout=ma  # Morocco
	;;
    *_MK*)
	default_layout=mk  # Macedonia
	;;
# According to https://launchpad.net/bugs/129982, Dutch users prefer the US
# keymap.
    *_NL*)
	default_layout=us  # Netherlands
	default_variant=intl # International (with dead keys)
	;;
    *_MN*)
	default_layout=mn  # Mongolia
	;;
    *_MT*)
	default_layout=mt  # Malta
	layout_priority=critical
	;;
    se_NO*)
	default_layout=no  # Norway
	default_variant=smi # Northern Saami
	;;
    *_NO*)
	default_layout=no  # Norway (se_NO is not in this case)
	;;
    *_PL*)
	default_layout=pl  # Poland
	;;
    *_PT*)
	default_layout=pt  # Portugal
	;;
    *_RO*)
	default_layout=ro  # Romania
	;;
    *_RU*)
	default_layout=ru  # Russia
	layout_priority=critical
	;;
    se_SE*)
	default_layout=se  # Sweden
	default_variant=smi # Northern Saami
	;;
    *_SK*)
	default_layout=sk  # Slovakia
	;;
    *_SI*)
	default_layout=si  # Slovenia
	;;
    *_TJ*)
	default_layout=tj  # Tajikistan
	;;
    *_TH*)
	default_layout=th  # Thailand
	layout_priority=critical
	;;
    ku_TR*)
	default_layout=tr  # Turkish
	default_variant=ku # Kurdish, Latin Q
	;;
    *_TR*)
	default_layout=tr  # Turkish
	layout_priority=critical
	;;
    *_UA*)
	default_layout=ua  # Ukraine
	;;
    en_US*)
	default_layout=us  # U.S. English
	;;
# According to https://launchpad.net/bugs/191451, most keyboards in Vietnam
# are in fact US keyboards.
    *_VN*)
	default_layout=us  # Vietnam
	;;
    # Keyboards for specific languages and international keyboards:
    # TODO: Is the following list correct?
    *_AR*|*_BO*|*_CL*|*_CO*|*_CR*|*_DO*|*_EC*|*_GT*|*_HN*|*_MX*|*_NI*|*_PA*|*_PE*|es_PR*|*_PY*|*_SV*|es_US*|*_UY*|*_VE*)
	default_layout=latam # Latin American
	;;
    ar_*)
	default_layout=ara # Arabic
	;;
    bs_*)
	default_layout=ba  # Bosnia and Herzegovina
	;;
    de_*)
	default_layout=de  # Germany
	;;
    el_*)
	default_layout=gr  # Greece
	;;
    eo|eo.*|eo_*|eo\@*)
	default_layout=epo  # Esperanto
	;;
    fr_*)
	default_layout=fr  # France
	default_variant=oss # Alternative
	layout_priority=critical
	;;
    gu_*)
	default_layout=in  # India
	default_variant=guj # Gujarati
	;;
    hi_*)
	default_layout=in  # India
	default_variant=deva # Devanagari
	;;
    hr_*)
	default_layout=hr  # Croatia
	;;
    hy_*)
	default_layout=am  # Armenia
	;;
    ka_*)
	default_layout=ge  # Georgia
	layout_priority=critical
	;;
    kn_*)
	default_layout=in  # India
	default_variant=kan # Kannada
	;;
    lo_*)
	default_layout=la  # Laos
	;;
    ml_*)
	default_layout=in  # India
	default_variant=mal # Malayalam
	;;
    pa_*)
	default_layout=in  # India
	default_variant=guru # Gurmukhi
	;;
    sr_ME*)
	default_layout=me  # Montenegro
	layout_priority=critical
	;;
    sr_*)
	default_layout=rs  # Serbia
	layout_priority=critical
	;;
    sv_*)
	default_layout=se  # Sweden
	default_variant=basic
	;;
    ta_*)
	default_layout=in  # India
	default_variant=tam # Tamil
	;;
    te_*)
	default_layout=in  # India
	default_variant=tel # Telugu
	;;
    zh_CN)
	default_layout=cn  # China
	;;
    # Fallback
    *)
	default_layout=us
	;;
esac

if \
    [ -d /lib/debian-installer ] \
    && db_get debian-installer/charmap \
    && [ "$RET" ]
then
    default_charmap="$RET"
elif [ "$locale" = C ]; then
    default_charmap=UTF-8
    charmap_priority=high
elif which locale >/dev/null; then
    default_charmap=`locale charmap`
else
    default_charmap=unknown
fi
if echo "$charmaps" | grep "$default_charmap" >/dev/null; then
    charmap_priority=low
else
    default_charmap=UTF-8
    charmap_priority=high
fi

arch=`guess_arch`

case "$arch" in
    alpha*)
	default_model=pc105
	model_priority=medium
	;;
    amd64*)
	default_model=pc105
	model_priority=medium
	;;
    arm*)
	default_model=pc105
	model_priority=medium
	;;
    i386*)
	default_model=pc105
	model_priority=medium
	;;
    ia64*)
	default_model=pc105
	model_priority=medium
	;;
    m68k/amiga)
	default_model=amiga
	model_priority=medium
	;;
    m68k/atari)
	default_model=ataritt
	model_priority=medium
	;;
    m68k/mac)
	default_model=macintosh_old
	model_priority=medium
	;;
    m68k/sun*)
	default_model=sun4 # also sun5, pc105
	model_priority=critical
	;;
    m68k/*vme*)
	default_model=pc105
	model_priority=medium
	;;
    mips*)
	default_model=pc105
	model_priority=medium
	;;
    powerpc/amiga)
	default_model=amiga
	model_priority=medium
	;;
    powerpc/apus)
	default_model=amiga
	model_priority=medium
	;;
    powerpc/chrp*)
	default_model=pc105 # also macintosh_old and maybe amiga
	model_priority=critical
	;;
    powerpc/mac)
	default_model=pc105
	model_priority=medium
	;;
    powerpc/pasemi)
	default_model=pc105
	model_priority=medium
	;;
    powerpc/powermac*)
	default_model=pc105
	model_priority=medium
	;;
    powerpc/prep)
	default_model=pc105
	model_priority=medium
	;;
    powerpc/ps3|powerpc/cell)
	default_model=pc105
	model_priority=medium
	;;
    sparc*)
	default_model=pc105 # also sun4, sun5
	model_priority=critical
	;;
    s390*)
	default_model=pc105
	model_priority=medium
	;;
    *)
	default_model=pc105
	model_priority=critical
	;;
esac    

### READ THE DEFAULTS ##################################################

XKBMODEL=''
XKBLAYOUT=''
XKBVARIANT=''
XKBOPTIONS=''

# Use the value of debian-installer/keymap to get better default
# layout.  Lower the priority of the Debconf question to medium.
# This guesswork is copied from xserver-xorg.config.
if db_get debian-installer/keymap && [ "$RET" ]; then
    di_keymap="${RET##mac-usb-}"
    di_keymap="${di_keymap%%-latin1}"

    case "$di_keymap" in
	be2) XKBLAYOUT="be";;
	bg) XKBLAYOUT="us,bg";;
	br) XKBLAYOUT="us"; XKBVARIANT="intl"; XKBMODEL="pc104";;
	br-abnt2) XKBLAYOUT="br"; XKBVARIANT="abnt2"; XKBMODEL="abnt2";;
	by) XKBLAYOUT="us,by";;
	cf) XKBLAYOUT="ca"; XKBVARIANT="fr";;
	croat) XKBLAYOUT="hr";;
	cz-lat2) XKBLAYOUT="cz";;
	de-latin1-nodeadkeys) XKBLAYOUT="de"; XKBVARIANT="nodeadkeys";;
	de) XKBLAYOUT="de";;
	dvorak) XKBLAYOUT="us"; XKBVARIANT="dvorak"; XKBMODEL="pc104";;
	dk) XKBLAYOUT="dk";;
	es) XKBLAYOUT="es";;
	et) XKBLAYOUT="ee";;
	'fi') XKBLAYOUT="fi";;
	fr-latin9) XKBLAYOUT="fr"; XKBVARIANT="latin9";;
	fr_CH) XKBLAYOUT="ch"; XKBVARIANT="fr";;
	fr) XKBLAYOUT="fr";;
	hebrew) XKBLAYOUT="us,il";;
	hu) XKBLAYOUT="hu";;
	gb) XKBLAYOUT="gb";;
	is) XKBLAYOUT="is";;
	it) XKBLAYOUT="it";;
	jp106) XKBLAYOUT="jp,jp"; XKBVARIANT=",kana"; XKBMODEL="jp106";;
	la) XKBLAYOUT="latam";;
	lt) XKBLAYOUT="lt";; 
	lv-latin4) XKBLAYOUT="lv";;
	mac-us-std) XKBLAYOUT="us";;
	mac-de2-ext) XKBLAYOUT="de"; XKBVARIANT="nodeadkeys";;
	mac-fr2-ext) XKBLAYOUT="fr";;
	mac-fr3) XKBLAYOUT="fr";;
	mac-es) XKBLAYOUT="es";;
	mk) XKBLAYOUT="us,mk";;
	nl) XKBLAYOUT="nl";;
	no) XKBLAYOUT="no";;
	pl) XKBLAYOUT="pl";;
	pt) XKBLAYOUT="pt";;
	ro) XKBLAYOUT="ro";;
	ru) XKBLAYOUT="us,ru";;
	se) XKBLAYOUT="se";;
	sg) XKBLAYOUT="ch"; XKBVARIANT="de";;
	sk-qwerty) XKBLAYOUT="sk"; XKBVARIANT="qwerty";;
	slovene) XKBLAYOUT="si";;
	sr-cy) XKBLAYOUT="rs,rs"; XKBVARIANT="latin,basic" ;;
	trf|trfu) XKBLAYOUT="tr"; XKBVARIANT="f";;
	trq|trqu) XKBLAYOUT="tr";;
	ua) XKBLAYOUT="us,ua";;
	uk) XKBLAYOUT="gb";;
	us) XKBLAYOUT="us"; XKBMODEL="pc104";;
    esac
fi

# Get defaults from debconf, to allow preseeding.
if [ -d /lib/debian-installer ] || [ "$OVERRIDE_ALLOW_PRESEEDING" ]; then
    if db_get console-setup/modelcode && [ "$RET" ]; then
	default_model="$RET"
    fi
    if db_get console-setup/layoutcode && [ "$RET" ]; then
	default_layout="$RET"
	if db_fget console-setup/layoutcode seen && [ "$RET" = true ]; then
	    layout_priority=medium
	    db_set console-setup/ask_detect false
	    db_fset console-setup/ask_detect seen true
	fi
    fi
    if db_get console-setup/variantcode && [ "$RET" ]; then
	default_variant="$RET"
    fi
    if db_get console-setup/optionscode && [ "$RET" ]; then
	XKBOPTIONS="$RET"
    fi
    if db_get console-setup/fontsize && [ "$RET" ]; then
	db_set console-setup/fontsize-text "$RET"
	db_set console-setup/fontsize-fb "$RET"
    fi
fi

# Get default layout from xorg.conf if available
if [ -f /etc/X11/xorg.conf ] && which awk >/dev/null; then
    awk_expr='
{
    $0 = tolower($0);
    sub("#.*","")
    xkb = "";
}

/^[ \t]*section[ \t]+"inputdevice"/,/^[ \t]*endsection/ {
    if ($1 == "option") {
	if ($2 == "\"xkbmodel\"") {
	    xkb = "XKBMODEL";
	} else if ($2 == "\"xkblayout\"") {
	    xkb = "XKBLAYOUT";
	} else if ($2 == "\"xkbvariant\"") {
	    xkb = "XKBVARIANT";
	} else if ($2 == "\"xkboptions\"") {
	    xkb = "XKBOPTIONS"; 
	}
	$1 = "";
	$2 = "";
    }
}

xkb != "" && /^[ \t]*\"[^"]+\"[ \t]*$/ {
    sub("^[ \t]*\"", "");
    sub("\".*", "");
    gsub("[ \t]", "");
    if ($1 !~ /[()]/) {
	print xkb "=\"" $0 "\"";
    } else {
	if (xkb == "XKBLAYOUT" && $1 ~ /^[^()]+\([^()]+\)$/) {
	    split($1, s, /[()]/);
	    print "XKBLAYOUT=" s[1];
	    print "XKBVARIANT=" s[2];
	}
    }
}
'
    eval $(awk "$awk_expr" < /etc/X11/xorg.conf)
fi

# Load the config file, if it exists.
if [ -e $CONFIGFILE ]; then
    . $CONFIGFILE || true
fi

if [ "$ACTIVE_CONSOLES" ]; then
    default_ttys="$ACTIVE_CONSOLES"
fi
if [ "$CHARMAP" ]; then
    default_charmap="$CHARMAP"
fi
if [ "$FONTFACE" ]; then
    default_fontface="$FONTFACE"
fi
if [ "$FONTSIZE" ]; then
    default_fontsize="$FONTSIZE"
fi
if [ "$CODESET" ]; then
    default_codeset="`decode_codeset $CODESET`"
    if [ -z "$default_codeset" ]; then
	default_codeset=Uni1
	codeset_priority=high
    fi
fi
if [ "$XKBMODEL" ] ; then
    model_priority=medium
    default_model="$XKBMODEL"
fi

XKBLAYOUT=$(echo $XKBLAYOUT | sed 's/ *//g')
XKBVARIANT=$(echo $XKBVARIANT | sed 's/ *//g')

if [ "$XKBLAYOUT" ]; then
    layout_priority=medium

    migrate_layout () {
	case "$1" in
	    cs)
		echo rs
		;;
	    *)
		echo "$1"
		;;
	esac
    }

    migrate_variant () {
	case "$1" in
	    jp)
		case "$2" in
		    latin)
			echo 106
			;;
		    jp106)
			echo kana
			;;
		    *)
			echo "$2"
			;;
		esac
		;;
	    *)
		echo "$2"
		;;
	esac
    }

    # Migration
    case "$XKBLAYOUT" in
	*,*)
	    layout1="${XKBLAYOUT%%,*}"
	    layout2="${XKBLAYOUT#*,}"
	    variant1="${XKBVARIANT%%,*}"
	    variant2="${XKBVARIANT#*,}"
	    XKBLAYOUT="$(migrate_layout "$layout1"),$(migrate_layout "$layout2")"
	    XKBVARIANT="$(migrate_variant "$layout1" "$variant1"),$(migrate_variant "$layout2" "$variant2")"
	    ;;
	*)
	    XKBLAYOUT="$(migrate_layout "$XKBLAYOUT")"
	    XKBVARIANT="$(migrate_variant "$XKBLAYOUT" "$XKBVARIANT")"
	    ;;
    esac

    case "$XKBLAYOUT" in
	lt,lt)
	    default_layout="${XKBLAYOUT%,*}"
	    default_variant="${XKBVARIANT%,*}"
	    unsupported_layout=no
	    ;;
	jp,jp|us,jp)
	    # fix on upgrade for #526862
	    default_layout="${XKBLAYOUT#*,}"
	    default_variant="${XKBVARIANT#*,}"
	    unsupported_layout=no
	    ;;
	# TODO: make s.t. to not forget to update this list
	me,me|rs,rs|us,am|us,ara|us,ben|us,bd|us,bg|us,bt|us,by|us,deva|us,ge|us,gh|us,gr|us,guj|us,guru|us,il|us,in|us,ir|us,iku|us,kan|us,kh|us,kz|us,la|us,lao|us,lk|us,lt|us,mk|us,mm|us,mn|us,mv|us,mal|us,ori|us,pk|us,ru|us,scc|us,sy|us,syr|us,tel|us,th|us,tj|us,tam|us,ua|us,uz)
	    if [ "${XKBVARIANT%,*}" = '' ]; then
		default_layout="${XKBLAYOUT#*,}"
		default_variant="${XKBVARIANT#*,}"
		unsupported_layout=no
	    else
		unsupported_layout=yes
	    fi
	    ;;	    
	*,*)
	    unsupported_layout=yes
	    ;;
	*)
	    default_layout="$XKBLAYOUT"
	    default_variant="$XKBVARIANT"
	    ;;
    esac
fi

# since there are two completely different layouts 
if [ "$default_layout" = bg -a -z "$default_variant" ]; then
    default_variant=bds
    layout_priority=high
fi

if [ "$XKBOPTIONS" ]; then
    default_toggle='No toggling'
    default_switch='No temporary switch'
    default_altgr='No AltGr key'
    default_compose='No compose key'
    for option in `echo $XKBOPTIONS | sed 's/,/ /g'`; do
	case "$option" in
	    compose:caps)
		default_compose='Caps Lock';;
	    compose:lwin)
		default_compose='Left Logo key';;
	    compose:menu)
		default_compose='Menu key';;
	    compose:ralt)
		default_compose='Right Alt';;
	    compose:rctrl)
		default_compose='Right Control';;
	    compose:rwin)
		default_compose='Right Logo key';;
	    grp:alt_caps_toggle)
		default_toggle='Alt+Caps Lock';;
	    grp:alt_shift_toggle)
		default_toggle='Alt+Shift';;
	    grp:caps_toggle)
		default_toggle='Caps Lock';;
	    grp:ctrl_alt_toggle)
		default_toggle='Control+Alt';;
	    grp:ctrl_shift_toggle)
		default_toggle='Control+Shift';;
	    grp:lalt_toggle)
		default_toggle='Left Alt';;
	    grp:lctrl_lshift_toggle)
		default_toggle='Left Control+Left Shift';;
	    grp:lctrl_toggle)
		default_toggle='Left Control';;
	    grp:lshift_toggle)
		default_toggle='Left Shift';;
	    grp:lswitch)
		default_switch='Left Alt';;
	    grp:lwin_switch)
		default_switch='Left Logo key';;
	    grp:lwin_toggle)
		default_toggle='Left Logo key';;
	    grp:menu_toggle)
		default_toggle='Menu key';;
	    grp:rctrl_toggle)
		default_toggle='Right Control';;
	    grp:rshift_toggle)
		default_toggle='Right Shift';;
	    grp:rwin_switch)
		default_switch='Right Logo key';;
	    grp:rwin_toggle)
		default_toggle='Right Logo key';;
	    grp:sclk_toggle)
		default_toggle='Scroll Lock key';;
	    grp:switch)
		default_switch='Right Alt';;
	    grp:toggle)
		default_toggle='Right Alt';;
	    grp:win_switch)
		default_switch='Both Logo keys';;
	    lv3:alt_switch)
		default_altgr='Both Alt keys';;
	    lv3:enter_switch)
		default_altgr='Keypad Enter key';;
	    lv3:lalt_switch)
		default_altgr='Left Alt';;
	    lv3:lwin_switch)
		default_altgr='Left Logo key';;
	    lv3:menu_switch)
		default_altgr='Menu key';;
	    lv3:ralt_switch)
		default_altgr='Right Alt';;
	    lv3:rwin_switch)
		default_altgr='Right Logo key';;
	    lv3:switch)
		default_altgr='Right Control';;
	    lv3:win_switch)
		default_altgr='Both Logo keys';;
	    grp_led:scroll)
		;;
	    *)
		unsupported_options=yes
		;;
	esac
    done
fi

# Store some of the default values into debconf db.
db_default console-setup/ttys "$default_ttys"
db_default console-setup/charmap "$default_charmap"
db_default console-setup/codeset "$default_codeset"
db_default console-setup/fontface "$default_fontface"
db_default console-setup/fontsize-text "$default_fontsize"
db_default console-setup/fontsize-fb "$default_fontsize"
db_default console-setup/fontsize "$default_fontsize"
db_default console-setup/toggle "$default_toggle"
db_default console-setup/switch "$default_switch"
db_default console-setup/altgr "$default_altgr"
db_default console-setup/compose "$default_compose"

#######################################################################

STATE=1
old_state=0
while :; do
    starting_state=$STATE
    case "$STATE" in
	1)
	    if \
		ask_debconf console-setup/model $model_priority \
		    model $default_model
	    then
		db_set console-setup/modelcode "$RET"
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    ;;
	2)
	    db_get console-setup/modelcode
	    if \
		$detect_keyboard \
		&& [ "$RET" != SKIP ] \
		&& [ -e "/usr/share/console-setup-mini/$RET.tree" ]
	    then
		db_input high console-setup/ask_detect || true
		if db_go; then
		    STATE=$(($STATE + 1))
		else
		    STATE=$(($STATE - 1))
		fi
	    else
		STATE=$(($STATE + $STATE - $old_state))
	    fi
	    ;;
	3)
	    db_get console-setup/modelcode
	    model="$RET"
	    if \
		[ "$STATE" -ge "$old_state" ] \
		&& $detect_keyboard \
		&& [ "$model" != SKIP ] \
		&& [ -e "/usr/share/console-setup-mini/$model.tree" ] \
		&& db_get console-setup/ask_detect \
		&& [ "$RET" = true ]
	    then
		db_subst console-setup/detect FILENAME \
		    "/usr/share/console-setup-mini/$model.tree"
		if db_input critical console-setup/detect && db_go; then
		    db_get console-setup/detect
		    detected_keyboard="$RET"
		    # TODO: produce human-readable layout name
		    db_subst console-setup/detected LAYOUT "$detected_keyboard"
		    db_input high console-setup/detected || true
		    if db_go; then
			unsupported_layout=no
			STATE=$(($STATE + 1))
		    else
			detected_keyboard=
			STATE=$(($STATE - 1))
		    fi
		else
		    STATE=$(($STATE - 1))
		fi
	    else
		detected_keyboard=
		STATE=$(($STATE + $STATE - $old_state))
	    fi
	    ;;
	4)
	    if [ "$detected_keyboard" ] || [ "$model" = SKIP ]; then
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif [ "$unsupported_layout" = yes ]; then
		if [ -f /etc/default/console-setup ]; then
		    db_reset console-setup/unsupported_config_layout || true
		    db_fset console-setup/unsupported_config_layout seen false
		    db_subst console-setup/unsupported_config_layout \
			XKBLAYOUT "$XKBLAYOUT"
		    db_input medium console-setup/unsupported_config_layout \
			|| true
		    if db_go; then 
			STATE=$(($STATE + 1))
		    else
			STATE=$(($STATE - 1))
		    fi
		    db_get console-setup/unsupported_config_layout
		else
		    db_reset console-setup/unsupported_layout || true
		    db_fset console-setup/unsupported_layout seen false
		    db_subst console-setup/unsupported_layout \
			XKBLAYOUT "$XKBLAYOUT"
		    db_input medium console-setup/unsupported_layout || true
		    if db_go; then 
			STATE=$(($STATE + 1))
		    else
			STATE=$(($STATE - 1))
		    fi
		    db_get console-setup/unsupported_layout
		fi
		if [ "$RET" != true ]; then
		    unsupported_layout=no
		fi
	    else
		# skip the question without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    fi
	    ;;
	5)
	    if [ "$detected_keyboard" ]; then
		layout="${detected_keyboard%%:*}"
		db_set console-setup/layoutcode "$layout"
		# skip the question without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif [ "$model" = SKIP ]; then
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif [ "$unsupported_layout" = yes ]; then
		db_set console-setup/layoutcode "$XKBLAYOUT"
		# skip the question without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif \
		ask_debconf console-setup/layout "$layout_priority" \
		    layout "$default_layout"
	    then
		layout="$RET"
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    ;;
	6)
	    adjust_layout=false
	    if [ "$detected_keyboard" ]; then
		case $detected_keyboard in
		    *:*)
			variant="${detected_keyboard#*:}"
			;;
		    *)
			variant=
			;;
		esac
		db_set console-setup/variantcode "$variant"
		adjust_layout=:
		# skip the question without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif [ "$model" = SKIP ]; then
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif [ "$unsupported_layout" = yes ]; then
		db_set console-setup/variantcode "$XKBVARIANT"
		# skip the question without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif \
		ask_debconf console-setup/variant "$layout_priority" \
                    "variant\*${layout}" "$default_variant"
	    then
		variant="$RET"
		adjust_layout=:
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    if $adjust_layout; then
		case "$layout" in
		    jp)
			case "$variant" in
			    106|common|OADG109A|nicola_f_bs|'')
				latin=yes
				real_layout=$layout
				;;
			    *)
				latin=no
				real_layout=jp,jp
				;;
			esac
			;;
		    lt)
			latin=no
			real_layout=lt,lt
			;;
		    me)
			case "$variant" in
			    basic|latin*)
				latin=yes
				real_layout=$layout
				;;
			    *)
				latin=no
				real_layout=me,me
				;;
			esac
			;;
		    rs)
			case "$variant" in
			    basic|latin*)
				latin=yes
				real_layout=$layout
				;;
			    *)
				latin=no
				real_layout=rs,rs
				;;
			esac
			;;
		    # TODO: make s.t. to not forget to update this list.  Don't
		    # forget to update also the nonlatin list in kbdcompiler
		    am|ara|ben|bd|bg|bt|by|deva|ge|gh|gr|guj|guru|il|in|ir|iku|kan|kh|kz|la|lao|lk|mk|mm|mn|mv|mal|ori|pk|ru|scc|sy|syr|tel|th|tj|tam|ua|uz)
			latin=no
			real_layout=us,$layout
			;;
		    *)
			latin=yes
			real_layout=$layout
			;;
		esac
		db_set console-setup/layoutcode "$real_layout"
		if [ "$latin" = yes ]; then
		    db_set console-setup/variantcode "$variant"
		elif [ "$real_layout" = lt,lt ]; then
		    case "$variant" in
			us)
			    db_set console-setup/variantcode "us,"
			    ;;
			*)
			    db_set console-setup/variantcode "$variant,us"
			    ;;
		    esac
		elif [ "$real_layout" = jp,jp ]; then
			    db_set console-setup/variantcode "106,$variant"
		elif [ "$real_layout" = me,me ]; then
		    case "$variant" in
			cyrillicyz)
			    db_set console-setup/variantcode \
				"latinyz,$variant"
			    ;;
			cyrillicalternatequotes)
			    db_set console-setup/variantcode \
				"latinalternatequotes,$variant"
			    ;;
			*)
			    db_set console-setup/variantcode \
				"basic,$variant"
			    ;;
		    esac
		elif [ "$real_layout" = rs,rs ]; then
		    case "$variant" in
			yz)
			    db_set console-setup/variantcode \
				"latinyz,$variant"
			    ;;
			alternatequotes)
			    db_set console-setup/variantcode \
				"latinalternatequotes,$variant"
			    ;;
			*)
			    db_set console-setup/variantcode \
				"latin,$variant"
			    ;;
		    esac
		else
		    db_set console-setup/variantcode ",$variant"
		fi
	    fi
	    ;;
	7)
	    if \
		[ "$unsupported_layout" = no \
		-a "$unsupported_options" = yes ]
	    then
		if [ -f /etc/default/console-setup ]; then
		    db_reset console-setup/unsupported_config_options || true
		    db_fset console-setup/unsupported_config_options seen false
		    db_subst console-setup/unsupported_config_options \
			XKBOPTIONS "$XKBOPTIONS"
		    db_input medium console-setup/unsupported_config_options \
			|| true
		    if db_go; then 
			STATE=$(($STATE + 1))
		    else
			STATE=$(($STATE - 1))
		    fi
		    db_get console-setup/unsupported_config_options
		else
		    db_reset console-setup/unsupported_options || true
		    db_fset console-setup/unsupported_options seen false
		    db_subst console-setup/unsupported_options \
			XKBOPTIONS "$XKBOPTIONS"
		    db_input medium console-setup/unsupported_options || true
		    if db_go; then 
			STATE=$(($STATE + 1))
		    else
			STATE=$(($STATE - 1))
		    fi
		    db_get console-setup/unsupported_options
		fi
		if [ "$RET" != true ]; then
		    unsupported_options=no
		fi
	    else
		# skip the question without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    fi
	    ;;
	8)
	    if \
		[ "$unsupported_layout" = yes \
		-o "$unsupported_options" = yes ]
	    then
		db_set console-setup/optionscode "$XKBOPTIONS"
		# skip the questions without making Debconf loop
		STATE=$(( $STATE + $STATE - $old_state ))
	    elif [ "$model" = SKIP ]; then
		STATE=$(( $STATE + $STATE - $old_state ))
	    else
		if [ "$latin" = yes ]; then
		    db_default console-setup/toggle 'No toggling'
		    db_default console-setup/switch 'No temporary switch'
		fi
		db_beginblock
		if [ "$latin" = no ]; then
		    db_get console-setup/toggle
		    if [ "$RET" = 'No toggling' ]; then
			db_reset console-setup/toggle
		    fi
		    db_input high console-setup/toggle || true
		    db_input medium console-setup/switch || true
		fi
		if [ ! -f $CONFIGFILE -a "$layout" = us ]; then
		    if [ "$variant" = '' ]; then
			# basic US keyboard doesn't use AltGr.
			db_default console-setup/altgr 'No AltGr key'
		    else
			db_default console-setup/altgr 'Right Alt'
		    fi
		fi
		db_input medium console-setup/altgr || true
		db_input medium console-setup/compose || true
		db_endblock

		if db_go; then 
		    STATE=$(($STATE + 1))
		else
		    STATE=$(($STATE - 1))
		fi

		db_get console-setup/toggle
		case "$RET" in
		    Caps\ Lock)
		        caps_allocated=yes
		        toggle=caps_toggle;;
		    Right\ Alt)
		        ralt_allocated=yes
		        toggle=toggle;;
		    Right\ Control)
		        rctrl_allocated=yes
		        toggle=rctrl_toggle;;
		    Right\ Shift)
		        rshift_allocated=yes
		        toggle=rshift_toggle;;
		    Right\ Logo?key)
		        rwin_allocated=yes
		        toggle=rwin_toggle;;
		    Menu?key)
			menu_allocated=yes
			toggle=menu_toggle;;
		    Alt+Shift)
			toggle=alt_shift_toggle;;
		    Control+Shift)
			toggle=ctrl_shift_toggle;;
		    Left\ Control+Left\ Shift)
			toggle=lctrl_lshift_toggle;;
		    Scroll\ Lock\ key)
			toggle=sclk_toggle;;
		    Alt+Caps\ Lock)
			toggle=alt_caps_toggle;;
		    Control+Alt)
			toggle=ctrl_alt_toggle;;
		    Left\ Alt)
		        lalt_allocated=yes
		        toggle=lalt_toggle;;
		    Left\ Control)
		        lctrl_allocated=yes
		        toggle=lctrl_toggle;;
		    Left\ Shift)
		        lshift_allocated=yes
		        toggle=lshift_toggle;;
		    Left\ Logo?key)
		        lwin_allocated=yes
		        toggle=lwin_toggle;;
		    No\ toggling)
		        toggle='';;
		    *)
			echo Unknown toggle key option
			exit 1
			;;
		esac
		if [ "$toggle" ]; then
		    toggle=grp:$toggle
		fi
		
		db_get console-setup/switch
		switch=''
		case "$RET" in
		    Right\ Alt)
		        if [ "$ralt_allocated" != yes ]; then
			    switch=switch
			    ralt_allocated=yes
		        fi;;
		    Left\ Alt)
		        if [ "$lalt_allocated" != yes ]; then
			    switch=lswitch
			    lalt_allocated=yes
		        fi;;
		    Right\ Logo?key)
		        if [ "$rwin_allocated" != yes ]; then
			    switch=rwin_switch
			    rwin_allocated=yes
		        fi;;
		    Left\ Logo?key)
		        if [ "$lwin_allocated" != yes ]; then
			    switch=lwin_switch
			    lwin_allocated=yes
		        fi;;
		    Both\ Logo?keys)
		        if \
			    [ "$rwin_allocated" != yes ] \
			    && [ "$lwin_allocated" != yes ]
			then
			    switch=win_switch
			    rwin_allocated=yes
			    lwin_allocated=yes
		        fi;;
		    No\ temporary\ switch)
		        switch='';;
		    *)
			echo Unknown switch key option
			exit 1
			;;
		esac
		if [ "$switch" ]; then
		    switch=grp:$switch
		fi
		
		db_get console-setup/altgr
		altgr=''
		case "$RET" in
		    No?AltGr?key)
			altgr='';;
		    Right?Alt)
			if [ "$ralt_allocated" != yes ]; then
			    altgr=ralt_switch
			    ralt_allocated=yes
			fi;;
		    Right?Control)
			if [ "$rctrl_allocated" != yes ]; then
			    altgr=switch
			    rctrl_allocated=yes
			fi;;
		    Menu?key)
			if [ "$menu_allocated" != yes ]; then
			    altgr=menu_switch
			    menu_allocated=yes
			fi;;
		    Keypad?Enter?key)
			altgr=enter_switch;;
		    Right?Logo?key)
			if [ "$rwin_allocated" != yes ]; then
			    altgr=rwin_switch
			    rwin_allocated=yes
			fi;;
		    Left?Logo?key)
			if [ "$lwin_allocated" != yes ]; then
			    altgr=lwin_switch
			    lwin_allocated=yes
			fi;;
		    Both?Logo?keys)
			if \
			    [ "$rwin_allocated" != yes ] \
			    && [ "$lwin_allocated" != yes ]
			then
			    altgr=win_switch
			    rwin_allocated=yes
			    lwin_allocated=yes
			fi;;
		    Both?Alt?keys)
			if \
			    [ "$lalt_allocated" != yes ] \
			    && [ "$ralt_allocated" != yes ]
			then
			    altgr=alt_switch
			    ralt_allocated=yes
			    lalt_allocated=yes
			fi;;
		    Left?Alt)
			if [ "$lalt_allocated" != yes ]; then
			    altgr=lalt_switch
			    lalt_allocated=yes
			fi;;
		    *)
			echo Unknown altgr key option
			exit 1
			;;
		esac
		if [ "$altgr" ]; then
		    altgr=lv3:$altgr
		fi

		db_get console-setup/compose
		compose=''
		case "$RET" in
		    No?compose?key)
			compose='';;
		    Right?Alt)
			if [ "$ralt_allocated" != yes ]; then
			    compose=ralt
			    ralt_allocated=yes
			fi;;
		    Right?Logo?key)
			if [ "$rwin_allocated" != yes ]; then
			    compose=rwin
			    rwin_allocated=yes
			fi;;
		    Left?Logo?key)
			if [ "$lwin_allocated" != yes ]; then
			    compose=lwin 
			    lwin_allocated=yes
			fi;;
		    Right?Control)
			if [ "$rctrl_allocated" != yes ]; then
			    compose=rctrl 
			    rctrl_allocated=yes
			fi;;
		    Menu?key)
			if [ "$menu_allocated" != yes ]; then
			    compose=menu
			    menu_allocated=yes
			fi;;
		    Caps?Lock)
			if [ "$caps_allocated" != yes ]; then
			    compose=caps
			    caps_allocated=yes
			fi;;
		    *)
			echo Unknown compose key option
			exit 1
			;;
		esac
		if [ "$compose" ]; then
		    compose=compose:$compose
		fi
		
		case "$real_layout" in
		    *,*)
		        leds=grp_led:scroll;;
		    *)
			leds='';;
		esac
		
		options=$(
		    echo $toggle $switch $altgr $compose $leds \
			| sed -e 's/^ *//' -e 's/ *$//' -e 's/  */,/g'
		)
		db_set console-setup/optionscode "$options"
	    fi
	    ;;		    
	9)
	    if [ "$package" = console-setup-mini ]; then
		if [ "$STATE" -ge "$old_state" ]; then
		    STATE=$(($STATE + 1))
		else
		    STATE=$(($STATE - 1))
		fi
		charmap=UTF-8
	    else
		# add commas
		choices=`echo "$charmaps" | sed -e 's/$/,/g' | LC_ALL=C sort `
		# remove newlines
		choices=`echo $choices | sed -e 's/,$//' `
		db_subst console-setup/charmap CHOICES "$choices"
		db_default console-setup/charmap "$default_charmap"
		db_input $charmap_priority console-setup/charmap || true
		if db_go; then
		    STATE=$(($STATE + 1))
		else
		    STATE=$(($STATE - 1))
		fi
		db_get console-setup/charmap
		charmap=$RET
	    fi
	    ;;
	10)
	    # It shouldn't be possible for $default_codeset to be
	    # empty, but just a precaution.
	    if [ "$default_codeset" ]; then
		db_default console-setup/codeset "$default_codeset"
	    fi
	    db_input $codeset_priority console-setup/codeset || true
	    if db_go; then
		db_get console-setup/codeset
		codeset="`encode_codeset $RET`"
		db_set console-setup/codesetcode "$codeset"
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    ;;
	11)
	    fontfaces=`available_fontfaces`
	    # add commas
	    choices=`echo "$fontfaces" | sed -e 's/$/,/g'`
	    # remove newlines
	    choices=`echo $choices | sed -e 's/,$//'`
	    db_subst console-setup/fontface CHOICES "$choices"
	    if [ -z "$default_fontface" ]; then
		case "$codeset" in
		    Arabic)
			default_fontface=VGA
			;;
		    Armenian)
			default_fontface=Fixed
			;;
		    CyrAsia)
			default_fontface=Fixed
			;;
		    CyrKoi)
			default_fontface=VGA
			;;
		    CyrSlav)
			default_fontface=Fixed
			;;
		    Ethiopian)
			default_fontface=Goha
			;;
		    Georgian)
			default_fontface=Fixed
			;;
		    Greek)
			default_fontface=Fixed
			;;
		    Hebrew)
			default_fontface=Fixed
			;;
		    Lao)
			default_fontface=Fixed
			;;
		    Lat15)
			default_fontface=VGA
			;;
		    Lat2)
			default_fontface=Fixed
			;;
		    Lat38)
			default_fontface=Fixed
			;;
		    Lat7)
			default_fontface=Fixed
			;;
		    Thai)
			default_fontface=Fixed
			;;
		    Uni1)
			default_fontface=VGA
			;;
		    Uni2)
			default_fontface=Fixed
			;;
		    Uni3)
			default_fontface=Fixed
			;;
		    Vietnamese)
			default_fontface=Fixed
			;;
		    *)
			default_fontface=Fixed
			;;
		esac
	    fi
	    db_default console-setup/fontface "$default_fontface"
	    db_input medium console-setup/fontface || true
	    if db_go; then
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    db_get console-setup/fontface
	    fontface=$RET
	    ;;
	12)
	    fontsizes=`available_fontsizes`
	    # add commas
	    choices=`echo "$fontsizes" | sed -e 's/$/,/g' `
	    # remove newlines
	    choices=`echo $choices | sed -e 's/,$//'`
	    if echo "$choices" | grep -q x; then
		size_template=console-setup/fontsize-fb
	    else
		size_template=console-setup/fontsize-text
	    fi
	    db_subst $size_template CHOICES "$choices"
	    db_input medium $size_template || true
	    if db_go; then
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    db_get $size_template
	    fontsize=$RET
	    db_set console-setup/fontsize "$fontsize"
	    ;;
	13)
	    db_input medium console-setup/ttys || true
	    if db_go; then
		STATE=$(($STATE + 1))
	    else
		STATE=$(($STATE - 1))
	    fi
	    db_get console-setup/ttys
	    ttys=$RET
	    ;;
	*)
	    break
	    ;;
    esac
    old_state=$starting_state
done

if [ $STATE -eq 0 ]; then
    exit 10
else
    # we don't do the following corrections during the state 2 or 3 of
    # the loop because if the user backs up and selects another layout
    # the keyboard model will be wrong.  We also want the combinations
    # Brasilian layout on Japanese keyboard and Japanese layout on
    # Brasilian keyboard to be possible.
    db_get console-setup/modelcode
    if [ "$RET" = "$default_model" ]; then
	if [ "$layout" = br ]; then 
	    db_set console-setup/modelcode abnt2
	elif [ "$layout" = jp ]; then 
	    db_set console-setup/modelcode jp106
	fi
    fi
fi
