package detect_devices; # $Id$ use diagnostics; use strict; use vars qw($pcitable_addons $usbtable_addons); #-###################################################################################### #- misc imports #-###################################################################################### use log; use common; use devices; use run_program; use c; #-##################################################################################### #- Globals #-##################################################################################### my %serialprobe; #-###################################################################################### #- Functions #-###################################################################################### sub dev_is_devfs() { -e "/dev/.devfsd" } #- no $::prefix, returns false during install and that's nice :) sub get() { #- Detect the default BIOS boot harddrive is kind of tricky. We may have IDE, #- SCSI and RAID devices on the same machine. From what I see so far, the default #- BIOS boot harddrive will be #- 1. The first IDE device if IDE exists. Or #- 2. The first SCSI device if SCSI exists. Or #- 3. The first RAID device if RAID exists. getIDE(), getSCSI(), getDAC960(), getCompaqSmartArray(), getATARAID(); } sub hds() { grep { $_->{media_type} eq 'hd' && !isRemovableDrive($_) } get() } sub tapes() { grep { $_->{media_type} eq 'tape' } get() } sub cdroms() { grep { $_->{media_type} eq 'cdrom' } get() } sub burners() { grep { isBurner($_) } cdroms() } sub dvdroms() { grep { isDvdDrive($_) } cdroms() } sub raw_zips() { grep { member($_->{media_type}, 'fd', 'hd') && isZipDrive($_) } get() } #-sub jazzs { grep { member($_->{media_type}, 'fd', 'hd') && isJazzDrive($_) } get() } sub ls120s() { grep { member($_->{media_type}, 'fd', 'hd') && isLS120Drive($_) } get() } sub zips() { map { $_->{device} .= 4; $_->{devfs_device} = $_->{devfs_prefix} . '/part4'; $_; } raw_zips(); } sub floppies() { require modules; eval { modules::load("floppy") }; my @fds = $@ ? () : map { my $info = (!dev_is_devfs() || -e "/dev/fd$_") && c::floppy_info(devices::make("fd$_")); if_($info && $info ne '(null)', { device => "fd$_", devfs_device => "floppy/$_", media_type => 'fd', info => $info }) } qw(0 1); my @ide = ls120s() and eval { modules::load("ide-floppy") }; eval { modules::load("usb-storage") } if usbStorage(); my @scsi = grep { $_->{media_type} eq 'fd' } getSCSI(); @ide, @scsi, @fds; } sub floppies_dev() { map { $_->{device} } floppies() } sub floppy() { first(floppies_dev()) } #- example ls120, model = "LS-120 SLIM 02 UHD Floppy" sub removables() { floppies(), cdroms(), zips(); } sub get_sys_cdrom_info { my (@drives) = @_; my @drives_order; foreach (cat_("/proc/sys/dev/cdrom/info")) { my ($t, $l) = split ':'; my @l; @l = split(' ', $l) if $l; if ($t eq 'drive name') { @drives_order = map { my $dev = $_; find { $_->{device} eq $dev } @drives; } @l; } else { my $capacity; if ($t eq 'Can write CD-R') { $capacity = 'burner'; } elsif ($t eq 'Can read DVD') { $capacity = 'DVD'; } if ($capacity) { each_index { ($drives_order[$::i] || {})->{capacity} .= "$capacity " if $_; } @l; } } } } sub get_usb_storage_info_24 { my (@l) = @_; my %usbs = map { my $s = cat_(glob_("$_/*")); my ($host) = $s =~ /^\s*Host scsi(\d+):/m; #-# my ($vendor_name) = $s =~ /^\s*Vendor: (.*)/m; my ($vendor, $id) = $s =~ /^\s*GUID: (....)(....)/m; if_(defined $host, $host => { vendor_name => $vendor_name, usb_vendor => hex $vendor, usb_id => hex $id }); } glob_('/proc/scsi/usb-storage-*') or return; #- only the entries matching the following conditions can be usb-storage devices @l = grep { $_->{channel} == 0 && $_->{id} == 0 && $_->{lun} == 0 } @l; my %l; push @{$l{$_->{host}}}, $_ foreach @l; foreach my $host (keys %usbs) { my @choices = @{$l{$host} || []} or log::l("weird, host$host from /proc/scsi/usb-storage-*/* is not in /proc/scsi/scsi"), next; if (@choices > 1) { @choices = grep { $_->{info} =~ /^\Q$usbs{$host}{vendor_name}/ } @choices; @choices or log::l("weird, can't find the good entry host$host from /proc/scsi/usb-storage-*/* in /proc/scsi/scsi"), next; @choices == 1 or log::l("argh, can't determine the good entry host$host from /proc/scsi/usb-storage-*/* in /proc/scsi/scsi"), next } add2hash($choices[0], $usbs{$host}); } complete_usb_storage_info(grep { exists $_->{usb_vendor} } @l); @l; } sub complete_usb_storage_info { my (@l) = @_; my @usb = grep { exists $_->{usb_vendor} } @l; foreach my $usb (usb_probe()) { if (my $e = find { $_->{usb_vendor} == $usb->{vendor} && $_->{usb_id} == $usb->{id} } @usb) { $e->{"usb_$_"} = $usb->{$_} foreach keys %$usb; } } } sub get_devfs_devices { my (@l) = @_; my %h = (cdrom => 'cd', hd => 'disc'); foreach (@l) { $_->{devfs_prefix} = sprintf('scsi/host%d/bus%d/target%d/lun%d', $_->{host}, $_->{channel}, $_->{id}, $_->{lun}) if $_->{bus} eq 'SCSI'; my $t = $h{$_->{media_type}} or next; $_->{devfs_device} = $_->{devfs_prefix} . '/' . $t; } } sub isBurner { my ($e) = @_; $e->{capacity} =~ /burner/ and return 1; #- do not work for SCSI my $f = tryOpen($e->{device}); #- SCSI burner are not detected this way. $f && c::isBurner(fileno($f)); } sub isDvdDrive { my ($e) = @_; $e->{capacity} =~ /DVD/ || $e->{info} =~ /DVD/ and return 1; #- do not work for SCSI my $f = tryOpen($e->{device}); $f && c::isDvdDrive(fileno($f)); } sub isZipDrive { $_[0]{info} =~ /ZIP\s+\d+/ } #- accept ZIP 100, untested for bigger ZIP drive. sub isJazzDrive { $_[0]{info} =~ /\bJAZZ?\b/i } #- accept "iomega jaz 1GB" sub isLS120Drive { $_[0]{info} =~ /LS-?120|144MB/ } sub isRemovableUsb { $_[0]{usb_media_type} && index($_[0]{usb_media_type}, 'Mass Storage') == 0 && usb2removable($_[0]) } sub isKeyUsb { $_[0]{usb_media_type} && index($_[0]{usb_media_type}, 'Mass Storage') == 0 && $_[0]{media_type} eq 'hd' } sub isFloppyUsb { $_[0]{usb_driver} && $_[0]{usb_driver} eq 'Removable:floppy' } sub isRemovableDrive { my ($e) = @_; isZipDrive($e) || isLS120Drive($e) || $e->{media_type} && $e->{media_type} eq 'fd' || isRemovableUsb($e) || $e->{usb_media_type} && index($e->{usb_media_type}, 'Mass Storage|Floppy (UFI)') == 0; } sub getSCSI_24() { my $err = sub { log::l("ERROR: unexpected line in /proc/scsi/scsi: $_[0]") }; my ($first, @l) = common::join_lines(cat_("/proc/scsi/scsi")) or return; $first =~ /^Attached devices:/ or $err->($first); @l = map_index { my ($host, $channel, $id, $lun) = m/^Host: scsi(\d+) Channel: (\d+) Id: (\d+) Lun: (\d+)/ or $err->($_); my ($vendor, $model) = /^\s*Vendor:\s*(.*?)\s+Model:\s*(.*?)\s+Rev:/m or $err->($_); my ($type) = /^\s*Type:\s*(.*)/m or $err->($_); { info => "$vendor $model", host => $host, channel => $channel, id => $id, lun => $lun, device => "sg$::i", raw_type => $type, bus => 'SCSI' }; } @l; get_usb_storage_info_24(@l); each_index { my $dev = "sd" . chr($::i + ord('a')); put_in_hash $_, { device => $dev, media_type => isFloppyUsb($_) ? 'fd' : 'hd' }; } grep { $_->{raw_type} =~ /Direct-Access|Optical Device/ } @l; each_index { put_in_hash $_, { device => "st$::i", media_type => 'tape' }; } grep { $_->{raw_type} =~ /Sequential-Access/ } @l; each_index { put_in_hash $_, { device => "sr$::i", media_type => 'cdrom' }; } grep { $_->{raw_type} =~ /CD-ROM|WORM/ } @l; # Old hp scanners report themselves as "Processor"s # (see linux/include/scsi/scsi.h and sans-find-scanner.1) each_index { put_in_hash $_, { media_type => 'scanner' }; } grep { $_->{raw_type} =~ /Scanner/ || $_->{raw_type} =~ /Processor / } @l; delete $_->{raw_type} foreach @l; get_devfs_devices(@l); get_sys_cdrom_info(@l); @l; } sub getSCSI_26() { my $dev_dir = '/sys/bus/scsi/devices'; my @scsi_types = ( "Direct-Access", "Sequential-Access", "Printer", "Processor", "WORM", "CD-ROM", "Scanner", "Optical Device", "Medium Changer", "Communications", ); my @l = map { my ($host, $channel, $id, $lun) = split ':' or log::l("bad entry in $dev_dir: $_"), next; my $dir = "$dev_dir/$_"; my $get = sub { my $s = cat_("$dir/$_[0]"); $s =~ s/\s+$//; $s; }; my $usb_dir = readlink("$dir/block/device") =~ m!/usb! && "$dir/block/device/../../.."; my $get_usb = sub { chomp_(cat_("$usb_dir/$_[0]")) }; my ($device) = readlink("$dir/block") =~ m!/block/(.*)!; my $media_type = ${{ st => 'tape', sr => 'cdrom', sd => 'hd' }}{substr($device, 0, 2)}; # Old hp scanners report themselves as "Processor"s # (see linux/include/scsi/scsi.h and sans-find-scanner.1) my $raw_type = $scsi_types[$get->('type')]; $media_type ||= 'scanner' if $raw_type =~ /Scanner|Processor/; { info => $get->('vendor') . ' ' . $get->('model'), host => $host, channel => $channel, id => $id, lun => $lun, bus => 'SCSI', media_type => $media_type, device => $device, $usb_dir ? ( usb_vendor => hex($get_usb->('idVendor')), usb_id => hex($get_usb->('idProduct')), ) : (), }; } all($dev_dir); complete_usb_storage_info(@l); foreach (@l) { $_->{media_type} = 'fd' if $_->{media_type} eq 'hd' && isFloppyUsb($_); } get_devfs_devices(@l); get_sys_cdrom_info(@l); @l; } sub getSCSI() { c::kernel_version() =~ /^\Q2.6/ ? getSCSI_26() : getSCSI_24() } my %eide_hds = ( "ASUS" => "Asus", "CD-ROM CDU" => "Sony", "CD-ROM Drive/F5D" => "ASUSTeK", "Compaq" => "Compaq", "CONNER" => "Conner Peripherals", "IBM" => "IBM", "FUJITSU" => "Fujitsu", "HITACHI" => "Hitachi", "Lite-On" => "Lite-On Technology Corp.", "LITE-ON" => "Lite-On Technology Corp.", "LTN" => "Lite-On Technology Corp.", "IOMEGA" => "Iomega", "MAXTOR" => "Maxtor", "Maxtor" => "Maxtor", "Micropolis" => "Micropolis", "Pioneer" => "Pioneer", "PLEXTOR" => "Plextor", "QUANTUM" => "Quantum", "SAMSUNG" => "Samsung", "Seagate " => "Seagate Technology", "ST3" => "Seagate Technology", "TEAC" => "Teac", "TOSHIBA" => "Toshiba", "WDC" => "Western Digital Corp.", ); sub getIDE() { my @idi; #- what about a system with absolutely no IDE on it, like some sparc machine. -e "/proc/ide" or return (); #- Great. 2.2 kernel, things are much easier and less error prone. foreach my $d (sort @{[glob_('/proc/ide/hd*')]}) { cat_("$d/driver") =~ /ide-scsi/ and next; #- already appears in /proc/scsi/scsi my $t = chomp_(cat_("$d/media")); my $type = ${{ disk => 'hd', cdrom => 'cdrom', tape => 'tape', floppy => 'fd' }}{$t} or next; my $info = chomp_(cat_("$d/model")) || "(none)"; my $num = ord(($d =~ /(.)$/)[0]) - ord 'a'; my ($vendor, $model) = map { if_($info =~ /^$_(-|\s)*(.*)/, $eide_hds{$_}, $2); } keys %eide_hds; my $host = $num; ($host, my $id) = divide($host, 2); ($host, my $channel) = divide($host, 2); my $devfs_prefix = sprintf('ide/host%d/bus%d/target%d/lun0', $host, $channel, $id); push @idi, { media_type => $type, device => basename($d), devfs_prefix => $devfs_prefix, info => $info, host => $host, channel => $channel, id => $id, bus => 'ide', if_($vendor, Vendor => $vendor), if_($model, Model => $model) }; } get_devfs_devices(@idi); get_sys_cdrom_info(@idi); @idi; } sub getCompaqSmartArray() { my (@idi, $f); foreach ('array/ida', 'cpqarray/ida', 'cciss/cciss') { my $prefix = "/proc/driver/$_"; #- kernel 2.4 places it here $prefix = "/proc/$_" if !-e "${prefix}0"; #- kernel 2.2 my ($name) = m|/(.*)|; for (my $i = 0; -r ($f = "${prefix}$i"); $i++) { foreach (cat_($f)) { if (my ($raw_device) = m|^\s*($name/.*?):|) { my $device = -d "/dev/$raw_device" ? "$raw_device/disc" : $raw_device; push @idi, { device => $device, prefix => $raw_device . 'p', info => "Compaq RAID logical disk", media_type => 'hd', bus => 'ida' }; } } } } @idi; } sub getDAC960() { my %idi; #- We are looking for lines of this format:DAC960#0: #- /dev/rd/c0d0: RAID-7, Online, 17928192 blocks, Write Thru0123456790123456789012 foreach (syslog()) { my ($device, $info) = m|/dev/(rd/.*?): (.*?),| or next; $idi{$device} = { info => $info, media_type => 'hd', device => $device, prefix => $device . 'p', bus => 'dac960' }; } values %idi; } sub getATARAID() { my %l; foreach (syslog()) { my ($device) = m|^\s*(ataraid/d\d+):| or next; $l{$device} = { info => 'ATARAID block device', media_type => 'hd', device => $device, prefix => $device . 'p', bus => 'ataraid' }; log::l("ATARAID: $device"); } values %l; } # cpu_name : arch() =~ /^alpha/ ? "cpu " : # arch() =~ /^ppc/ ? "processor" : "vendor_id" # cpu_model : arch() =~ /^alpha/ ? "cpu model" : # arch() =~ /^ppc/ ? "cpu " : "model name" # cpu_freq = arch() =~ /^alpha/ ? "cycle frequency [Hz]" : # arch() =~ /^ppc/ ? "clock" : "cpu MHz" sub getCPUs() { my (@cpus, $cpu); foreach (cat_("/proc/cpuinfo")) { if (/^processor/) { # ix86 specific push @cpus, $cpu if $cpu; $cpu = {}; } $cpu->{$1} = $2 if /^([^\t]+).*:\s(.*)$/; $cpu->{processor}++ if $1 eq "processor"; } push @cpus, $cpu; @cpus; } sub getSoundDevices() { (arch() =~ /ppc/ ? \&modules::load_category : \&modules::probe_category)->('multimedia/sound'); } sub isTVcard { member($_[0]{driver}, qw(bttv cx8800 saa7134 usbvision)) } sub getTVcards() { grep { isTVcard($_) } detect_devices::probeall(); } sub getSerialModem { my ($o_mouse) = @_; my $mouse = $o_mouse || {}; $mouse->{device} = readlink "/dev/mouse"; my $serdev = arch() =~ /ppc/ ? "macserial" : "serial"; eval { modules::load($serdev) }; my @modems; probeSerialDevices(); foreach my $port (map { "ttyS$_" } (0..7)) { next if $mouse->{device} =~ /$port/; my $device = "/dev/$port"; next if !-e $device || !hasModem($device); $serialprobe{$device}{device} = $device; push @modems, $serialprobe{$device}; } my @devs = pcmcia_probe(); foreach my $modem (@modems) { #- add an alias for macserial on PPC modules::add_alias('serial', $serdev) if arch() =~ /ppc/ && $modem->{device}; foreach (@devs) { $_->{type} =~ /serial/ and $modem->{device} = $_->{device} } } @modems; } sub getModem() { getSerialModem({}), matching_driver('www\.linmodems\.org'); } sub getSpeedtouch() { grep { $_->{description} eq 'Alcatel|USB ADSL Modem (Speed Touch)' } probeall(); } sub getBewan() { grep { $_->{description} =~ /Bewan Systems\|PCI ADSL Modem|BEWAN ADSL USB/ } probeall(); } sub getSagem() { grep { member($_->{driver}, qw(adiusbadsl eagle-usb)) } probeall(); } # generate from the following from eci driver sources: # perl -e 'while (<>) { print qq("$1$2",\n"$3$4",\n) if /\b([a-z\d]*)\s*([a-z\d]*)\s*([a-z\d]*)\s*([a-z\d]*)$/ }' {vendor}, $_->{id}, $_->{subvendor}, $_->{subid}), @ids) } usb_probe(); } sub getNet() { # we want LAN like interfaces here (eg: ath|br|eth|fddi|plip|tr|usb|wifi|wlan). # there's also bnep%d for bluetooth, bcp%d... # we do this by blacklisting the following interfaces: # - sit0 which is *always* created by net/ipv6/sit.c, thus is always created since net.agent loads ipv6 module # - ippp|isdn|plip|ppp (initscripts suggest that isdn%d can be created but kernel sources claim not) # ippp%d are created by drivers/isdn/i4l/isdn_ppp.c # plip%d are created by drivers/net/plip.c # ppp%d are created by drivers/net/ppp_generic.c # # we need both detection schemes since: # - get_netdevices() use the SIOCGIFCONF ioctl that does not list interfaces that are down # - /proc/net/dev does not list VLAN and IP aliased interfaces grep { !/^(?:lo|ippp|isdn|plip|ppp|sit0)/ } uniq( (map { if_(/^\s*([A-Za-z0-9:\.]*):\s/, $1) } cat_("/proc/net/dev")), c::get_netdevices(), ); } #sub getISDN() { # mapgrep(sub {member (($_[0] =~ /\s*(\w*):/), @netdevices), $1 }, split(/\n/, cat_("/proc/net/dev"))); #} # heavily inspirated from hidups driver from nut: sub getUPS() { # nut/driver/hidups.h: my $UPS_USAGE = 0x840004; my $POWER_USAGE = 0x840020; my $hiddev_find_application = sub { my ($fd, $usage) = @_; my $i = 0; my $ret; do { $i++ } while ($ret = ioctl($fd, c::HIDIOCAPPLICATION(), $i)) && $ret != $usage; return $ret == $usage ? 1 : 0; }; (map { $_->{driver} = "mge-shut"; $_ } grep { $_->{DESCRIPTION} =~ /MGE UPS/ } values %serialprobe), (map { open(my $f, $_); if_(!$hiddev_find_application->($f, $UPS_USAGE) && !$hiddev_find_application->($f, $POWER_USAGE), { port => $_, name => c::get_usb_ups_name(fileno($f)), driver => "hidups", } ); } -e "/dev/.devfsd" ? glob("/dev/usb/hid/hiddev*") : glob("/dev/usb/hiddev*")); } $pcitable_addons = <<'EOF'; # add here lines conforming the pcitable format (0xXXXX\t0xXXXX\t"\w+"\t".*") EOF $usbtable_addons = <<'EOF'; # add here lines conforming the usbtable format (0xXXXX\t0xXXXX\t"\w+"\t".*") EOF sub install_addons { my ($prefix) = @_; #- this test means install_addons can only be called after ldetect-lst has been installed. if (-d "$prefix/usr/share/ldetect-lst") { my $update = 0; foreach ([ 'pcitable.d', $pcitable_addons ], [ 'usbtable.d', $usbtable_addons ]) { my ($dir, $str) = @$_; -d "$prefix/usr/share/ldetect-lst/$dir" && $str =~ /^[^#]/m and $update = 1 and output "$prefix/usr/share/ldetect-lst/$dir/95drakx.lst", $str; } $update and run_program::rooted($prefix, "/usr/sbin/update-ldetect-lst"); } } sub add_addons { my ($addons, @l) = @_; foreach (split "\n", $addons) { /^\s/ and die qq(bad detect_devices::probeall_addons line "$_"); s/^#.*//; s/"(.*?)"/$1/g; next if /^$/; my ($vendor, $id, $driver, $description) = split("\t", $_, 4) or die qq(bad detect_devices::probeall_addons line "$_"); foreach (@l) { $_->{vendor} == hex $vendor && $_->{id} == hex $id or next; put_in_hash($_, { driver => $driver, description => $description }); } } @l; } sub pci_probe() { add_addons($pcitable_addons, map { my %l; @l{qw(vendor id subvendor subid pci_bus pci_device pci_function media_type driver description)} = split "\t"; $l{$_} = hex $l{$_} foreach qw(vendor id subvendor subid); $l{bus} = 'PCI'; \%l } c::pci_probe()); } sub usb_probe() { -e "/proc/bus/usb/devices" or return; add_addons($usbtable_addons, map { my %l; @l{qw(vendor id media_type driver description pci_bus pci_device)} = split "\t"; $l{media_type} = join('|', grep { $_ ne '(null)' } split('\|', $l{media_type})); $l{$_} = hex $l{$_} foreach qw(vendor id); $l{bus} = 'USB'; \%l } c::usb_probe()); } sub firewire_probe() { my ($e, @l); foreach (cat_('/proc/bus/ieee1394/devices')) { if (m!Vendor/Model ID: (.*) \[(\w+)\] / (.*) \[(\w+)\]!) { push @l, $e = { vendor => hex($2), id => hex($4), description => join('|', $1, $3), bus => 'Firewire', }; } elsif (/Software Specifier ID: (\w+)/) { $e->{specifier_id} = hex $1; } elsif (/Software Version: (\w+)/) { $e->{specifier_version} = hex $1; } } foreach (@l) { if ($e->{specifier_id} == 0x00609e && $e->{specifier_version} == 0x010483) { add2hash($_, { driver => 'sbp2', description => "Generic Firewire Storage Controller" }); } } @l; } sub pcmcia_probe() { -e '/var/run/stab' || -e '/var/lib/pcmcia/stab' or return (); my (@devs, $desc); foreach (cat_('/var/run/stab'), cat_('/var/lib/pcmcia/stab')) { if (/^Socket\s+\d+:\s+(.*)/) { $desc = $1; } else { my (undef, $type, $module, undef, $device) = split; push @devs, { description => $desc, driver => $module, type => $type, device => $device }; } } @devs; } # pcmcia_probe provides field "device", used in network.pm # => probeall with $probe_type is unsafe sub probeall() { return if $::noauto; require sbus_probing::main; pci_probe(), usb_probe(), firewire_probe(), pcmcia_probe(), sbus_probing::main::probe(); } sub matching_desc { my ($regexp) = @_; grep { $_->{description} =~ /$regexp/i } probeall(); } sub matching_driver { my ($regexp) = @_; grep { $_->{driver} =~ /$regexp/i } probeall(); } sub stringlist() { map { sprintf("%-16s: %s%s%s", $_->{driver} || 'unknown', $_->{description} eq '(null)' ? sprintf("Vendor=0x%04x Device=0x%04x", $_->{vendor}, $_->{id}) : $_->{description}, $_->{media_type} ? sprintf(" [%s]", $_->{media_type}) : '', $_->{subid} && $_->{subid} != 0xffff ? sprintf(" SubVendor=0x%04x SubDevice=0x%04x", $_->{subvendor}, $_->{subid}) : '', ) } probeall(); } sub tryOpen($) { my $F; sysopen($F, devices::make($_[0]), c::O_NONBLOCK()) && $F; } sub tryWrite($) { my $F; sysopen($F, devices::make($_[0]), 1 | c::O_NONBLOCK()) && $F; } sub syslog() { -r "/tmp/syslog" and return map { /<\d+>(.*)/ } cat_("/tmp/syslog"); my $LD_LOADER = $ENV{LD_LOADER} || ""; `$LD_LOADER /bin/dmesg`; } sub get_mac_model() { my $mac_model = cat_("/proc/device-tree/model") || die "Can't open /proc/device-tree/model"; log::l("Mac model: $mac_model"); $mac_model; } sub get_mac_generation() { my $generation = cat_("/proc/cpuinfo") || die "Can't open /proc/cpuinfo"; my @genarray = split(/\n/, $generation); my $count = 0; while ($count <= @genarray) { if ($genarray[$count] =~ /pmac-generation/) { @genarray = split(/:/, $genarray[$count]); return $genarray[1]; } $count++; } return "Unknown Generation"; } sub hasSMP() { return if $::testing; c::detectSMP() || any { /\bProcessor #(\d+)\s+(\S*)/ && $1 > 0 && $2 ne 'invalid' } syslog(); } sub hasPCMCIA() { $::o->{pcmcia} } #- because /proc/pcmcia seems not to be present on 2.4 at least (or use /var/run/stab) #- try to detect a laptop, we assume pcmcia service is an indication of a laptop or #- the following regexp to match graphics card apparently only used for such systems. sub isLaptop() { hasPCMCIA() || (matching_desc('C&T.*655[45]\d') || matching_desc('C&T.*68554') || matching_desc('Neomagic.*Magic(Media|Graph)') || matching_desc('ViRGE.MX') || matching_desc('S3.*Savage.*[IM]X') || matching_desc('ATI.*(Mobility|LT)')) || cat_('/proc/cpuinfo') =~ /\bmobile\b/i; } sub usbMice() { grep { $_->{media_type} =~ /\|Mouse/ && $_->{driver} !~ /Tablet:wacom/ || $_->{driver} =~ /Mouse:USB/ } usb_probe() } sub usbWacom() { grep { $_->{driver} =~ /Tablet:wacom/ } usb_probe() } sub usbKeyboards() { grep { $_->{media_type} =~ /\|Keyboard/ } usb_probe() } sub usbStorage() { grep { $_->{media_type} =~ /Mass Storage\|/ } usb_probe() } sub usbKeyboard2country_code { my ($usb_kbd) = @_; my ($F, $tmp); sysopen($F, sprintf("/proc/bus/usb/%03d/%03d", $usb_kbd->{pci_bus}, $usb_kbd->{pci_device}), 0) and sysseek $F, 0x28, 0 and sysread $F, $tmp, 1 and unpack("C", $tmp); } sub probeSerialDevices() { foreach (0..3) { #- make sure the device are created before probing, devices::make("/dev/ttyS$_"); #- and make sure the device is a real terminal (major is 4). int((stat "/dev/ttyS$_")[6]/256) == 4 or $serialprobe{"/dev/ttyS$_"} = undef; } #- for device already probed, we can safely (assuming device are #- not moved during install :-) #- include /dev/mouse device if using an X server. mkdir_p("/var/lock"); -l "/dev/mouse" and $serialprobe{"/dev/" . readlink "/dev/mouse"} = undef; foreach (keys %serialprobe) { m|^/dev/(.*)| and touch "/var/lock/LCK..$1" } print STDERR "Please wait while probing serial ports...\n"; #- start probing all serial ports... really faster than before ... #- ... but still take some time :-) my %current; foreach (run_program::get_stdout('serial_probe')) { if (/^\s*$/) { $serialprobe{$current{DEVICE}} = { %current } if $current{DEVICE}; %current = (); } elsif (/^([^=]+)=(.*?)\s*$/) { $current{$1} = $2; } } foreach (values %serialprobe) { $_->{DESCRIPTION} =~ /modem/i and $_->{CLASS} = 'MODEM'; #- hack to make sure a modem is detected. $_->{DESCRIPTION} =~ /olitec/i and $_->{CLASS} = 'MODEM'; #- hack to make sure such modem gets detected. log::l("probed $_->{DESCRIPTION} of class $_->{CLASS} on device $_->{DEVICE}"); } } sub probeSerial($) { $serialprobe{$_[0]} } sub hasModem($) { $serialprobe{$_[0]} && $serialprobe{$_[0]}{CLASS} eq 'MODEM' && $serialprobe{$_[0]}{DESCRIPTION}; } sub hasMousePS2 { my $t; sysread(tryOpen($_[0]) || return, $t, 256) != 1 || $t ne "\xFE"; } sub raidAutoStartIoctl() { sysopen(my $F, devices::make("md0"), 2) or return; ioctl $F, 0x914, 0; #- RAID_AUTORUN } sub raidAutoStartRaidtab { my (@parts) = @_; $::isInstall or return; require raid; #- faking a raidtab, it seems to be working :-))) #- (choosing any inactive md) raid::inactivate_all(); my $detect_one = sub { my ($device) = @_; my $free_md = devices::make(find { !raid::is_active($_) } map { "md$_" } 0 .. raid::max_nb()); output("/tmp/raidtab", "raiddev $free_md\n device " . devices::make($device) . "\n"); log::l("raidAutoStartRaidtab: trying $device"); run_program::run('raidstart', '-c', "/tmp/raidtab", $free_md); }; $detect_one->($_->{device}) foreach @parts; #- try again to detect RAID 10 $detect_one->($_) foreach raid::active_mds(); unlink "/tmp/raidtab"; } sub raidAutoStart { my (@parts) = @_; log::l("raidAutoStart"); eval { modules::load('md') }; my %personalities = ('1' => 'linear', '2' => 'raid0', '3' => 'raid1', '4' => 'raid5'); raidAutoStartIoctl() or raidAutoStartRaidtab(@parts); foreach (1..2) { #- try twice for RAID 10 my @needed_perso = map { if_(/^kmod: failed.*md-personality-(.)/ || /^md: personality (.) is not loaded/, $personalities{$1}) } syslog() or last; eval { modules::load(@needed_perso) }; raidAutoStartIoctl() or raidAutoStartRaidtab(@parts); } } sub usb_description2removable { local ($_) = @_; return 'camera' if /\bcamera\b/i; return 'memory_card' if /\bmemory\s?stick\b/i || /\bcompact\s?flash\b/i || /\bsmart\s?media\b/i; return 'memory_card' if /DiskOnKey/i || /IBM-DMDM/i; return 'zip' if /\bzip\s?(100|250|750)/i; return 'floppy' if /\bLS-?120\b/i; return; } sub usb2removable { my ($e) = @_; $e->{usb_driver} or return; if ($e->{usb_driver} =~ /Removable:(.*)/) { return $1; } elsif (my $name = usb_description2removable($e->{usb_description})) { return $name; } undef; } sub suggest_mount_point { my ($e) = @_; my $name = $e->{media_type}; if (member($name, 'hd', 'fd')) { if (exists $e->{usb_driver}) { return usb2removable($e) || 'removable'; } if (isZipDrive($e)) { $name = 'zip'; } elsif ($name eq 'fd') { $name = 'floppy'; } else { log::l("suggest_mount_point: don't know what to with hd $e->{device}"); } } $name; } 1; ef='#n656'>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 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
package install_steps; # $Id$

use diagnostics;
use strict;
use vars qw(@filesToSaveForUpgrade @filesNewerToUseAfterUpgrade @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
);

@filesNewerToUseAfterUpgrade = qw(
/etc/profile
);

#-######################################################################################
#- 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/drakx") {
	eval { cp_af("/tmp/ddebug.log", "$o->{prefix}/root/drakx") };
	output(install_any::auto_inst_file(), install_any::g_auto_install(1));
    }

    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(N("Error"), [
N("An error occurred, but I don't know how to handle it nicely.
Continue at your own risk."), formatError($@) ]) if $@;
    }
}

sub errorInStep { 
    my ($_o, $_err) = @_;
    print "error :(\n"; 
    c::_exit(1);
}
sub kill_action {}

#-######################################################################################
#- Steps Functions
#-######################################################################################
#------------------------------------------------------------------------------
sub selectLanguage {
    my ($o) = @_;

    #- for auto_install compatibility with old $o->{lang}
    $o->{locale} = lang::system_locales_to_ourlocale($o->{lang}, $o->{lang}) if $o->{lang};

    lang::set($o->{locale}{lang}, !$o->isa('interactive::gtk'));
    $o->{locale}{langs} ||= { $o->{locale}{lang} => 1 };

    if (!exists $o->{locale}{country}) {
	$o->{locale}{country} = $1 if lang::l2locale($o->{locale}{lang}) =~ /^.._(..)/;
    }

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

    #- for auto_install compatibility with old $o->{keyboard} containing directly $o->{keyboard}{KEYBOARD}
    $o->{keyboard} = { KEYBOARD => $o->{keyboard} } if $o->{keyboard} && !ref($o->{keyboard});

    if (!$o->{keyboard} || $o->{keyboard}{unsafe}) {
	$o->{keyboard} = keyboard::from_usb() || keyboard::lang2keyboard($o->{locale}{lang});
	$o->{keyboard}{unsafe} = 1;
	keyboard::setup($o->{keyboard}) if !$::live;
    }

    addToBeDone {
	lang::write_langs($o->{prefix}, $o->{locale}{langs});
    } 'formatPartitions' unless $::g_auto_install;
    addToBeDone {
	lang::write($o->{prefix}, $o->{locale});
    } 'installPackages' unless $::g_auto_install;
}
#------------------------------------------------------------------------------
sub selectKeyboard {
    my ($o) = @_;
    $o->{keyboard}{KBCHARSET} = lang::l2charset($o->{locale}{lang});
    keyboard::setup($o->{keyboard});

    addToBeDone {
	keyboard::write($o->{keyboard});
    } 'installPackages' if !$::g_auto_install && (!$o->{isUpgrade} || !$o->{keyboard}{unsafe});

    if ($o->{raw_X}) {
	require Xconfig::default;
	Xconfig::default::config_keyboard($o->{raw_X}, $o->{keyboard});
	$o->{raw_X}->write;
    }
}
#------------------------------------------------------------------------------
sub acceptLicense {}

#------------------------------------------------------------------------------
sub setupSCSI {
    my ($o) = @_;
    modules::configure_pcmcia($o->{pcmcia}) if $o->{pcmcia};
    modules::load_ide();
    modules::load_category('bus/firewire');
    modules::load_category('disk/scsi|hardware_raid|firewire');

    install_any::getHds($o, $o);
}

#------------------------------------------------------------------------------
sub selectInstallClass {
    my ($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})) || die)->{part};
	install_any::use_root_part($o->{all_hds}, $p, $o->{prefix});
    } 
}

#------------------------------------------------------------------------------
sub doPartitionDisksBefore {
    my ($o) = @_;
    eval { 
	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;
}

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

    if (!$::testing) {
	my $hds = $o->{all_hds}{hds};
	partition_table::write($_) foreach @$hds;
	$_->{rebootNeeded} and $o->rebootNeeded foreach @$hds;
    }

    fs::set_removable_mntpoints($o->{all_hds});
    fs::set_all_default_options($o->{all_hds}, %$o, lang::fs_options($o->{locale}))
	if !$o->{isUpgrade};

    $o->{fstab} = [ fsedit::get_all_fstab($o->{all_hds}) ];
    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->{all_hds})) {
	die \N("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 sort { $a->{mntpoint} cmp $b->{mntpoint} }
						 grep { $_->{mntpoint} && maybeFormatted($_) } @{$o->{fstab}};
    }

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

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

    if ($o->{partitioning}{auto_allocate}) {
	fsedit::auto_allocate($o->{all_hds}, $o->{partitions});
    }
}

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

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

    #- TODO: set the mntpoints

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

	next if !$m || $m eq 'swap'; #- there may be a lot of swap.

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

	#- in case the type does not correspond, force it to ext3
	$_->{type} = 0x483 if $m =~ m|^/| && !isTrueFS($_) && !isOtherAvailableFS($_);
    }
    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} });
        $_->{toFormatUnsure} = member($_->{mntpoint}, '/', '/usr');

	if (!$_->{toFormat}) {
	    my $t = fsedit::typeOfPart($_->{device});
	    $_->{toFormatUnsure} ||=
	      #- 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->{all_hds}{raids}, $o->{fstab}, $o->{prefix});
}

#------------------------------------------------------------------------------
sub setPackages {
    my ($o, $rebuild_needed) = @_;

    install_any::setPackages($o, $rebuild_needed);
    pkgs::selectPackagesAlreadyInstalled($o->{packages}, $o->{prefix});
    $rebuild_needed and pkgs::selectPackagesToUpgrade($o->{packages}, $o->{prefix});
}

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) {
	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 { cp_af("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgisave") };
	    }
	}
	foreach (@filesNewerToUseAfterUpgrade) {
	    unlink "$o->{prefix}/$_.rpmnew";
	}
    }

    #- 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");

    log::l("setting excludedocs to $o->{excludedocs}");
    substInFile { s/%_excludedocs.*//; $_ .= "%_excludedocs yes\n" if eof && $o->{excludedocs} } "$o->{prefix}/etc/rpm/macros";

    mkdir "$o->{prefix}$_" foreach qw(/boot /usr /usr/share /usr/share/mdk /usr/share/bootsplash);
    #- add oem lilo theme and background if the files exists.
    install_any::getAndSaveFile("Mandrake/base/oem-message-graphic", "$o->{prefix}/boot/oem-message-graphic");
    install_any::getAndSaveFile("Mandrake/base/oem-background.png", "$o->{prefix}/usr/share/mdk/oem-background.png");
    #- add oem bootsplash theme if files exists.
    foreach (qw(oem-message-graphic oem-bootsplash-800x600.jpg oem-bootsplash-1024x768.jpg oem-bootsplash-1200x1024.jpg
                oem-bootsplash-1600x1200.jpg)) {
	install_any::getAndSaveFile("Mandrake/base/$_", "$o->{prefix}/usr/share/bootsplash/$_");
    }
}

sub pkg_install {
    my ($o, @l) = @_;
    log::l("selecting packages ".join(" ", @l));
    require pkgs;
    if ($::testing) {
	log::l("selecting package \"$_\"") foreach @l;
    } else {
	$o->{packages}{rpmdb} ||= pkgs::rpmDbOpen($o->{prefix});
	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;
    $o->{packages}{rpmdb} ||= pkgs::rpmDbOpen($o->{prefix});
    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};

    #- this method is always called, go here to close still opened rpm db.
    delete $packages->{rpmdb};

    if (%{$packages->{state}{ask_remove} || {}}) {
	log::l("removing : ", join ', ', keys %{$packages->{state}{ask_remove}});
	pkgs::remove($o->{prefix}, [ keys %{$packages->{state}{ask_remove}} ], $packages);
    }

    #- 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);
    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 \N("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 any { m|read failed: Input/output error| } cat_("$o->{prefix}/root/drakx/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";
    }

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

    my $have_devfsd = do {
	my $p = pkgs::packageByName($o->{packages}, 'devfsd');
	$p && $p->flag_installed
    };
    if ($have_devfsd) {
        require bootloader;
	bootloader::may_append($o->{bootloader}, devfs => 'mount');
    }

    #- 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";

    any::config_dvd($o->{prefix}, $have_devfsd);
    any::config_mtools($o->{prefix});

    any::writeandclean_ldsoconf($o->{prefix});

    #- make sure wins is disabled in /etc/nsswitch.conf
    #- else if eth0 is not existing, glibc segfaults.
    substInFile { s/\s*wins// if /^\s*hosts\s*:/ } "$o->{prefix}/etc/nsswitch.conf";

    #- make sure some services have been enabled (or a catastrophic restart will occur).
    #- these are normally base package post install scripts or important services to start.
    run_program::rooted($o->{prefix}, "chkconfig", "--add", $_) foreach
			qw(random netfs network rawdevices sound kheader keytable syslog crond portmap);

    if ($o->{mouse}{device} =~ /ttyS/) {
	log::l("disabling gpm for serial mice (doesn't get along nicely with X)");
	run_program::rooted($o->{prefix}, "chkconfig", "--del", "gpm") 
    }

    #- update menu scheme before calling update menus if desktop mode.
    if ($o->{meta_class} eq 'desktop') {
	run_program::rooted($o->{prefix}, "touch", "/etc/menu/do-not-create-menu-link");
	run_program::rooted($o->{prefix}, "touch", "/etc/menu/enable_simplified");
    } elsif (!$o->{isUpgrade}) {
	run_program::rooted($o->{prefix}, "touch", "/etc/menu/do-not-create-menu-link");
    }
    #- call update-menus at the end of package installation
    run_program::rooted($o->{prefix}, "update-menus");

    if ($o->{pcmcia}) {
	substInFile { s/.*(TaskBarShowAPMStatus).*/$1=1/ } "$o->{prefix}/usr/lib/X11/icewm/preferences";
	eval { cp_af("$o->{prefix}/usr/share/applnk/System/kapm.kdelnk",
		     "$o->{prefix}/etc/skel/Desktop/Autostart/kapm.kdelnk") };
    }

    if ($o->{brltty}) {
	output("$o->{prefix}/etc/brltty.conf", <<EOF);
braille-driver $o->{brltty}{driver}
braille-device $o->{brltty}{device}
text-table $o->{brltty}{table}
EOF
    }

    $o->install_urpmi;

    if ($o->{locale}{lang} =~ /^(zh_TW|th|vi|be|bg)/) {
	#- skip since we don't have the right font (it badly fails at least for zh_TW)
    } else {
	my $kde_charset = lang::charset2kde_charset(lang::l2charset($o->{locale}{lang}));
	my $welcome = c::to_utf8(N("Welcome to %s", '%n'));
	substInFile { 
	    s/^(GreetString)=.*/$1=$welcome/;
	    s/^(Language)=.*/$1=$o->{locale}{lang}/;
	    if (!member($kde_charset, 'iso8859-1', 'iso8859-15')) { 
		#- don't keep the default for those
		s/^(StdFont)=.*/$1=*,12,5,$kde_charset,50,0/;
		s/^(FailFont)=.*/$1=*,12,5,$kde_charset,75,0/;
		s/^(GreetFont)=.*/$1=*,24,5,$kde_charset,50,0/;
	    }
	} "$o->{prefix}/usr/share/config/kdm/kdmrc";

    }
    install_any::disable_user_view() if $o->{security} >= 3 || $o->{authentication}{NIS};
    run_program::rooted($o->{prefix}, "kdeDesktopCleanup");

    foreach (list_skels($o->{prefix}, '.kde/share/config/kfmrc')) {
	my $found;
	substInFile {
	    $found ||= /KFM Misc Defaults/;
	    $_ .= 
"[KFM Misc Defaults]
GridWidth=85
GridHeight=70
" if eof && !$found;
	} $_ 
    }

    #- move some file after an upgrade that may be seriously annoying.
    #- and rename saved files to .mdkgiorig.
    if ($o->{isUpgrade}) {
	my $pkg = pkgs::packageByName($o->{packages}, 'rpm');
	$pkg && ($pkg->flag_selected || $pkg->flag_installed) && $pkg->compare(">= 4.0") and pkgs::cleanOldRpmDb($o->{prefix});

	log::l("moving previous desktop files that have been updated to Trash of each user");
	install_any::kdemove_desktop_file($o->{prefix});

	foreach (@filesToSaveForUpgrade) {
	    renamef("$o->{prefix}/$_.mdkgisave", "$o->{prefix}/$_.mdkgiorig")
	      if -e "$o->{prefix}$_.mdkgisave";
	}

	foreach (@filesNewerToUseAfterUpgrade) {
	    if (-e "$o->{prefix}/$_.rpmnew" && -e "$o->{prefix}/$_") {
		renamef("$o->{prefix}/$_", "$o->{prefix}/$_.mdkgiorig");
		renamef("$o->{prefix}/$_.rpmnew", "$o->{prefix}/$_");
	    }
	}
    }

    #- fix bad update-alternatives that may occurs after upgrade (but let them for install too).
    if (-d "$o->{prefix}/etc/alternatives") {
	foreach (all("$o->{prefix}/etc/alternatives")) {
	    next if run_program::rooted($o->{prefix}, 'test', '-e', "/etc/alternatives/$_");
	    log::l("fixing broken alternative $_");
	    run_program::rooted($o->{prefix}, "update-alternatives", "--auto", $_);
	}
    }

    #- update oem lilo image if it exists.
    if (-s "$o->{prefix}/boot/oem-message-graphic") {
	rename "$o->{prefix}/boot/message-graphic", "$o->{prefix}/boot/message-graphic.mdkgiorig";
	rename "$o->{prefix}/boot/oem-message-graphic", "$o->{prefix}/boot/message-graphic";
    }

    #- update background image if it exists for common environment.
    if (-s "$o->{prefix}/usr/share/mdk/oem-background.png") {
	if (-e "$o->{prefix}/usr/share/mdk/backgrounds/default.png") {
	    rename "$o->{prefix}/usr/share/mdk/backgrounds/default.png",
	           "$o->{prefix}/usr/share/mdk/backgrounds/default.png.mdkgiorig";
	    rename "$o->{prefix}/usr/share/mdk/oem-background.png", "$o->{prefix}/usr/share/mdk/backgrounds/default.png";
	} else {
	    #- KDE desktop background.
	    if (-e "$o->{prefix}/usr/share/config/kdesktoprc") {
		update_gnomekderc("$o->{prefix}/usr/share/config/kdesktoprc", "Desktop0",
				  MultiWallpaperMode => "NoMulti",
				  Wallpaper => "/usr/share/mdk/oem-background.png",
				  WallpaperMode => "Scaled",
				 );
	    }
	    #- GNOME desktop background.
	    if (-e "$o->{prefix}/etc/gnome/config/Background") {
		update_gnomekderc("$o->{prefix}/etc/gnome/config/Background", "Default",
				  wallpaper => "/usr/share/mdk/oem-background.png",
				  wallpaperAlign => "3",
				 );
	    }
	}
    }

    #- modifying Mandrake theme directly, all image may not be available.
    if (-e "$o->{prefix}/usr/share/bootsplash/themes/Mandrake/lilo/message" &&
	-e "$o->{prefix}/usr/share/bootsplash/oem-message-graphic") {
	rename "$o->{prefix}/usr/share/bootsplash/themes/Mandrake/lilo/message",
	  "$o->{prefix}/usr/share/bootsplash/message.mdkgiorig";
	rename "$o->{prefix}/usr/share/bootsplash/oem-message-graphic",
	  "$o->{prefix}/usr/share/bootsplash/themes/Mandrake/lilo/message";
    }
    my $redo_bootsplash;
    foreach (qw(oem-bootsplash-800x600.jpg oem-bootsplash-1024x768.jpg oem-bootsplash-1200x1024.jpg
                oem-bootsplash-1600x1200.jpg)) {
	if (-e "$o->{prefix}/usr/share/bootsplash/themes/Mandrake/images/$_" && "$o->{prefix}/usr/share/bootsplash/$_") {
	    rename "$o->{prefix}/usr/share/bootsplash/themes/Mandrake/images/$_", "$o->{prefix}/usr/share/bootsplash/$_.mdkgiorig";
	    rename "$o->{prefix}/usr/share/bootsplash/$_", "$o->{prefix}/usr/share/bootsplash/themes/Mandrake/images/$_";
	    ++$redo_bootsplash;
	}
    }
    if ($redo_bootsplash && -x "$o->{prefix}/usr/share/loader/make-initrd") {
	#- redo bootsplash installation for changes to take effects...
	run_program::rooted($o->{prefix}, "/usr/share/loader/make-initrd", "-n");
    }

    if ($o->{blank} || $o->{updatemodules}) {
	my @l = detect_devices::floppies_dev();

	foreach (qw(blank updatemodules)) {
	    $o->{$_} eq "1" and $o->{$_} = $l[0] || die \N("No floppy drive available");
	}

	$o->{blank} and $o->copyKernelFromFloppy;
	$o->{updatemodules} and $o->updateModulesFromFloppy;
    }
}

sub copyKernelFromFloppy {
    my ($o) = @_;
    return if $::testing || !$o->{blank};

    fs::mount($o->{blank}, "/floppy", "vfat", 0);
    eval { cp_af("/floppy/vmlinuz", "$o->{prefix}/boot/vmlinuz-default") };
    if ($@) {
	log::l("copying of /floppy/vmlinuz from blank modified disk failed: $@");
    }
    fs::umount("/floppy");
}

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

    my $pkg = pkgs::packageByName($o->{packages}, 'urpmi');
    if ($pkg && ($pkg->flag_selected || $pkg->flag_installed)) {
	install_any::install_urpmi($o->{prefix}, 
				   $::oem ? 'cdrom' : $o->{method}, #- HACK
				   $o->{packages},
				   $o->{packages}{mediums});
	pkgs::saveCompssUsers($o->{prefix}, $o->{packages}, $o->{compssUsers}, $o->{compssUsersSorted});
    }
}

sub updateModulesFromFloppy {
    my ($o) = @_;
    return if $::testing || !$o->{updatemodules};

    fs::mount($o->{updatemodules}, "/floppy", "ext2", 0);
    foreach (glob_("$o->{prefix}/lib/modules/*")) {
	my ($kernelVersion) = m,lib/modules/(\S*),;
	log::l("examining updated modules for kernel $kernelVersion");
	if (-d "/floppy/$kernelVersion") {
	    my @src_files = glob_("/floppy/$kernelVersion/*");
	    my @dest_files = map { chomp_($_) } run_program::rooted_get_stdout($o->{prefix}, 'find', '/lib/modules');
	    foreach my $s (@src_files) {
		log::l("found updatable module $s");
		my ($sfile, $sext) = $s =~ m!([^/\.]*\.o)(?:\.gz|\.bz2)?$!;
		my $qsfile = quotemeta $sfile;
		my $qsext = quotemeta $sext;
		foreach my $target (@dest_files) {
		    $target =~ /$qsfile/ or next;
		    eval { cp_af($s, $target) };
		    if ($@) {
			log::l("updating module $target by $s failed: $@");
		    } else {
			log::l("updating module $target by $s");
		    }
		    if ($target !~ /$qsfile$qsext$/) {
			#- extension differ, first rename target file correctly,
			#- then uncompress source file, then compress it as expected.
			my ($basetarget, $text) = $target =~ /(.*?)(\.gz|\.bz2)$/;
			rename $target, "$basetarget$sext";
			$sext eq '.gz' and run_program::run("gzip", "-d", "$basetarget$sext");
			$sext eq '.bz2' and run_program::run("bzip2", "-d", "$basetarget$sext");
			$text eq '.gz' and run_program::run("gzip", $basetarget);
			$text eq '.bz2' and run_program::run("bzip2", $basetarget);
		    }
		}
	    }
	}
    }
    fs::umount("/floppy");
}

#------------------------------------------------------------------------------
sub selectMouse($) {
    my ($_o) = @_;
}

#------------------------------------------------------------------------------
sub configureNetwork {
    my ($o) = @_;
    require network;
    network::configureNetwork2($o, $o->{prefix}, $o->{netc}, $o->{intf});
    if ($o->{method} =~ /ftp|http|nfs/) {
	$o->{netcnx}{type} = 'lan';
	foreach ("up", "down") {
	    my $f = "$o->{prefix}/etc/sysconfig/network-scripts/net_cnx_$_";
	    output_with_perm($f, 0755, "\nif$_ eth0\n");
	}
	output "$o->{prefix}/etc/sysconfig/network-scripts/net_cnx_pg", "\n/usr/sbin/drakconnect\n";

	require network::netconnect;
	$o->{netcnx}{$_} = $o->{netc}{$_} foreach qw(NET_DEVICE NET_INTERFACE);
	$o->{netcnx}{NET_INTERFACE} and network::netconnect::set_net_conf($o->{netcnx}, $o->{netc});
	network::netconnect::save_conf($o->{netcnx});
    }
}

#------------------------------------------------------------------------------
sub installUpdates {
    my ($o) = @_;
    my $u = $o->{updates} or return; $u->{updates} or return;

    upNetwork($o);
    require crypto;
    crypto::getPackages($o->{prefix}, $o->{packages}, $u->{mirror}) and
	$o->pkg_install(@{$u->{packages} || []});

    #- re-install urpmi with update security medium.
    $o->install_urpmi;
}

sub summaryBefore {}

sub summary {
    my ($o) = @_;
    configureTimezone($o);
    configurePrinter($o) if $o->{printer};
}

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

    require bootloader;
    bootloader::get_append($o->{bootloader}, 'acpi') ne 'off' && !(-x "$::prefix/usr/bin/acpi" && -x "$::prefix/usr/sbin/acpid")
	and $o->do_pkgs->install(qw(acpi acpid));
}

#------------------------------------------------------------------------------
sub configureTimezone {
    my ($o) = @_;
    install_any::preConfigureTimezone($o);

    $o->pkg_install('ntp') if $o->{timezone}{ntp};

    require timezone;
    timezone::write($o->{prefix}, $o->{timezone});
}

#------------------------------------------------------------------------------
sub configureServices {
    my ($o) = @_;
    if ($o->{services}) {
	require services;
	services::doit($o, $o->{services});
    }
}
#------------------------------------------------------------------------------
sub configurePrinter {
    my ($o) = @_;
    $o->do_pkgs->install('foomatic-filters', 'foomatic-db-engine', 'foomatic-db', 'printer-utils', 'printer-testpages',
			 if_($o->do_pkgs->is_installed('gimp'), 'gimpprint'));
    
    require printer::main;
    eval { add2hash($o->{printer} ||= {}, printer::main::getinfo($o->{prefix})) }; #- get existing configuration.

    require printer::printerdrake;
    printer::printerdrake::install_spooler($o->{printer}, $o); #- not interactive...

    foreach (values %{$o->{printer}{configured} || {}}) {
	log::l("configuring printer queue " . $_->{queuedata}{queue} || $_->{QUEUE});
	#- when copy is so adulée (sorry french taste :-)
	#- and when there are some configuration in one place and in another place...
	$o->{printer}{currentqueue} = {};
	printer::main::copy_printer_params($_->{queuedata}, $o->{printer}{currentqueue});
	printer::main::copy_printer_params($_, $o->{printer});
	#- setup all configured queues, which is not the case interactively where
	#- only the working queue is setup on configuration.
	printer::main::configure_queue($o->{printer});
    }
}

#------------------------------------------------------------------------------
sub setRootPassword {
    my ($o) = @_;
    $o->{superuser} ||= {};
    $o->{superuser}{name} = 'root';
    any::write_passwd_user($o->{superuser}, $o->{authentication}{md5});
    delete $o->{superuser}{name};
    install_any::set_authentication($o);
}

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

sub addUser {
    my ($o) = @_;
    my $users = $o->{users} ||= [];

    my (%uids, %gids); 
    foreach (glob_("$::prefix/home")) { my ($u, $g) = (stat($_))[4,5]; $uids{$u} = 1; $gids{$g} = 1 }

    foreach (@$users) {
	$_->{home} ||= "/home/$_->{name}";

	my $u = $_->{uid} || ($_->{oldu} = (stat("$::prefix$_->{home}"))[4]) || int getpwnam($_->{name});
	my $g = $_->{gid} || ($_->{oldg} = (stat("$::prefix$_->{home}"))[5]) || int getgrnam($_->{name});
	#- search for available uid above 501 else initscripts may fail to change language for KDE.
	if (!$u || getpwuid($u)) { for ($u = 501; getpwuid($u) || $uids{$u}; $u++) {} }
	if (!$g)                 { for ($g = 501; getgrgid($g) || $gids{$g}; $g++) {} }
	
	$_->{uid} = $u; $uids{$u} = 1;
	$_->{gid} = $g; $gids{$g} = 1;
    }

    any::write_passwd_user($_, $o->{authentication}{md5}) foreach @$users;

    append_to_file("$::prefix/etc/group",
		   map { "$_->{name}:x:$_->{gid}:\n" } grep { ! getgrgid($_->{gid}) } @$users);

    foreach my $u (@$users) {
	if (! -d "$::prefix$u->{home}") {
	    my $mode = $o->{security} < 2 ? 0755 : 0750;
	    eval { cp_af("$::prefix/etc/skel", "$::prefix$u->{home}") };
	    if ($@) {
		log::l("copying of skel failed: $@"); mkdir("$::prefix$u->{home}", $mode); 
	    } else {
		chmod $mode, "$::prefix$u->{home}";
	    }
	}
	require commands;
	eval { commands::chown_("-r", "$u->{uid}.$u->{gid}", "$::prefix$u->{home}") }
	    if $u->{uid} != $u->{oldu} || $u->{gid} != $u->{oldg};
    }
    #- since we wrote the password in /etc/passwd, we must convert to shadow
    run_program::rooted($::prefix, 'pwconv') if $o->{authentication}{shadow};

    any::addUsers($users);

    $o->pkg_install("autologin") if $o->{autologin};
    any::set_autologin($o->{autologin}, $o->{desktop});

    install_any::disable_user_view() if @$users == ();
}