package mouse; # $Id$ use diagnostics; use strict; #-###################################################################################### #- misc imports #-###################################################################################### use common; use modules; use detect_devices; use run_program; use devices; use commands; use modules; use log; my @mouses_fields = qw(nbuttons MOUSETYPE XMOUSETYPE name); my %mice = arch() =~ /^sparc/ ? ( 'sunmouse' => [ [ 'sunmouse' ], [ [ 3, 'sun', 'sun', __("Sun - Mouse") ] ]] ) : ( 'PS/2' => [ [ 'psaux' ], [ [ 2, 'ps/2', 'PS/2', __("Standard") ], [ 5, 'ps/2', 'MouseManPlusPS/2', __("Logitech MouseMan+") ], [ 5, 'imps2', 'IMPS/2', __("Generic PS2 Wheel Mouse") ], [ 5, 'ps/2', 'GlidePointPS/2', __("GlidePoint") ], '', [ 5, 'ps/2', 'ThinkingMousePS/2', __("Kensington Thinking Mouse") ], [ 5, 'netmouse', 'NetMousePS/2', __("Genius NetMouse") ], [ 5, 'netmouse', 'NetScrollPS/2', __("Genius NetScroll") ], ]], 'USB' => [ [ 'usbmouse' ], [ if_(arch() eq 'ppc', [ 1, 'ps/2', 'PS/2', __("1 button") ]), [ 2, 'ps/2', 'PS/2', __("Generic") ], [ 5, 'ps/2', 'IMPS/2', __("Wheel") ], ]], __("serial") => [ [ map { "ttyS$_" } 0..3 ], [ [ 2, 'Microsoft', 'Microsoft', __("Generic 2 Button Mouse") ], [ 3, 'Microsoft', 'Microsoft', __("Generic 3 Button Mouse") ], [ 5, 'ms3', 'IntelliMouse', __("Microsoft IntelliMouse") ], [ 3, 'MouseMan', 'MouseMan', __("Logitech MouseMan") ], [ 2, 'MouseSystems', 'MouseSystems', __("Mouse Systems") ], '', [ 3, 'logim', 'MouseMan', __("Logitech CC Series") ], [ 5, 'pnp', 'IntelliMouse', __("Logitech MouseMan+/FirstMouse+") ], [ 5, 'ms3', 'IntelliMouse', __("Genius NetMouse") ], [ 2, 'MMSeries', 'MMSeries', __("MM Series") ], [ 2, 'MMHitTab', 'MMHittab', __("MM HitTablet") ], [ 3, 'Logitech', 'Logitech', __("Logitech Mouse (serial, old C7 type)") ], [ 3, 'Microsoft', 'ThinkingMouse', __("Kensington Thinking Mouse") ], ]], __("busmouse") => [ [ arch() eq 'ppc' ? 'adbmouse' : ('atibm', 'inportbm', 'logibm') ], [ if_(arch() eq 'ppc', [ 1, 'Busmouse', 'BusMouse', __("1 button") ]), [ 2, 'Busmouse', 'BusMouse', __("2 buttons") ], [ 3, 'Busmouse', 'BusMouse', __("3 buttons") ], ]], __("none") => [ [ 'none' ], [ [ 0, 'none', 'Microsoft', __("No mouse") ], ]], ); sub xmouse2xId { #- xmousetypes must be sorted as found in /usr/include/X11/extensions/xf86misc.h #- so that first mean "0", etc my @xmousetypes = ( "Microsoft", "MouseSystems", "MMSeries", "Logitech", "BusMouse", #MouseMan, "Logitech", "PS/2", "MMHittab", "GlidePoint", "IntelliMouse", "ThinkingMouse", "IMPS/2", "ThinkingMousePS/2", "MouseManPlusPS/2", "GlidePointPS/2", "NetMousePS/2", "NetScrollPS/2", "SysMouse", "Auto", "AceCad", "WSMouse", "USB", ); my ($id) = @_; $id = 'BusMouse' if $id eq 'MouseMan'; my $i; map_index { $_ eq $id and $i = $::i } @xmousetypes; $i; } my %mouse_btn_keymap = ( 0 => "NONE", 67 => "F9", 68 => "F10", 87 => "F11", 88 => "F12", 85 => "F13", 89 => "F14", 90 => "F15", 56 => "L-Option/Alt", 125 => "L-Command", 98 => "Num: /", 55 => "Num: *", 117 => "Num: =", ); sub ppc_one_button_keys { keys %mouse_btn_keymap } sub ppc_one_button_key2text { $mouse_btn_keymap{$_[0]} } sub raw2mouse { my ($type, $raw) = @_; $raw or return; my %l; @l{@mouses_fields} = @$raw; +{ %l, type => $type }; } sub fullnames { map_each { my $type = $::a; grep {$_} map { if ($_) { my $l = raw2mouse($type, $_); "$type|$l->{name}"; } else { $type .= "|[" . _("Other") . "]"; ''; } } @{$::b->[1]} } %mice; } sub fullname2mouse { my ($fname, %opts) = @_; my ($type, @l) = split '\|', $fname; my ($name) = pop @l; $opts{device} ||= $mice{$type}[0][0]; foreach (@{$mice{$type}[1]}) { my $l = raw2mouse($type, $_); $name eq $l->{name} and return { %$l, %opts }; } die "$fname not found ($type, $name)"; } sub serial_ports() { map { "ttyS$_" } 0..7 } sub serial_port2text { $_[0] =~ /ttyS(\d+)/ ? "$_[0] / COM" . ($1 + 1) : $_[0]; } sub read { my ($prefix) = @_; my %mouse = getVarsFromSh "$prefix/etc/sysconfig/mouse"; eval { add2hash_(\%mouse, fullname2mouse($mouse{FULLNAME})) }; $mouse{device} = readlink "$prefix/dev/mouse" or log::l("reading $prefix/dev/mouse symlink failed"); $mouse{nbuttons} = $mouse{XEMU3} eq "yes" ? 2 : $mouse{WHEEL} eq "yes" ? 5 : 3; \%mouse; } sub write { my ($prefix, $mouse) = @_; local $mouse->{FULLNAME} = qq("$mouse->{type}|$mouse->{name}"); #-" local $mouse->{XEMU3} = bool2yesno($mouse->{nbuttons} < 3); local $mouse->{WHEEL} = bool2yesno($mouse->{nbuttons} > 3); setVarsInSh("$prefix/etc/sysconfig/mouse", $mouse, qw(MOUSETYPE XMOUSETYPE FULLNAME XEMU3 WHEEL device)); symlinkf $mouse->{device}, "$prefix/dev/mouse" or log::l("creating $prefix/dev/mouse symlink failed"); if (arch() =~ /ppc/) { my $s = join('', "dev.mac_hid.mouse_button_emulation = " . to_bool($mouse->{button2_key} || $mouse->{button3_key}) . "\n", if_($mouse->{button2_key}, "dev.mac_hid.mouse_button2_keycode = $mouse->{button2_key}\n"), if_($mouse->{button3_key}, "dev.mac_hid.mouse_button3_keycode = $mouse->{button3_key}\n"), ); substInFile { $_ = '' if /^\Qdev.mac_hid.mouse_button/; $_ .= $s if eof; } "$prefix/etc/sysctl.conf"; #- hack - dev RPM symlinks to mouse0 - lands on mouse1 with new input layer on PPC input/mice will get both ADB and USB symlinkf "/dev/input/mice", "$prefix/dev/usbmouse" if ($mouse->{device} eq "usbmouse"); } } sub mouseconfig { my ($t, $mouse, @wacom); #- Whouah! probing all devices from ttyS0 to ttyS3 once a time! detect_devices::probeSerialDevices(); #- check new probing methods keep everything used here intact! foreach (0..3) { $t = detect_devices::probeSerial("/dev/ttyS$_"); if ($t->{CLASS} eq 'MOUSE') { $t->{MFG} ||= $t->{MANUFACTURER}; $mouse = fullname2mouse("serial|Microsoft IntelliMouse") if $t->{MFG} eq 'MSH' && $t->{MODEL} eq '0001'; $mouse = fullname2mouse("serial|Logitech MouseMan") if $t->{MFG} eq 'LGI' && $t->{MODEL} =~ /^80/; $mouse = fullname2mouse("serial|Genius NetMouse") if $t->{MFG} eq 'KYE' && $t->{MODEL} eq '0003'; $mouse ||= fullname2mouse("serial|Generic 2 Button Mouse"); #- generic by default. $mouse->{device} = "ttyS$_"; last; } elsif ($t->{CLASS} eq "PEN" || $t->{MANUFACTURER} eq "WAC") { push @wacom, "ttyS$_"; } } $mouse, @wacom; } sub detect() { if (arch() =~ /^sparc/) { return fullname2mouse("sunmouse|Sun - Mouse"); } if (arch() eq "ppc") { return fullname2mouse(detect_devices::hasMousePS2("usbmouse") ? "USB|1 button" : # No need to search for an ADB mouse. If I did, the PPC kernel would # find one whether or not I had one installed! So.. default to it. "busmouse|1 button"); } my @wacom; my $fast_mouse_probe = sub { my $auxmouse = detect_devices::hasMousePS2("psaux") && fullname2mouse("PS/2|Standard", unsafe => 1); if (modules::get_alias("usb-interface")) { if (my (@l) = detect_devices::usbMice()) { log::l("found usb mouse $_->{driver} $_->{description} ($_->{type})") foreach @l; eval { modules::load("usbmouse"); modules::load("mousedev"); }; if (!$@ && detect_devices::tryOpen("usbmouse")) { my $mouse = fullname2mouse($l[0]{driver} =~ /Mouse:(.*)/ ? $1 : "USB|Generic"); $auxmouse and $mouse->{auxmouse} = $auxmouse; #- for laptop, we kept the PS/2 as secondary (symbolic). return $mouse; } eval { modules::unload("mousedev"); modules::unload("usbmouse"); }; } } $auxmouse; }; if (modules::get_alias("usb-interface")) { my $keep_mouse; if (my (@l) = detect_devices::usbWacom()) { log::l("found usb wacom $_->{driver} $_->{description} ($_->{type})") foreach @l; eval { modules::load("wacom"); modules::load("evdev"); }; unless ($@) { foreach (0..$#l) { detect_devices::tryOpen("input/event$_") and $keep_mouse = 1, push @wacom, "input/event$_"; } } $keep_mouse or eval { modules::unload("evdev"); modules::unload("wacom"); }; } } #- at this level, not all possible mice are detected so avoid invoking serial_probe #- which takes a while for its probe. if ($::isStandalone) { my $mouse = $fast_mouse_probe->(); $mouse and return ($mouse, @wacom); } #- probe serial device to make sure a wacom has been detected. eval { modules::load("serial") }; my ($r, @serial_wacom) = mouseconfig(); push @wacom, @serial_wacom; if (!$::isStandalone) { my $mouse = $fast_mouse_probe->(); $r && $mouse and $r->{auxmouse} = $mouse; #- we kept the auxilliary mouse as PS/2. $r and return ($r, @wacom); $mouse and return ($mouse, @wacom); } else { $r and return ($r, @wacom); } #- in case only a wacom has been found, assume an inexistant mouse (necessary). @wacom and return { CLASS => 'MOUSE', nbuttons => 2, device => "nothing", MOUSETYPE => "Microsoft", XMOUSETYPE => "Microsoft"}, @wacom; #- defaults to generic serial mouse on ttyS0. #- Oops? using return let return a hash ref, if not using it, it return a list directly :-) return fullname2mouse("serial|Generic 2 Button Mouse", unsafe => 1); } #- write_conf : write the mouse infos into the Xconfig files. #- input : #- $mouse : the hashtable containing the informations #- $mouse input #- $mouse->{nbuttons} : number of buttons : integer #- $mouse->{device} : device of the mouse : string : ex 'psaux' #- $mouse->{XMOUSETYPE} : type of the mouse for gpm : string : ex 'PS/2' #- $mouse->{type} : type (generic ?) of the mouse : string : ex 'PS/2' #- $mouse->{name} : name of the mouse : string : ex 'Standard' #- $mouse->{MOUSETYPE} : type of the mouse : string : ex "ps/2" #- $mouse->{XEMU3} : emulate 3rd button : string : 'yes' or 'no' sub write_conf { my ($mouse) = @_; &write('', $mouse); modules::write_conf('') if $mouse->{device} eq "usbmouse" && !$::testing; my $f = "/etc/X11/XF86Config"; my $g = "/etc/X11/XF86Config-4"; my $update_mouse = sub { my ($mouse, $id) = @_; my @zaxis = ( $mouse->{nbuttons} > 3 ? [ "ZAxisMapping", "4 5" ] : (), $mouse->{nbuttons} > 5 ? [ "ZAxisMapping", "6 7" ] : (), $mouse->{nbuttons} < 3 ? ([ "Emulate3Buttons" ], [ "Emulate3Timeout", "50" ]) : () ); my $zaxis = join('', map { qq(\n $_->[0]) . ($_->[1] && qq( $_->[1])) } @zaxis); substInFile { if ($id > 1) { if (/^DeviceName\s+"Mouse$id"/ .. /^EndSection/) { $_ = '' if /(ZAxisMapping|Emulate3)/; #- remove existing line s|^(\s*Protocol\s+).*|$1"$mouse->{XMOUSETYPE}"|; s|^(\s*Device\s+).*|$1"/dev/mouse"$zaxis|; } } else { if (/^Section\s+"Pointer"/ .. /^EndSection/) { $_ = '' if /(ZAxisMapping|Emulate3)/; #- remove existing line s|^(\s*Protocol\s+).*|$1"$mouse->{XMOUSETYPE}"|; s|^(\s*Device\s+).*|$1"/dev/mouse"$zaxis|; } } } $f if -e $f && !$::testing; $zaxis = join('', map { qq(\n Option "$_->[0]") . ($_->[1] && qq( "$_->[1]")) } @zaxis); substInFile { if (/Identifier\s+"Mouse$id"/ .. /^EndSection/) { $_ = '' if /(ZAxisMapping|Emulate3)/; #- remove existing line s|^(\s*Option\s+"Protocol"\s+).*|$1"$mouse->{XMOUSETYPE}"|; s|^(\s*Option\s+"Device"\s+).*|$1"/dev/mouse"$zaxis|; } } $g if -e $g && !$::testing; }; $update_mouse->($mouse, 1); $mouse->{auxmouse} and $update_mouse->($mouse->{auxmouse}, 2); } ' href='#n172'>172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 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 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972
package install_steps; # $Id$

use diagnostics;
use strict;
use vars qw(@filesToSaveForUpgrade @ISA);

#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use install_any qw(:all);
use partition_table qw(:types);
use detect_devices;
use modules;
use run_program;
use lang;
use keyboard;
use fsedit;
use loopback;
use pkgs;
use any;
use log;
use fs;

@filesToSaveForUpgrade = qw(
/etc/ld.so.conf /etc/fstab /etc/hosts /etc/conf.modules /etc/modules.conf
);


#-######################################################################################
#- OO Stuff
#-######################################################################################
sub new($$) {
    my ($type, $o) = @_;

    bless $o, ref $type || $type;
    return $o;
}

#-######################################################################################
#- In/Out Steps Functions
#-######################################################################################
sub enteringStep {
    my ($o, $step) = @_;
    log::l("starting step `$step'");
}
sub leavingStep {
    my ($o, $step) = @_;
    log::l("step `$step' finished");

    if (-d "$o->{prefix}/root") {
	eval { commands::cp('-f', "/tmp/ddebug.log", "$o->{prefix}/root") };
	output(install_any::auto_inst_file(), install_any::g_auto_install());
    }

    for (my $s = $o->{steps}{first}; $s; $s = $o->{steps}{$s}{next}) {
	#- the reachability property must be recomputed each time to take
	#- into account failed step.
	next if $o->{steps}{$s}{done} && !$o->{steps}{$s}{redoable};

	my $reachable = 1;
	if (my $needs = $o->{steps}{$s}{needs}) {
	    my @l = ref $needs ? @$needs : $needs;
	    $reachable = min(map { $o->{steps}{$_}{done} || 0 } @l);
	}
	$o->{steps}{$s}{reachable} = 1 if $reachable;
    }
    $o->{steps}{$step}{reachable} = $o->{steps}{$step}{redoable};

    while (my $f = shift @{$o->{steps}{$step}{toBeDone} || []}) {
	eval { &$f() };
	$o->ask_warn(_("Error"), [
_("An error occurred, but I don't know how to handle it nicely.
Continue at your own risk."), $@ ]) if $@;
    }
}

sub errorInStep($$) { print "error :(\n"; c::_exit(1) }
sub kill_action {}
sub set_help { 1 }

#-######################################################################################
#- Steps Functions
#-######################################################################################
#------------------------------------------------------------------------------
sub selectLanguage {
    my ($o) = @_;
    lang::set($o->{lang});
    $o->{langs} ||= { $o->{lang} => 1 };

    log::l("selectLanguage: pack_langs ", lang::pack_langs($o->{langs}));

    if ($o->{keyboard_unsafe} || !$o->{keyboard}) {
	$o->{keyboard_unsafe} = 1;
	$o->{keyboard} = keyboard::lang2keyboard($o->{lang});
	selectKeyboard($o) if !$::live;
    }
}
#------------------------------------------------------------------------------
sub selectKeyboard {
    my ($o) = @_;
    keyboard::setup($o->{keyboard});

    #- if we go back to the selectKeyboard, you must rewrite
    addToBeDone {
	lang::write_langs($o->{prefix}, $o->{langs});
    } 'formatPartitions' unless $::g_auto_install;
    addToBeDone {
	lang::write($o->{prefix}, $o->{lang});
	keyboard::write($o->{prefix}, $o->{keyboard}, lang::lang2charset($o->{lang}));
    } 'installPackages' unless $::g_auto_install;
}
#------------------------------------------------------------------------------
sub selectPath {}
#------------------------------------------------------------------------------
sub selectInstallClass {}
#------------------------------------------------------------------------------
sub setupSCSI {
    my ($o) = @_;
    modules::configure_pcmcia($o->{pcmcia}) if $o->{pcmcia};
    modules::load_ide();
    modules::load_thiskind('scsi|disk');
}

#------------------------------------------------------------------------------
sub doPartitionDisksBefore {
    my ($o) = @_;

    if (cat_("/proc/mounts") =~ m|/\w+/(\S+)\s+/tmp/hdimage\s+(\S+)| && !$o->{partitioning}{readonly}) {
	$o->{stage1_hd} = { device => $1, type => $2 };
	install_any::getFile("XXX"); #- close still opened filehandle
	eval { fs::umount("/tmp/hdimage") };
    }
    eval { 
	close *pkgs::LOG;
	eval { fs::umount("$o->{prefix}/proc") };
	eval {          fs::umount_all($o->{fstab}, $o->{prefix}) };
	eval { sleep 1; fs::umount_all($o->{fstab}, $o->{prefix}) } if $@; #- HACK
    } if $o->{fstab} && !$::testing && !$::live;

    $o->{raid} ||= {};
}

#------------------------------------------------------------------------------
sub doPartitionDisksAfter {
    my ($o) = @_;
    unless ($::testing) {
	partition_table::write($_) foreach @{$o->{hds}};
	$_->{rebootNeeded} and $o->rebootNeeded foreach @{$o->{hds}};
    }

    $o->{fstab} = [ fsedit::get_fstab(@{$o->{hds}}, @{$o->{lvms}}, $o->{raid}) ];
    fsedit::get_root_($o->{fstab}) or die "Oops, no root partition";
    
    if (arch() =~ /ppc/ && detect_devices::get_mac_generation =~ /NewWorld/) {
	die "Need bootstrap partition to boot system!" if !(defined $partition_table_mac::bootstrap_part);
    }
    
    if (arch() =~ /ia64/ && !fsedit::has_mntpoint("/boot/efi", $o->{hds})) {
	die _("You must have a FAT partition mounted in /boot/efi");
    }

    if ($o->{partitioning}{use_existing_root}) {
	#- ensure those partitions are mounted so that they are not proposed in choosePartitionsToFormat
	fs::mount_part($_, $o->{prefix}) foreach grep { $_->{mntpoint} && !$_->{notFormatted} } @{$o->{fstab}};
    }

    if (my $s = delete $o->{stage1_hd}) {
	my ($part) = grep { $_->{device} eq $s->{device} } @{$o->{fstab}};
	$part->{isMounted} ?
	  do { rmdir "/tmp/hdimage" ; symlinkf("$o->{prefix}$part->{mntpoint}", "/tmp/hdimage") } :
	  eval { 
	      fs::mount($s->{device}, "/tmp/hdimage", $s->{type});
	      $part->{isMounted} = 1;
	  };
    }

    cat_("/proc/mounts") =~ m|(\S+)\s+/tmp/image nfs| &&
      !grep { $_->{mntpoint} eq "/mnt/nfs" } @{$o->{manualFstab} || []} and
	push @{$o->{manualFstab}}, { type => "nfs", mntpoint => "/mnt/nfs", device => $1, options => "noauto,ro,nosuid,rsize=8192,wsize=8192" };
}

#------------------------------------------------------------------------------
sub doPartitionDisks {
    my ($o) = @_;

    install_any::getHds($o);

    if ($o->{partitioning}{use_existing_root} || $o->{isUpgrade}) {
	# either one root is defined (and all is ok), or we take the first one we find
	my $p = fsedit::get_root_($o->{fstab}) || first(install_any::find_root_parts($o->{fstab}, $o->{prefix})) or die;
	install_any::use_root_part($o->{fstab}, $p, $o->{prefix});
    } 
    if ($o->{partitioning}{auto_allocate}) {
	fsedit::auto_allocate($o->{hds}, $o->{partitions}, $o->{raid}{raid});
    }
}

#------------------------------------------------------------------------------

sub ask_mntpoint_s {
    my ($o, $fstab) = @_;

    #- TODO: set the mntpoints

    my %m; foreach (@$fstab) {
	my $m = $_->{mntpoint};

	next unless $m && $m ne 'swap'; #- there may be a lot of swap.

	$m{$m} and die _("Duplicate mount point %s", $m);
	$m{$m} = 1;

	#- in case the type does not correspond, force it to ext2
	$_->{type} = 0x83 if $m =~ m|^/| && !isFat($_) && !isTrueFS($_);
    }
    1;
}


sub rebootNeeded($) {
    my ($o) = @_;
    log::l("Rebooting...");
    c::_exit(0);
}

sub choosePartitionsToFormat($$) {
    my ($o, $fstab) = @_;

    foreach (@$fstab) {
	$_->{mntpoint} = "swap" if isSwap($_);
	$_->{mntpoint} or next;
	
	add2hash_($_, { toFormat => $_->{notFormatted} });
	if (!$_->{toFormat}) {
	    my $t = isLoopback($_) ? 
	      eval { fsedit::typeOfPart($o->{prefix} . loopback::file($_)) } :
	      fsedit::typeOfPart($_->{device});
	    $_->{toFormatUnsure} = member($_->{mntpoint}, '/', '/usr') ||
	      #- if detected dos/win, it's not precise enough to just compare the types (too many of them)
	      (!$t || isOtherAvailableFS({ type => $t }) ? !isOtherAvailableFS($_) : $t != $_->{type});
	}
    }
}

sub formatMountPartitions {
    my ($o) = @_;
    fs::formatMount_all($o->{raid}, $o->{fstab}, $o->{prefix});
}

#------------------------------------------------------------------------------
sub setPackages {
    my ($o) = @_;
    install_any::setPackages($o);
    pkgs::selectPackagesAlreadyInstalled($o->{packages}, $o->{prefix})
	if !$o->{isUpgrade} && (-r "$o->{prefix}/var/lib/rpm/packages.rpm" || -r "$o->{prefix}/var/lib/rpm/Packages");
}
sub selectPackagesToUpgrade {
    my ($o) = @_;
    pkgs::selectPackagesToUpgrade($o->{packages}, $o->{prefix}, $o->{base}, $o->{toRemove}, $o->{toSave});
}

sub choosePackages {
    my ($o, $packages, $compssUsers, $first_time) = @_;

    #- now for upgrade, package that must be upgraded are
    #- selected first, after is used the same scheme as install.

    #- make sure we kept some space left for available else the system may
    #- not be able to start (xfs at least).
    my $available = install_any::getAvailableSpace($o);
    my $availableCorrected = pkgs::invCorrectSize($available / sqr(1024)) * sqr(1024);
    log::l(sprintf "available size %s (corrected %s)", formatXiB($available), formatXiB($availableCorrected));

    add2hash_($o, { compssListLevel => 5 }) if !$::auto_install;

    #- avoid destroying user selection of packages but only
    #- for expert, as they may have done individual selection before.
    if ($first_time || !$::expert) {
	install_any::unselectMostPackages($o);

	exists $o->{compssListLevel}
	  and pkgs::setSelectedFromCompssList($packages, $o->{compssUsersChoice}, $o->{compssListLevel}, $availableCorrected);
    }
    $availableCorrected;
}

sub beforeInstallPackages {
    my ($o) = @_;

    #- save these files in case of upgrade failure.
    if ($o->{isUpgrade}) {
	foreach (@filesToSaveForUpgrade) {
	    unlink "$o->{prefix}/$_.mdkgisave";
	    if (-e "$o->{prefix}/$_") {
		eval { commands::cp("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgisave") };
	    }
	}
    }

    #- some packages need such files for proper installation.
    install_any::write_fstab($o);

    require network;
    network::add2hosts("$o->{prefix}/etc/hosts", "localhost.localdomain", "127.0.0.1");

    require pkgs;
    pkgs::init_db($o->{prefix});
}

sub pkg_install {
    my ($o, @l) = @_;
    log::l("selecting packages");
    require pkgs;
    if ($::testing) {
	log::l("selecting package \"$_\"") foreach @l;
    } else {
	pkgs::selectPackage($o->{packages}, pkgs::packageByName($o->{packages}, $_) || die "$_ rpm not found") foreach @l;
    }
    my @toInstall = pkgs::packagesToInstall($o->{packages});
    if (@toInstall) {
	log::l("installing packages");
	$o->installPackages;
    } else {
	log::l("all packages selected are already installed, nothing to do")
    }
}

sub pkg_install_if_requires_satisfied {
    my ($o, @l) = @_;
    require pkgs;
    foreach (@l) {
	my %newSelection;
	my $pkg = pkgs::packageByName($o->{packages}, $_) || die "$_ rpm not found";
	pkgs::selectPackage($o->{packages}, $pkg, 0, \%newSelection);
	if (scalar(keys %newSelection) == 1) {
	    pkgs::selectPackage($o->{packages}, $pkg);
	} else {
	    log::l("pkg_install_if_requires_satisfied: not selecting $_ because of ", join(", ", keys %newSelection));
	}
    }
    $o->installPackages;
}

sub installPackages($$) { #- complete REWORK, TODO and TOCHECK!
    my ($o) = @_;
    my $packages = $o->{packages};

    if (@{$o->{toRemove} || []}) {
	#- hack to ensure proper upgrade of packages from other distribution,
	#- as release number are not mandrake based. this causes save of
	#- important files and restore them after.
	foreach (@{$o->{toSave} || []}) {
	    if (-e "$o->{prefix}/$_") {
		eval { commands::cp("-f", "$o->{prefix}/$_", "$o->{prefix}/$_.mdkgisave") };
	    }
	}
	pkgs::remove($o->{prefix}, $o->{toRemove});
	foreach (@{$o->{toSave} || []}) {
	    if (-e "$o->{prefix}/$_.mdkgisave") {
		renamef("$o->{prefix}/$_.mdkgisave", "$o->{prefix}/$_");
	    }
	}
	$o->{toSave} = [];

	#- hack for compat-glibc to upgrade properly :-(
	if (pkgs::packageFlagSelected(pkgs::packageByName($packages, 'compat-glibc')) &&
	    !pkgs::packageFlagInstalled(pkgs::packageByName($packages, 'compat-glibc'))) {
	    rename "$o->{prefix}/usr/i386-glibc20-linux", "$o->{prefix}/usr/i386-glibc20-linux.mdkgisave";
	}
    }

    #- small transaction will be built based on this selection and depslist.
    my @toInstall = pkgs::packagesToInstall($packages);

    my $time = time;
    $ENV{DURING_INSTALL} = 1;
    pkgs::install($o->{prefix}, $o->{isUpgrade}, \@toInstall, $packages->{depslist}, $packages->{mediums});
    delete $ENV{DURING_INSTALL};
    run_program::rooted_or_die($o->{prefix}, 'ldconfig') unless $::g_auto_install;
    log::l("Install took: ", formatTimeRaw(time - $time));
    install_any::log_sizes($o);
    scalar(@toInstall); #- return number of packages installed.
}

sub afterInstallPackages($) {
    my ($o) = @_;

    return if $::g_auto_install;

    die _("Some important packages didn't get installed properly.
Either your cdrom drive or your cdrom is defective.
Check the cdrom on an installed computer using \"rpm -qpl Mandrake/RPMS/*.rpm\"
") if grep { m|read failed: Input/output error| } cat_("$o->{prefix}/root/install.log");

    if (arch() !~ /^sparc/) { #- TODO restore it as may be needed for sparc
	-x "$o->{prefix}/usr/bin/dumpkeys" or $::testing or die 
"Some important packages didn't get installed properly.

Please switch to console 2 (using ctrl-alt-f2)
and look at the log file /tmp/ddebug.log

Consoles 1,3,4,7 may also contain interesting information";
    }

    pkgs::done_db();

    #-  why not? cuz weather is nice today :-) [pixel]
    common::sync(); common::sync();

    #- generate /etc/lvmtab needed for rc.sysinit
    run_program::rooted($o->{prefix}, 'vgscan') if -e '/etc/lvmtab';

    #- configure PCMCIA services if needed.
    modules::write_pcmcia($o->{prefix}, $o->{pcmcia});

    #- for mandrake_firstime
    touch "$o->{prefix}/var/lock/TMP_1ST";