summaryrefslogtreecommitdiffstats
path: root/bootloader/make-kbd-info
diff options
context:
space:
mode:
Diffstat (limited to 'bootloader/make-kbd-info')
-rwxr-xr-xbootloader/make-kbd-info115
1 files changed, 115 insertions, 0 deletions
diff --git a/bootloader/make-kbd-info b/bootloader/make-kbd-info
new file mode 100755
index 0000000..d36fde8
--- /dev/null
+++ b/bootloader/make-kbd-info
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+
+# Copyright (C) 2017 Mageia
+#
+# 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, 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# SYNOPSIS
+#
+# This program gets the list of supported keyboards from libDrakX and
+# generates a grub2 keyboard mapping file for each keyboard in the list.
+# It then generates the keyboard names file and the language to keyboard
+# mapping file that are used when generating the bootloader menus for
+# the Mageia ISOs.
+#
+# The grub2 keyboard mapping files are generated using the grub2-kbdcomp
+# program. The X11 keyboard layout and variant names are obtained from
+# libDrakX. The files (*.gkb) are stored in the 'layouts' subdirectory
+# of the current working directory.
+#
+# The keyboard names file consists of a list of paired identifier and
+# description strings. The identifier is the keyboard identifier used
+# in libDrakX. The description is the canonical keyboard description
+# provided by libDrakX. The file (kbd-names.txt) is stored in the
+# current working directory.
+#
+# The language to keyboard mapping file consists of a map of language
+# identifier to keyboard identifier strings. The language identifier
+# is the standard language/country code used for specifying a locale
+# (e.g. en_US). The keyboard identifier is the default keyboard for
+# that language, as provided by libDrakX. The file (lang-kbds.txt) is
+# stored in the current working directory.
+#
+# The list of supported languages is read from the language names file
+# (lang-names.txt) that is used when generating the bootloader menus.
+# This file is expected to be found in the current working directory.
+
+use lib qw(/usr/lib/libDrakX);
+
+use strict;
+
+use Cwd qw(getcwd);
+use Data::Dumper;
+use MDK::Common;
+use common;
+use keyboard;
+use run_program;
+
+# Make sure we get the canonical description for the keyboard.
+$ENV{LANGUAGE} = 'C';
+
+# Make sure the 'layouts' subdirectory exists.
+my $kbd_dir = getcwd() . '/layouts';
+mkdir_p($kbd_dir);
+
+# Generate the grub2 keyboard mapping files and collect the keyboard
+# descriptions. For keyboards with multiple layouts, only use the first
+# layout. If we fail to generate a keyboard mapping, don't include that
+# keyboard in the lists.
+my %names;
+my @keyboards = map { { KEYBOARD => $_ } } keyboard::KEYBOARDs();
+foreach (@keyboards) {
+ my $id = $_->{KEYBOARD};
+ my $xkb = keyboard::keyboard2full_xkb($_);
+ my @model = split(',', $xkb->{XkbModel});
+ my @layout = split(',', $xkb->{XkbLayout});
+ my @variant = split(',', $xkb->{XkbVariant});
+ my $kbd_file = $kbd_dir . '/' . $id . '.gkb';
+ if (-e $kbd_file || run_program::run('grub2-kbdcomp', '-o', $kbd_file, '-model', $model[0], $layout[0], $variant[0])) {
+ $names{$id} = translate(keyboard::keyboard2text($_));
+ } else {
+ rm_rf($kbd_file);
+ }
+}
+
+# Generate the keyboard names file.
+my $filename = getcwd() . '/kbd-names.txt';
+open(my $f, '>' . $filename) or die "couldn't open $filename";
+print $f "(\n";
+foreach my $id (sort keys %names) {
+ my $name = $names{$id};
+ printf $f " '$id'%s => '$name',\n", ' ' x (16 - length($id));
+}
+print $f ")\n";
+close($f);
+
+# Read the list of supported languages.
+my $lang_names = getcwd() . '/lang-names.txt';
+-e $lang_names or die "cannot find language names file $lang_names\n";
+my @langs = group_by2(eval(cat_($lang_names)))
+ or die "error in language names file $lang_names\n";
+
+# Generate the language to keyboard mapping file.
+$filename = getcwd() . '/lang-kbds.txt';
+open($f, '>' . $filename) or die "couldn't open $filename";
+print $f "{\n";
+foreach (@langs) {
+ my ($lang) = @$_;
+ my $kbd = keyboard::lang2keyboard($lang)->{KEYBOARD};
+ $kbd = '' if !$names{$kbd};
+ printf $f " '$lang' => '$kbd',\n";
+}
+print $f "}\n";
+close($f);