diff options
author | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2017-12-01 13:48:03 +0000 |
---|---|---|
committer | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2017-12-01 13:48:03 +0000 |
commit | 32ddfa110613b099099ec72e835c02e5dc5e775c (patch) | |
tree | 2ad6dd089878d0c535c1db4d7a201a3343f495bb /draklive2 | |
parent | 86ab49fcdbfe8a9a8a02f37c286cd90c8693c2bb (diff) | |
download | drakiso-32ddfa110613b099099ec72e835c02e5dc5e775c.tar drakiso-32ddfa110613b099099ec72e835c02e5dc5e775c.tar.gz drakiso-32ddfa110613b099099ec72e835c02e5dc5e775c.tar.bz2 drakiso-32ddfa110613b099099ec72e835c02e5dc5e775c.tar.xz drakiso-32ddfa110613b099099ec72e835c02e5dc5e775c.zip |
draklive2: support language selection in the boot menu.
Diffstat (limited to 'draklive2')
-rwxr-xr-x | draklive2 | 63 |
1 files changed, 56 insertions, 7 deletions
@@ -463,6 +463,21 @@ sub create_bootloader { @theme_fonts = map { basename($_) } glob("$theme/*.pf2"); } + my $add_lang_menu = defined $live->{media}{bootloader_langs}; + if ($add_lang_menu) { + my $lang_names = get_absolute_path($live, $live->{media}{bootloader_langs}); + -e $lang_names or die "cannot find language name file $lang_names\n"; + my @langs = eval(cat_($lang_names)) or die "error in language name file $lang_names\n"; + MDK::Common::File::output_utf8($grub2_dir . '/lang-menu.cfg', build_lang_menu_cfg(@langs)); + + my $locale_dir = $grub2_dir . '/locale'; + mkdir_p($locale_dir); + + my $messages = get_absolute_path($live, $live->{media}{bootloader_messages}); + -d $messages or die "cannot find translated messages directory $messages\n"; + cp_f(glob($messages . '/*.mo'), $locale_dir); + } + my $eltorito_img = get_absolute_path($live, $live->{media}{eltorito_img}); if (defined $eltorito_img) { -e $eltorito_img or die "cannot find grub2 Eltorito boot image $eltorito_img\n"; @@ -478,7 +493,7 @@ sub create_bootloader { cp_f($live->{settings}{config_root} . '/' . $live->{media}{grub2_cfg}, $grub2_cfg); run_("sed", "-i", "s/VOLUME_LABEL/$label/g", $grub2_cfg); } else { - output($grub2_cfg, build_grub2_cfg($live, $theme_name, \@theme_fonts)); + output($grub2_cfg, build_grub2_cfg($live, $theme_name, \@theme_fonts, $add_lang_menu)); } my $title = $label; @@ -526,8 +541,8 @@ sub build_grub2_eltorito_img { # temporary hack to workaround grub2/grub2-efi conflict run_({ root => $live->get_system_root }, 'urpmi', '-q', '--force', 'grub2'); - my @modules = qw(biosdisk iso9660 fat part_msdos all_video font png gfxterm gfxmenu linux configfile - echo ls search test); + my @modules = qw(biosdisk iso9660 fat part_msdos all_video font png gfxterm gfxmenu linux + configfile echo gettext ls search test); my $output = '/boot/grub2/eltorito.img'; run_({ root => $live->get_system_root }, 'grub2-mkimage', @@ -549,8 +564,8 @@ sub build_grub2_bootx64_efi { # temporary hack to workaround grub2/grub2-efi conflict run_({ root => $live->get_system_root }, 'urpmi', '-q', '--force', 'grub2-efi'); - my @modules = qw(iso9660 fat part_msdos all_video font png gfxterm gfxmenu linux configfile - echo ls search test); + my @modules = qw(iso9660 fat part_msdos all_video font png gfxterm gfxmenu linux + configfile echo gettext ls search test); my $output = '/boot/grub2/bootx64.efi'; run_({ root => $live->get_system_root }, 'grub2-mkimage', @@ -567,13 +582,17 @@ sub build_grub2_bootx64_efi { } sub build_grub2_cfg { - my ($live, $theme_name, $theme_fonts) = @_; + my ($live, $theme_name, $theme_fonts, $add_lang_menu) = @_; my @loadfonts; if (defined $theme_name) { @loadfonts = map { "loadfont \${prefix}/themes/$theme_name/$_" } @$theme_fonts; } + my @langs = get_langs($live); + my $default_lang = $langs[0] || 'en_US'; + my $gettext = $add_lang_menu ? '$' : ''; + my $boot_dir = $live->get_media_prefix('boot'); join("\n", @@ -599,10 +618,21 @@ sub build_grub2_cfg { "set timeout=" . get_bootloader_timeout($live), "set default=" . get_bootloader_default($live), "", + if_($add_lang_menu, + "if [ -z \$lang ] ; then", + " set lang=$default_lang", + "fi", + "export lang", + "", + "submenu $gettext\"Language [\$lang]\" {", + " source \$prefix/lang-menu.cfg", + "}", + "", + ), (map { my ($name, $cmdline) = @$_; join("\n", - "menuentry '$name' {", + "menuentry $gettext\"$name\" {", " linux $boot_dir/vmlinuz " . get_default_append($live) . if_($cmdline, " $cmdline"), " initrd $boot_dir/initrd.gz", "}" @@ -633,6 +663,25 @@ sub get_default_append { ); } +sub build_lang_menu_cfg { + my ($langs) = @_; + join("\n", + "function set_language {", + " set lang=\$1", + " configfile \$prefix/grub.cfg", + "}", + "", + "set default=\$lang", + "set timeout=-1", + "", + (map { + my ($id, $name) = @$_; + "menuentry '$name' --id $id { set_language $id }"; + } group_by2(@$langs)), + "", + ); +} + sub build_uefi_grub2_cfg { my ($live) = @_; join("\n", |