[Pkg-kbd-devel] Bug#386836: console-setup: smooth upgrade from pre-console-setup systems

Colin Watson cjwatson at ubuntu.com
Sun Sep 10 15:08:07 UTC 2006


Package: console-setup
Version: 1.7
Severity: wishlist
Tags: patch

The attached patch implements a relatively smooth upgrade from
pre-console-setup systems. If X is installed, it extracts the desired
keyboard layout from xorg.conf; failing that, it uses a pretty horrible
lookup table borrowed from Ubuntu's xserver-xorg.config (which is a
superset of Debian's, I think), with the additional bug-fix of mapping
uk to plain gb rather than gb(intl) because UK users do not expect to
have dead keys. If it finds a keyboard layout using either of these
methods, it drops the priority of the layout and variant questions from
critical to medium.

I realise this patch is less than entirely elegant, but it makes
upgrades rather smoother, which I think will be useful if/when Debian
moves to console-setup by default. I'm using this in Ubuntu.

Thanks,

-- 
Colin Watson                                       [cjwatson at ubuntu.com]
-------------- next part --------------
--- console-setup-1.7.orig/debian/config.proto	2006-07-22 21:05:55.000000000 +0100
+++ console-setup-1.7/debian/config.proto	2006-09-10 12:05:27.000000000 +0100
@@ -64,6 +64,7 @@
 . /usr/share/debconf/confmodule
 
 CONFIGFILE=/etc/default/console-setup
+XORGCONFIGFILE=/etc/X11/xorg.conf
 
 ## FONTSETS ## Will be replaced by assignment for $fontsets:
 
@@ -645,7 +646,7 @@
 
 default_layout=''
 default_variant=''
-layout_priority=''
+layout_priority=critical
 case "$locale" in
     # Keyboards for countries
     *_AL*)
@@ -972,14 +973,97 @@
 ######################################################################
 
 # Load the config file, if it exists.
+got_x_config=no
+got_full_config=no
 if [ -e $CONFIGFILE ]; then
     . $CONFIGFILE || true
-    
+    got_x_config=yes
+    got_full_config=yes
+elif [ -e $XORGCONFIGFILE ]; then
+    XKBMODEL="$(sed -ne 's/^[[:space:]]\+Option[[:space:]]\+"XkbModel"[[:space:]]\+"\([^"]\+\)"/\1/ip' $XORGCONFIGFILE | head -n1)"
+    XKBLAYOUT="$(sed -ne 's/^[[:space:]]\+Option[[:space:]]\+"XkbLayout"[[:space:]]\+"\([^"]\+\)"/\1/ip' $XORGCONFIGFILE | head -n1)"
+    XKBVARIANT="$(sed -ne 's/^[[:space:]]\+Option[[:space:]]\+"XkbVariant"[[:space:]]\+"\([^"]\+\)"/\1/ip' $XORGCONFIGFILE | head -n1)"
+    XKBOPTIONS="$(sed -ne 's/^[[:space:]]\+Option[[:space:]]\+"XkbOptions"[[:space:]]\+"\([^"]\+\)"/\1/ip' $XORGCONFIGFILE | head -n1)"
+    got_x_config=yes
+    layout_priority=medium
+elif db_get debian-installer/keymap && [ "$RET" ]; then
+    # This is a desperation measure, but required for migration from
+    # pre-console-setup systems without X installed. We just have to copy
+    # the guesswork formerly done by xserver-xorg.config.
+    got_x_config=yes
+    layout_priority=medium
+
+    di_keymap="${RET##mac-usb-}"
+    di_keymap="${di_keymap%%-latin1}"
+
+    XKBMODEL="$default_model"
+    XKBLAYOUT=''
+    XKBVARIANT=''
+    XKBOPTIONS=''
+    case "$di_keymap" in
+	be2) XKBLAYOUT="be";;
+	bg) XKBLAYOUT="bg"; XKBVARIANT="bds";;
+	br) XKBLAYOUT="us"; XKBVARIANT="intl"; XKBMODEL="pc104";;
+	br-abnt2) XKBLAYOUT="br"; XKBVARIANT="abnt2"; XKBMODEL="abnt2";;
+	by) XKBLAYOUT="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="il";;
+	hu) XKBLAYOUT="hu";;
+	gb) XKBLAYOUT="gb";;
+	is) XKBLAYOUT="is";;
+	it) XKBLAYOUT="it";;
+	jp106) XKBLAYOUT="jp"; XKBVARIANT="jp106";;
+	la) XKBLAYOUT="latam";;
+	lt) XKBLAYOUT="lt";; 
+	lv-latin4) XKBLAYOUT="lv";;
+	# XXX should these be XKBMODEL="macintosh"?
+	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="mk";;
+	nl) XKBLAYOUT="nl";;
+	no) XKBLAYOUT="no";;
+	pl) XKBLAYOUT="pl";;
+	pt) XKBLAYOUT="pt";;
+	ro) XKBLAYOUT="ro";;
+	ru) XKBLAYOUT="ru";;
+	se) XKBLAYOUT="se";;
+	sg) XKBLAYOUT="ch"; XKBVARIANT="de";;
+	sk-qwerty) XKBLAYOUT="sk"; XKBVARIANT="qwerty";;
+	slovene) XKBLAYOUT="si";;
+	sr-cy) XKBLAYOUT="cs";;
+	trf|trfu) XKBLAYOUT="tr"; XKBVARIANT="f";;
+	trq|trqu) XKBLAYOUT="tr";;
+	ua) XKBLAYOUT="ua";;
+	uk) XKBLAYOUT="gb";;
+	us) XKBLAYOUT="us"; XKBMODEL="pc104";;
+	*) got_x_config=no; layout_priority=critical;;
+    esac
+fi
+
+if [ "$got_full_config" = yes ]; then
     default_ttys="$ACTIVE_CONSOLES"
     default_charmap="$CHARMAP"
     default_codeset="$CODESET"
     default_fontface="$FONTFACE"
     default_fontsize="$FONTSIZE"
+fi
+
+if [ "$got_x_config" = yes ]; then
     default_model="$XKBMODEL"
 
     case "$XKBLAYOUT" in
@@ -1078,9 +1172,11 @@
 		unsupported_layout=yes;;
 	esac
     done
+fi
 
-    # Store values from config file into debconf db.
+# Store values from config file into debconf db.
     
+if [ "$got_full_config" = yes ]; then
     db_set console-setup/ttys "$default_ttys"
     db_set console-setup/charmap "$default_charmap"
     db_set console-setup/codeset "$default_codeset"
@@ -1088,6 +1184,8 @@
     db_set console-setup/fontsize-text "$default_fontsize"
     db_set console-setup/fontsize-fb "$default_fontsize"
     db_set console-setup/fontsize "$default_fontsize"
+fi
+if [ "$got_x_config" = yes ]; then
     db_set console-setup/toggle "$default_toggle"
     db_set console-setup/switch "$default_switch"
     db_set console-setup/altgr "$default_altgr"
@@ -1123,7 +1275,7 @@
 		    STATE=$(($STATE - 1))
 		fi
 	    elif \
-		ask_debconf console-setup/layout critical \
+		ask_debconf console-setup/layout $layout_priority \
 		    layout "$default_layout"
 	    then
 		layout="$RET"
@@ -1138,7 +1290,7 @@
 		# skip the question without making Debconf loop
 		STATE=$(( $STATE + $STATE - $old_state ))
 	    elif \
-		ask_debconf console-setup/variant critical \
+		ask_debconf console-setup/variant $layout_priority \
                     "variant\*${layout}" "$default_variant"
 	    then
 		variant="$RET"


More information about the Pkg-kbd-devel mailing list