package Xconfig::xfreeX; # $Id$ use diagnostics; use strict; use Xconfig::parse; use common; use log; sub empty_config { my ($class) = @_; my $raw_X = Xconfig::parse::read_XF86Config_from_string(our $default_header); bless $raw_X, $class; } sub read { my ($class, $file) = @_; $file ||= ($::prefix || '') . (bless {}, $class)->config_file; my $raw_X = Xconfig::parse::read_XF86Config($file); bless $raw_X, $class; } sub write { my ($raw_X, $file) = @_; $file ||= ($::prefix || '') . $raw_X->config_file; rename $file, "$file.old"; Xconfig::parse::write_XF86Config($raw_X, $file); } my @monitor_fields = qw(VendorName ModelName HorizSync VertRefresh); sub get_monitors { my ($raw_X) = @_; my @raw_monitors = $raw_X->get_monitor_sections; map { raw_export_section($_, [ 'Identifier', @monitor_fields ]) } @raw_monitors; } sub set_monitors { my ($raw_X, @monitors) = @_; my @raw_monitors = $raw_X->new_monitor_sections(int @monitors); mapn { my ($raw_monitor, $monitor) = @_; raw_import_section($raw_monitor, $monitor, \@monitor_fields); } \@raw_monitors, \@monitors; } sub get_monitor { my ($raw_X) = @_; my @l = $raw_X->get_monitors; if (!@l) { $raw_X->new_monitor_sections(1); @l = $raw_X->get_monitors; } $l[0] } my @keyboard_fields = qw(XkbLayout XkbModel XkbDisable XkbOptions XkbCompat); sub get_keyboard { my ($raw_X) = @_; my $raw_kbd = $raw_X->get_keyboard_section; raw_export_section($raw_kbd, \@keyboard_fields); } sub set_keyboard { my ($raw_X, $kbd) = @_; my $raw_kbd = eval { $raw_X->get_keyboard_section } || $raw_X->new_keyboard_section; raw_import_section($raw_kbd, $kbd); $raw_X->set_Option('keyboard', $raw_kbd, keys %$kbd); } #- example: { Protocol => 'IMPS/2', Device => '/dev/psaux', Emulate3Buttons => undef, Emulate3Timeout => 50, ZAxisMapping => [ '4 5', '6 7' ] } my @mouse_fields = qw(Protocol Device ZAxisMapping Emulate3Buttons Emulate3Timeout); #-); sub get_mice { my ($raw_X) = @_; my @raw_mice = $raw_X->get_mouse_sections; map { raw_export_section($_, \@mouse_fields) } @raw_mice; } sub set_mice { my ($raw_X, @mice) = @_; my @raw_mice = $raw_X->new_mouse_sections(int @mice); mapn { my ($raw_mouse, $mouse) = @_; raw_import_section($raw_mouse, $mouse); $raw_X->set_Option('mouse', $raw_mouse, keys %$mouse); } \@raw_mice, \@mice; } sub get_devices { my ($raw_X) = @_; my @raw_devices = $raw_X->get_device_sections; map { my $raw_device = $_; my $device = raw_export_section($raw_device, [ 'Identifier', $raw_X->get_device_section_fields ]); $device->{Options} = raw_export_section($raw_device, [ grep { (deref_array($raw_device->{$_}))[0]->{Option} } keys %$raw_device ]); $device; } @raw_devices; } sub set_devices { my ($raw_X, @devices) = @_; my @raw_devices = $raw_X->new_device_sections(int @devices); mapn { my ($raw_device, $device) = @_; my %Options = %{$device->{Options} || {}}; add2hash(\%Options, $device->{'Options_' . $raw_X->name}); raw_import_section($raw_device, $device, [ $raw_X->get_device_section_fields ]); raw_import_section($raw_device, \%Options); $_->{Option} = 1 foreach map { deref_array($raw_device->{$_}) } keys %Options; $raw_device->{''} = [ { post_comment => $device->{raw_LINES} } ] if $device->{raw_LINES}; } \@raw_devices, \@devices; } sub get_device { my ($raw_X) = @_; first(get_devices($raw_X)); } sub get_screens { my ($raw_X) = @_; $raw_X->get_Sections('Screen'); } sub get_default_screen { my ($raw_X) = @_; my @l = get_screens($raw_X); (find { $_->{Identifier} && val($_->{Identifier}) eq 'screen1' || $_->{Driver} && val($_->{Driver}) =~ /svga|accel/ } @l) || $l[0]; } sub set_screens { my ($raw_X, @screens) = @_; my @raw_screens = $raw_X->new_screen_sections(int @screens); mapn { my ($raw_screen, $screen) = @_; raw_import_section($raw_screen, $screen); } \@raw_screens, \@screens; } sub get_modules { my ($raw_X) = @_; my $raw_Module = $raw_X->get_Section('Module') or return; my $Module = raw_export_section($raw_Module, ['Load']); @{$Module->{Load} || []}; } sub add_load_module { my ($raw_X, $module) = @_; my $raw_Module = $raw_X->get_Section('Module') || $raw_X->new_module_section; my %load_modules_comment = ( dbe => 'Double-Buffering Extension', v4l => 'Video for Linux', dri => 'direct rendering', glx => '3D layer', 'glx-3.so' => '3D layer', ); my $comment = $load_modules_comment{$module}; push @{$raw_Module->{Load}}, { val => $module, comment_on_line => $comment && " # $comment", } if !member($module, $raw_X->get_modules); } sub remove_load_module { my ($raw_X, $module) = @_; my $raw_Module = $raw_X->get_Section('Module') or return; if (my @l = grep { $_->{val} ne $module } @{$raw_Module->{Load}}) { $raw_Module->{Load} = \@l; } else { $raw_X->remove_Section('Module'); } } sub set_load_module { my ($raw_X, $module, $bool) = @_; $bool ? add_load_module($raw_X, $module) : remove_load_module($raw_X, $module); } sub get_resolution { my ($raw_X, $Screen) = @_; $Screen ||= $raw_X->get_default_screen or return {}; my $depth = val($Screen->{DefaultColorDepth}); my $Display = find { !$depth || val($_->{l}{Depth}) eq $depth } @{$Screen->{Display} || []} or return {}; val($Display->{l}{Modes}) =~ /(\d+)x(\d+)/ or return {}; { X => $1, Y => $2, Depth => val($Display->{l}{Depth}) }; } sub set_resolution { my ($raw_X, $resolution, $Screen_) = @_; foreach my $Screen ($Screen_ ? $Screen_ : $raw_X->get_screens) { $Screen ||= $raw_X->get_default_screen or internal_error('no screen'); $Screen->{DefaultColorDepth} = { val => $resolution->{Depth} }; $Screen->{Display} = [ map { my $modes = do { if ($resolution->{fbdev}) { '"default"'; } else { my @Modes = grep { m/(\d+)x(\d+)/; $1 <= $resolution->{X} && (!$resolution->{Y} || $2 <= $resolution->{Y}); } reverse our @resolutions; join(" ", map { qq("$_") } @Modes); } }; { l => { Depth => { val => $_ }, Modes => { val => $modes } } }; } $raw_X->depths ]; } } #-############################################################################## #- common to xfree3 and xfree4 #-############################################################################## sub default_ModeLine { our $default_ModeLine } sub get_device_sections { my ($raw_X) = @_; $raw_X->get_Sections('Device'); } sub new_device_sections { my ($raw_X, $nb_new) = @_; $raw_X->remove_Section('Device'); map { $raw_X->add_Section('Device', { Identifier => { val => "device$_" } }) } (1 .. $nb_new); } sub get_monitor_sections { my ($raw_X) = @_; $raw_X->get_Sections('Monitor'); } sub new_monitor_sections { my ($raw_X, $nb_new) = @_; my $ModeLine = ModeLine_from_string(qq(Section "Monitor"\n) . $raw_X->default_ModeLine . qq(EndSection\n)); $raw_X->remove_Section('Monitor'); map { $raw_X->add_Section('Monitor', { Identifier => { val => "monitor$_" }, ModeLine => $ModeLine }) } (1 .. $nb_new); } sub new_screen_sections { my ($raw_X, $nb_new) = @_; $raw_X->remove_Section('Screen'); map { $raw_X->add_Section('Screen', {}) } (1 .. $nb_new); } sub new_module_section { my ($raw_X) = @_; return $raw_X->add_Section('Module', {}); } #-############################################################################## #- helpers #-############################################################################## sub raw_export_section { my ($section, $fields) = @_; my $export_name = sub { my ($name) = @_; my $h = $section->{$name} or return; my @l = map { if_(!$_->{commented}, $_->{val}) } deref_array($h) or return; $name => (ref($h) eq 'ARRAY' ? \@l : $l[0]); }; my %h = map { $export_name->($_) } @$fields; \%h; } sub raw_import_section { my ($section, $h, $fields) = @_; foreach ($fields ? grep { exists $h->{$_} } @$fields : keys %$h) { my @l = map { ref($_) eq 'HASH' ? $_ : { val => $_ } } deref_array($h->{$_}); $section->{$_} = (ref($h->{$_}) eq 'ARRAY' ? \@l : $l[0]); } } sub add_Section { my ($raw_X, $Section, $h) = @_; my @suggested_ordering = qw(Files ServerFlags Module DRI Keyboard Pointer XInput InputDevice Monitor Device Screen ServerLayout); my %order = map_index { { lc($_) => $::i } } @suggested_ordering; my $e = { name => $Section, l => $h }; my $added; @$raw_X = map { if ($order{lc $_->{name}} > $order{lc $Section} && !$added) { $added = 1; ($e, $_); } else { $_ } } @$raw_X; push @$raw_X, $e if !$added; $h; } sub remove_Section { my ($raw_X, $Section, $when) = @_; @$raw_X = grep { $_->{name} ne $Section || $when && $when->($_->{l}) } @$raw_X; $raw_X; } sub get_Sections { my ($raw_X, $Section, $when) = @_; map { if_($_->{name} eq $Section && (!$when || $when->($_->{l})), $_->{l}) } @$raw_X; } sub get_Section { my ($raw_X, $Section, $when) = @_; my @l = get_Sections($raw_X, $Section, $when); @l > 1 and log::l("Xconfig: found more than one Section $Section"); $l[0]; } sub get_Section_by_Identifier { my ($raw_X, $Section, $Identifier) = @_; my @l = get_Sections($raw_X, $Section, sub { val($_[0]{Identifier}) eq $Identifier }); @l > 1 and die "more than one Section $Section has Identifier $Identifier"; $l[0]; } sub val { my ($ref) = @_; $ref && $ref->{val}; } sub ModeLine_from_string { my ($s) = @_; my $raw_X_for_ModeLine = Xconfig::parse::read_XF86Config_from_string($s); get_Section($raw_X_for_ModeLine, 'Monitor')->{ModeLine}; } our @resolutions = ('640x480', '800x600', '1024x768', if_(arch() =~ /ppc/, '1152x768'), '1152x864', '1280x960', '1280x1024', '1400x1050', '1600x1200', '1920x1440', '2048x1536'); our $default_header = <<'END'; # File generated by XFdrake. # ********************************************************************** # Refer to the XF86Config man page for details about the format of # this file. # ********************************************************************** Section "Files" # Multiple FontPath entries are allowed (they are concatenated together) # By default, Mandrake 6.0 and later now use a font server independent of # the X server to render fonts. FontPath "unix/:-1" EndSection Section "ServerFlags" #DontZap # disable (server abort) #DontZoom # disable / (resolution switching) AllowMouseOpenFail # allows the server to start up even if the mouse doesn't work EndSection END our $default_ModeLine = arch() =~ /ppc/ ? <<'END_PPC' : <<'END'; # Apple iMac modes ModeLine "1024x768" 78.525 1024 1049 1145 1312 768 769 772 800 +hsync +vsync ModeLine "800x600" 62.357 800 821 901 1040 600 601 604 632 +hsync +vsync ModeLine "640x480" 49.886 640 661 725 832 480 481 484 514 +hsync +vsync # Apple monitors tend to do 832x624 ModeLine "832x624" 57 832 876 940 1152 624 625 628 667 -hsync -vsync # Apple PowerBook G3 ModeLine "800x600" 100 800 816 824 840 600 616 624 640 -hsync -vsync # Apple TI Powerbook ModeLine "1152x768" 78.741 1152 1173 1269 1440 768 769 772 800 +vsync +vsync # Pismo Firewire G3 ModeLine "1024x768" 65 1024 1032 1176 1344 768 771 777 806 -hsync -vsync # iBook2 ModeLine "1024x768" 65 1024 1048 1184 1344 768 771 777 806 -hsync -vsync # 17" Apple Studio Display ModeLine "1024x768" 112.62 1024 1076 1248 1420 768 768 780 808 +hsync +vsync # HiRes Apple Studio Display ModeLine "1280x1024" 135 1280 1288 1392 1664 1024 1027 1030 1064 # Another variation ModeLine "1280x1024" 134.989 1280 1317 1429 1688 1024 1025 1028 1066 +hsync +vsync END_PPC # Sony Vaio C1(X,XS,VE,VN)? # 1024x480 @ 85.6 Hz, 48 kHz hsync ModeLine "1024x480" 65.00 1024 1032 1176 1344 480 488 494 563 -hsync -vsync # TV fullscreen mode or DVD fullscreen output. # 768x576 @ 79 Hz, 50 kHz hsync ModeLine "768x576" 50.00 768 832 846 1000 576 590 595 630 # 768x576 @ 100 Hz, 61.6 kHz hsync ModeLine "768x576" 63.07 768 800 960 1024 576 578 590 616 END 1; id='n192' href='#n192'>192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
package any; # $Id$

use diagnostics;
use strict;

#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use detect_devices;
use partition_table qw(:types);
use fsedit;
use fs;
use lang;
use run_program;
use keyboard;
use devices;
use modules;
use log;
use c;

sub drakx_version() { 
    sprintf "DrakX v%s built %s", $::testing ? ('TEST', scalar gmtime()) : (split('/', cat_("$ENV{SHARE_PATH}/VERSION")))[2,3];
}

sub facesdir {
    my ($prefix) = @_;
    "$prefix/usr/share/mdk/faces/";
}
sub face2png {
    my ($face, $prefix) = @_;
    facesdir($prefix) . $face . ".png";
}
sub facesnames {
    my ($prefix) = @_;
    my $dir = facesdir($prefix);
    my @l = grep { /^[A-Z]/ } all($dir);
    map { if_(/(.*)\.png/, $1) } (@l ? @l : all($dir));
}

sub addKdmIcon {
    my ($prefix, $user, $icon) = @_;
    my $dest = "$prefix/usr/share/faces/$user.png";
    eval { cp_af(facesdir($prefix) . $icon . ".png", $dest) } if $icon;
}

sub allocUsers {
    my ($prefix, $users) = @_;
    my @m = my @l = facesnames($prefix);
    foreach (grep { !$_->{icon} || $_->{icon} eq "automagic" } @$users) {
	$_->{auto_icon} = splice(@m, rand(@m), 1); #- known biased (see cookbook for better)
	log::l("auto_icon is $_->{auto_icon}");
	@m = @l unless @m;
    }
}

sub addUsers {
    my ($prefix, $users) = @_;

    allocUsers($prefix, $users);
    foreach my $u (@$users) {
	run_program::rooted($prefix, "usermod", "-G", join(",", @{$u->{groups}}), $u->{name}) if !is_empty_array_ref($u->{groups});
	addKdmIcon($prefix, $u->{name}, delete $u->{auto_icon} || $u->{icon});
    }
}

sub crypt {
    my ($password, $md5) = @_;
    crypt($password, $md5 ? '$1$' . salt(8) : salt(2));
}
sub enableShadow {
    my ($prefix) = @_;
    run_program::rooted($prefix, "pwconv")  or log::l("pwconv failed");
    run_program::rooted($prefix, "grpconv") or log::l("grpconv failed");
}

sub hdInstallPath() {
    my $tail = first(readlink("/tmp/image") =~ m|^/tmp/hdimage/(.*)|);
    my $head = first(readlink("/tmp/hdimage") =~ m|$::prefix(.*)|);
    $tail && ($head ? "$head/$tail" : "/mnt/hd/$tail");
}

sub kernelVersion() {
    my $kernel = readlink("$::prefix/boot/vmlinuz") || first(all("$::prefix/boot"));
    first($kernel =~ /vmlinuz-(.*)/);
}

sub mkbootdisk {
    my ($in, $bootloader, $fstab) = @_;

    if (arch() =~ /sparc/) {
	#- as probing floppies is a bit more different on sparc, assume always /dev/fd0.
	#- [pixel] uh, but in that case it would be better to change detect_devices::floppies, no?
	$in->ask_okcancel('',
			 N("A custom bootdisk provides a way of booting into your Linux system without
depending on the normal bootloader. This is useful if you don't want to install
SILO on your system, or another operating system removes SILO, or SILO doesn't
work with your hardware configuration. A custom bootdisk can also be used with
the Mandrake rescue image, making it much easier to recover from severe system
failures.

If you want to create a bootdisk for your system, insert a floppy in the first
drive and press \"Ok\".")) or return;
    } else {
	$in->ask_yesorno('', formatAlaTeX(
			    N("A custom bootdisk provides a way of booting into your Linux system without
depending on the normal bootloader. This is useful if you don't want to install
LILO (or grub) on your system, or another operating system removes LILO, or LILO doesn't
work with your hardware configuration. A custom bootdisk can also be used with
the Mandrake rescue image, making it much easier to recover from severe system
failures. Would you like to create a bootdisk for your system?
%s", isThisFs('xfs', fsedit::get_root($fstab)) ? N("

(WARNING! You're using XFS for your root partition,
creating a bootdisk on a 1.44 Mb floppy will probably fail,
because XFS needs a very large driver).") : ''))) or return;
    }

    my $floppy_dev;
    my @l = detect_devices::floppies_dev() or die \N("Sorry, no floppy drive available");
    my %l = (
	     'fd0'  => N("First floppy drive"),
	     'fd1'  => N("Second floppy drive"),
	     'Skip' => N("Skip"),
	    );
    my $format = sub { $l{$_[0]} || $_[0] };

    $in->ask_from_({
	       messages => N("Choose the floppy drive you want to use to make the bootdisk"),
	      }, [ { val => \$floppy_dev, list => \@l, format => $format } ]
        ) or return;

    $in->ask_warn('', N("Insert a floppy in %s", $format->($floppy_dev)));

    my $_w = $in->wait_message('', N("Creating bootdisk..."));

    require bootloader;
    bootloader::mkbootdisk(kernelVersion(), $floppy_dev, $bootloader->{perImageAppend});
    1;
}

sub setupBootloader {
    my ($in, $b, $all_hds, $fstab, $security) = @_;
    my $hds = $all_hds->{hds};

    require bootloader;
  general:
    setupBootloader__general($in, $b, $all_hds, $fstab, $security) or return 0;
    setupBootloader__boot_bios_drive($in, $b, $hds) or goto general;

    setupBootloader__entries($in, $b, $all_hds, $fstab) or goto general;

    #- somewhere should bootloader really installed ?
    bootloader::install($b, $fstab, $hds);
}


sub setupBootloader_simple {
    my ($in, $b, $all_hds, $fstab, $security) = @_;
    my $hds = $all_hds->{hds};

    require bootloader;
    my $mixed_kind_of_disks = bootloader::mixed_kind_of_disks($hds);
    #- full expert questions when there is 2 kind of disks
    #- it would need a semi_auto asking on which drive the bios boots...

    $mixed_kind_of_disks || $b->{bootUnsafe} || arch() =~ /ppc/ or return 1; #- default is good enough
    
    if (!$mixed_kind_of_disks && arch() !~ /ia64/) {
	setupBootloader__mbr_or_not($in, $b, $hds, $fstab) or return 0;
    } else {
      general:
	setupBootloader__general($in, $b, $all_hds, $fstab, $security) or return 0;
    }
    setupBootloader__boot_bios_drive($in, $b, $hds) or goto general;
    1;
}


sub setupBootloader__boot_bios_drive {
    my ($in, $b, $hds) = @_;

    bootloader::mixed_kind_of_disks($hds) && 
      $b->{boot} =~ /\d$/ && #- on a partition
	is_empty_hash_ref($b->{bios}) && #- some bios mapping already there
	  arch() !~ /ppc/ or return 1;

    log::l("mixed_kind_of_disks");
    my $hd = $in->ask_from_listf('', N("You decided to install the bootloader on a partition.
This implies you already have a bootloader on the hard drive you boot (eg: System Commander).

On which drive are you booting?"), \&partition_table::description, $hds) or return 0;
    log::l("mixed_kind_of_disks chosen $hd->{device}");
    $b->{first_hd_device} = "/dev/$hd->{device}";
    1;
}

sub setupBootloader__mbr_or_not {
    my ($in, $b, $hds, $fstab) = @_;

    if (arch() =~ /ppc/) {
	if (defined $partition_table::mac::bootstrap_part) {
	    $b->{boot} = $partition_table::mac::bootstrap_part;
	    log::l("set bootstrap to $b->{boot}"); 
	} else {
	    die "no bootstrap partition - yaboot.conf creation failed";
	}
    } else {
	my $floppy = detect_devices::floppy();

	my @l = (
		 [ N("First sector of drive (MBR)") => '/dev/' . $hds->[0]{device} ],
		 [ N("First sector of the root partition") => '/dev/' . fsedit::get_root($fstab, 'boot')->{device} ],
		     if_($floppy, 
                 [ N("On Floppy") => "/dev/$floppy" ],
		     ),
		 [ N("Skip") => '' ],
		);

	my $default = arch() =~ /sparc/ ? ($b->{use_partition} ? $l[1] : $l[0]) : 
	                                  find { $_->[1] eq $b->{boot} } @l;
	$in->ask_from_({ title => arch() =~ /sparc/ ? N("SILO Installation") : N("LILO/grub Installation"),
			 messages => N("Where do you want to install the bootloader?"),
			 interactive_help_id => 'setupBootloaderBeginner',
		       },
		      [ { val => \$default, list => \@l, format => sub { $_[0][0] }, type => 'list' } ]);
	my $new_boot = $default->[1] or return;

	if (arch() =~ /sparc/) {
	    $b->{use_partition} = $new_boot eq $l[1][1];
	}  else {
	    #- remove bios mapping if the user changed the boot device
	    delete $b->{bios} if $new_boot ne $b->{boot};

	    $b->{boot} = $new_boot;
	}
    }
    1;
}

sub setupBootloader__general {
    my ($in, $b, $all_hds, $fstab, $security) = @_;

    my @silo_install_lang = (N("First sector of drive (MBR)"), N("First sector of boot partition"));

    ($b->{method}, my $method_choices) = bootloader::method_choices($fstab, $b);
    my $profiles = bootloader::has_profiles($b);
    my $prev_force_acpi = my $force_acpi = bootloader::get_append($b, 'acpi') ne 'off';
    my $prev_force_noapic = my $force_noapic = bootloader::get_append($b, 'noapic');
    my $memsize = bootloader::get_append($b, 'mem');
    my $prev_clean_tmp = my $clean_tmp = any { $_->{mntpoint} eq '/tmp' } @{$all_hds->{special} ||= []};
    my $prev_boot = $b->{boot};
    my $mkbootdisk;

    $b->{password2} ||= $b->{password} ||= '';
    $b->{vga} ||= 'normal';
    if (arch() !~ /ppc/) {
	$in->ask_from_({ messages => N("Bootloader main options"),
			 interactive_help_id => 'setupBootloader',
		       }, [
            { label => N("Bootloader to use"), val => \$b->{method}, list => [ keys %$method_choices ], format => sub { $method_choices->{$_[0]} } },
                arch() =~ /sparc/ ? (
            { label => N("Bootloader installation"), val => \$b->{use_partition}, list => [ 0, 1 ], format => sub { $silo_install_lang[$_[0]] } },
		) : if_(arch() !~ /ia64/,
            { label => N("Boot device"), val => \$b->{boot}, list => [ map { "/dev/$_" } (map { $_->{device} } (@{$all_hds->{hds}}, grep { !isFat_or_NTFS($_) } @$fstab)), detect_devices::floppies_dev() ], not_edit => !$::expert },
            { label => N("Compact"), val => \$b->{compact}, type => "bool", text => N("compact"), advanced => 1 },
            { label => N("Video mode"), val => \$b->{vga}, list => [ keys %bootloader::vga_modes ], not_edit => !$::expert, format => sub { $bootloader::vga_modes{$_[0]} }, advanced => 1 },
		),
            { label => N("Delay before booting default image"), val => \$b->{timeout} },
            { label => N("Enable ACPI"), val => \$force_acpi, type => 'bool' },
            { label => N("Force No APIC"), val => \$force_noapic, type => 'bool' },
		if_($security >= 4 || $b->{password} || $b->{restricted},
            { label => N("Password"), val => \$b->{password}, hidden => 1 },
            { label => N("Password (again)"), val => \$b->{password2}, hidden => 1 },
            { label => N("Restrict command line options"), val => \$b->{restricted}, type => "bool", text => N("restrict") },
		),
                if_(arch() !~ /alpha/ && arch() !~ /ppc/,
            { label => N("Create a bootdisk"), val => \$mkbootdisk, type => 'bool', advanced => 1 },
		),
            { label => N("Clean /tmp at each boot"), val => \$clean_tmp, type => 'bool', advanced => 1 },
            { label => N("Precise RAM size if needed (found %d MB)", availableRamMB()), val => \$memsize, advanced => 1 },
		if_(detect_devices::isLaptop(),
            { label => N("Enable multiple profiles"), val => \$profiles, type => 'bool', advanced => 1 },
		),
        ],
        complete => sub {
	    !$memsize || $memsize =~ /K$/ || $memsize =~ s/^(\d+)M?$/$1M/i or $in->ask_warn('', N("Give the ram size in MB")), return 1;
	    #-				     $security > 4 && length($b->{password}) < 6 and $in->ask_warn('', N("At this level of security, a password (and a good one) in lilo is requested")), return 1;
	    $b->{restricted} && !$b->{password} and $in->ask_warn('', N("Option ``Restrict command line options'' is of no use without a password")), return 1;
	    $b->{password} eq $b->{password2} or !$b->{restricted} or $in->ask_warn('', [ N("The passwords do not match"), N("Please try again") ]), return 1;
	    0;
	}) or return 0;
    } else {
	$b->{boot} = $partition_table::mac::bootstrap_part;	
	$in->ask_from_({ messages => N("Bootloader main options"),
			 interactive_help_id => 'setupYabootGeneral',
		       }, [
            { label => N("Bootloader to use"), val => \$b->{method}, list => [ keys %$method_choices ], format => sub { $method_choices->{$_[0]} } },
            { label => N("Init Message"), val => \$b->{'init-message'} },
            { label => N("Boot device"), val => \$b->{boot}, list => [ map { "/dev/$_" } (map { $_->{device} } (grep { isAppleBootstrap($_) } @$fstab)) ], not_edit => !$::expert },
            { label => N("Open Firmware Delay"), val => \$b->{delay} },
            { label => N("Kernel Boot Timeout"), val => \$b->{timeout} },
            { label => N("Enable CD Boot?"), val => \$b->{enablecdboot}, type => "bool" },
            { label => N("Enable OF Boot?"), val => \$b->{enableofboot}, type => "bool" },
            { label => N("Default OS?"), val => \$b->{defaultos}, list => [ 'linux', 'macos', 'macosx', 'darwin' ] },
        ]) or return 0;				
    }

    #- remove bios mapping if the user changed the boot device
    delete $b->{bios} if $b->{boot} ne $prev_boot;

    if ($b->{method} eq 'grub') {
	$in->do_pkgs->ensure_is_installed('grub', "/usr/sbin/grub", 1) or return 0;
    }

    bootloader::set_profiles($b, $profiles);
    bootloader::set_append($b, "mem", $memsize);
    if ($prev_force_acpi != $force_acpi) {
	bootloader::set_append($b, acpi => ($force_acpi ? '' : 'off'));
    }
    if ($prev_force_noapic != $force_noapic) {
	($force_noapic ? \&bootloader::set_append : \&bootloader::remove_append_simple)->($b, 'noapic');
    }

    if ($prev_clean_tmp != $clean_tmp) {
	if ($clean_tmp && !fsedit::has_mntpoint('/tmp', $all_hds)) {
	    push @{$all_hds->{special}}, { device => 'none', mntpoint => '/tmp', type => 'tmpfs' };
	} else {
	    @{$all_hds->{special}} = grep { $_->{mntpoint} eq '/tmp' } @{$all_hds->{special}};
	}
    }
    mkbootdisk($in, $b, $fstab) or return &setupBootloader__general if $mkbootdisk;

    1;
}

sub setupBootloader__entries {
    my ($in, $b, $all_hds, $fstab) = @_;

    my $Modify = sub {
	my ($e) = @_;
	my $default = my $old_default = $e->{label} eq $b->{default};

	my @l;
	if ($e->{type} eq "image") { 
	    @l = (
{ label => N("Image"), val => \$e->{kernel_or_dev}, list => [ map { s/$::prefix//; $_ } glob_("$::prefix/boot/vmlinuz*") ], not_edit => 0 },
{ label => N("Root"), val => \$e->{root}, list => [ map { "/dev/$_->{device}" } @$fstab ], not_edit => !$::expert },
{ label => N("Append"), val => \$e->{append} },
  if_(arch() !~ /ppc|ia64/,
{ label => N("Video mode"), val => \$e->{vga}, list => [ keys %bootloader::vga_modes ], format => sub { $bootloader::vga_modes{$_[0]} }, not_edit => !$::expert },
),
{ label => N("Initrd"), val => \$e->{initrd}, list => [ map { s/$::prefix//; $_ } glob_("$::prefix/boot/initrd*") ], not_edit => 0 },
{ label => N("Read-write"), val => \$e->{'read-write'}, type => 'bool' }
	    );
	    @l = @l[0..2] unless $::expert;
	} else {
	    @l = ( 
{ label => N("Root"), val => \$e->{kernel_or_dev}, list => [ map { "/dev/$_->{device}" } @$fstab ], not_edit => !$::expert },
if_(arch() !~ /sparc|ppc|ia64/,
{ label => N("Table"), val => \$e->{table}, list => [ '', map { "/dev/$_->{device}" } @{$all_hds->{hds}} ], not_edit => !$::expert },
{ label => N("Unsafe"), val => \$e->{unsafe}, type => 'bool' }
),
	    );
	    @l = $l[0] unless $::expert;
	}
	if (arch() !~ /ppc/) {
	    @l = (