summaryrefslogtreecommitdiffstats
path: root/perl-install/modules.pm
blob: 8e5e19288a65128ff955833a33f17558fb443bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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
package modules; # $Id$

use strict;
use vars qw(%conf %mappings_24_26 %mappings_26_24);

use common;
use detect_devices;
use run_program;
use log;
use list_modules;

%conf = ();

sub modules_descriptions() {
    my $f = '/lib/modules/' . c::kernel_version() . '/modules.description';
    -e $f or $f = '/lib/modules.description';
    map { /(\S+)\s+(.*)/ } cat_($f);
}

sub module2description { +{ modules_descriptions() }->{$_[0]} }

sub category2modules_and_description {
    my ($categories) = @_;
    my %modules_descriptions = modules_descriptions();
    map { $_ => $modules_descriptions{$_} } category2modules($categories);
}

%mappings_24_26 = ("usb-ohci" => "ohci-hcd",
                   "usb-uhci" => "uhci-hcd",
                   "uhci" => "uhci-hcd",
                   "printer" => "usblp",
                   "bcm4400" => "b44",
                   "3c559" => "3c359",
                   "3c90x" => "3c59x",
                   "dc395x_trm" => "dc395x");
%mappings_26_24 = reverse %mappings_24_26;
sub mapping_24_26 {
    return map { c::kernel_version() =~ /^\Q2.6/ ? $mappings_24_26{$_} || $_ : $_ } @_;
}
sub mapping_26_24 {
    my ($modname) = @_;
    if (c::kernel_version() =~ /^\Q2.6/) {
        if ($modname eq 'uhci-hcd') {
            return 'usb-uhci';
        } else {
            return $mappings_26_24{$modname} || $modname;
        }
    }
    $modname;
}

#-###############################################################################
#- module loading
#-###############################################################################
# handles dependencies
# eg: load('vfat', 'reiserfs', [ ne2k => 'io=0xXXX', 'dma=5' ])
sub load {
    #- keeping the order of modules
    my %options;
    my @l = map {
	my ($name, @options) = ref($_) ? @$_ : $_;
	$options{$name} = \@options;
	dependencies_closure(mapping_24_26($name));
    } @_;

    @l = difference2([ uniq(@l) ], [ map { my $s = $_; $s =~ s/_/-/g; $s, $_ } loaded_modules() ]) or return;

    my $network_module = do {
	my ($network_modules, $other) = partition { module2category($_) =~ m,network/(main|gigabit|usb|wireless), } @l;
	if (@$network_modules > 1) {
	    # do it one by one
	    load($_) foreach @$network_modules;
	    load(@$other);
	    return;
	}
	$network_modules->[0];
    };
    my @network_devices = $network_module ? detect_devices::getNet() : ();

    if ($::testing || $::blank) {
	log::l("i would load module $_ (" . join(" ", @{$options{$_}}) . ")") foreach @l;
    } elsif ($::isStandalone || $::move) {
	run_program::run('/sbin/modprobe', $_, @{$options{$_}}) 
	  or !run_program::run('/sbin/modprobe', '-n', $_) #- ignore missing modules
	  or die "insmod'ing module $_ failed" foreach @l;
    } else {
	load_raw(map { [ $_ => $options{$_} ] } @l);
    }
    sleep 2 if any { /^(usb-storage|mousedev|printer)$/ } @l;

    if ($network_module) {
	add_alias($_, $network_module) foreach difference2([ detect_devices::getNet() ], \@network_devices);
    }
    when_load($_, @{$options{$_}}) foreach @l;
}

sub unload {
    if ($::testing) {
	log::l("rmmod $_") foreach @_;
    } else {
	run_program::run("rmmod", $_) foreach @_;
    }
}

sub load_category {
    my ($category, $o_wait_message) = @_;

    #- probe_category returns the PCMCIA cards. It doesn't know they are already
    #- loaded, so:
    read_already_loaded();

    my @try_modules = (
      if_($category =~ /scsi/,
	  if_(arch() !~ /ppc/, 'imm', 'ppa'),
	  if_(detect_devices::usbStorage(), 'usb-storage'),
      ),
      if_(arch() =~ /ppc/, 
	  if_($category =~ /scsi/, 'mesh', 'mac53c94'),
	  if_($category =~ /net/, 'bmac', 'gmac', 'mace', 'airport'),
	  if_($category =~ /sound/, 'dmasound_pmac'),
      ),
    );
    grep {
	$o_wait_message->($_->{description}, $_->{driver}) if $o_wait_message;
	eval { load([ $_->{driver}, if_($_->{options}, $_->{options}) ]) };
	$_->{error} = $@;

	$_->{try} = 1 if member($_->{driver}, 'hptraid', 'ohci1394'); #- don't warn when this fails

	!($_->{error} && $_->{try});
    } probe_category($category),
      map { { driver => $_, description => $_, try => 1 } } @try_modules;
}

sub probe_category {
    my ($category) = @_;

    my @modules = category2modules($category);

    grep {
	if ($category eq 'network/isdn') {
	    my $b = $_->{driver} =~ /ISDN:([^,]*),?([^,]*)(?:,firmware=(.*))?/;
	    if ($b) {
		$_->{driver} = $1;
		$_->{options} = $2;
		$_->{firmware} = $3;
		$_->{driver} eq "hisax" and $_->{options} .= " id=HiSax";
	    }
	    $b;
	} else {
	    member($_->{driver}, @modules);
	}
    } detect_devices::probeall();
}


#-###############################################################################
#- modules.conf functions
#-###############################################################################
sub get_alias {
    my ($alias) = @_;
    $conf{$alias}{alias};
}
sub get_probeall {
    my ($alias) = @_;
    $conf{$alias}{probeall};
}
sub get_options {
    my ($name) = @_;
    $conf{$name}{options};
}
sub set_options {
    my ($name, $new_option) = @_;
    $conf{$name}{options} = $new_option;
}
sub add_alias { 
    my ($alias, $module) = @_;
    $module =~ /ignore/ and return;
    /\Q$alias/ && $conf{$_}{alias} && $conf{$_}{alias} eq $module and return $_ foreach keys %conf;
    log::l("adding alias $alias to $module");
    $conf{$alias}{alias} = $module;
    $conf{$module}{above} = 'snd-pcm-oss' if $module =~ /^snd-/;
    $alias;
}
sub add_probeall {
    my ($alias, $module) = @_;

    my $l = $conf{$alias}{probeall} ||= [];
    @$l = uniq(@$l, $module);
    log::l("setting probeall $alias to @$l");
}
sub remove_probeall {
    my ($alias, $module) = @_;

    my $l = $conf{$alias}{probeall} ||= [];
    @$l = grep { $_ ne $module } @$l;
    log::l("setting probeall $alias to @$l");
}

sub remove_alias($) {
    my ($name) = @_;
    remove_alias_regexp("^$name\$");
}

sub remove_alias_regexp($) {
    my ($aliased) = @_;
    foreach (keys %conf) {
        delete $conf{$_}{alias} if /$aliased/;
    }
}

sub remove_alias_regexp_byname($) {
    my ($name) = @_;
    foreach (keys %conf) {
        delete $conf{$_} if /$name/;
    }
}

sub remove_module($) {
    my ($name) = @_;
    remove_alias($name);
    delete $conf{$name};
    0;
}

sub read_conf {
    my ($file) = @_;
    my %c;

    foreach (cat_($file)) {
	next if /^\s*#/;
	s/#.*$//;
	my ($type, $alias, $val) = split(/\s+/, chomp_($_), 3) or next;
	$val =~ s/\s+$//;

	$val = [ split ' ', $val ] if $type eq 'probeall';

	$c{$alias}{$type} = $val;
    }
    #- cheating here: not handling aliases of aliases
    while (my ($_k, $v) = each %c) {
	if (my $a = $v->{alias}) {
	    local $c{$a}{alias};
	    delete $v->{probeall};
	    add2hash($c{$a}, $v);
	}
    }
    #- convert old aliases to new probeall
    foreach my $name ('scsi_hostadapter', 'usb-interface') {
	my @old_aliases = 
	  map { $_->[0] } sort { $a->[1] <=> $b->[1] } 
	  map { if_(/^$name(\d*)/ && $c{$_}{alias}, [ $_, $1 || 0 ]) } keys %c;
	foreach my $alias (@old_aliases) {
	    push @{$c{$name}{probeall} ||= []}, delete $c{$alias}{alias};
	}
    }
    # Convert alsa driver from old naming system to new one (snd-card-XXX => snd-XXX)
    # Ensure correct upgrade for snd-via683 and snd-via8233 drivers
    foreach my $alias (sort keys %c) {
        $c{$alias}{alias} =~ s/^snd-card/snd/;
        $c{$alias}{alias} = 'snd-via82xx' if $c{$alias}{alias} =~ /^snd-via686|^snd-via8233/;
    }

    \%c;
}

sub mergein_conf {
    my ($file) = @_;
    my $modconfref = read_conf($file);
    while (my ($key, $value) = each %$modconfref) {
	$conf{$key}{alias} ||= $value->{alias};
	$conf{$key}{options} = $value->{options} if $value->{options};
	push @{$conf{$key}{probeall} ||= []}, deref($value->{probeall});
    }
}

sub write_conf() {
    my $file = "$::prefix/etc/modules.conf";
    rename "$::prefix/etc/conf.modules", $file; #- make the switch to new name if needed

    #- Substitute new aliases in modules.conf (if config has changed)
    substInFile {
	my ($type, $alias, $module) = split(/\s+/, chomp_($_), 3);
	if ($type eq 'post-install' && $alias eq 'supermount') {	    
	    #- remove the post-install supermount stuff.
	    $_ = '';
	} elsif ($type eq 'alias' && $alias =~ /scsi_hostadapter|usb-interface/) {
	    #- remove old aliases which are replaced by probeall
	    $_ = '';
     } elsif ($type eq 'above') {
         # Convert alsa driver from old naming system to new one (snd-card-XXX => snd-XXX)
         # Ensure correct upgrade for snd-via683 and snd-via8233 drivers
         s/snd-card/snd/g;
         s/snd-via686|snd-via8233/snd-via82xx/g;
	} elsif ($conf{$alias}{$type} && $conf{$alias}{$type} ne $module) {
	    my $v = join(' ', uniq(deref($conf{$alias}{$type})));
	    $_ = "$type $alias $v\n";
	} elsif ($type eq 'alias' && !defined $conf{$alias}{alias}) { 
         $_ = '';
     }
    } $file;

    my $written = read_conf($file);

    open(my $F, ">> $file") or die("cannot write module config file $file: $!\n");
    while (my ($mod, $h) = each %conf) {
	while (my ($type, $v) = each %$h) {
	    my $v2 = join(' ', uniq(deref($v)));
	    print $F "$type $mod $v2\n" 
	      if $v2 && !$written->{$mod}{$type};
	}
    }
    my @l;
    push @l, 'scsi_hostadapter' if !is_empty_array_ref($conf{scsi_hostadapter}{probeall});
    push @l, 'bttv' if detect_devices::matching_driver('^bttv$');
    my @l_26 = @l;
    if (my ($agp) = probe_category('various/agpgart')) {
	push @l_26, $agp->{driver};
    }
    append_to_modules_loaded_at_startup("$::prefix/etc/modules", @l);
    append_to_modules_loaded_at_startup("$::prefix/etc/modprobe.preload", @l_26);
    #- use module-init-tools script for the moment
    run_program::rooted($::prefix, "/sbin/generate-modprobe.conf", ">", "/etc/modprobe.conf") if -e "$::prefix/etc/modprobe.conf";
}

sub append_to_modules_loaded_at_startup {
    my ($file, @l) = @_;
    my $l = join '|', map { '^\s*'.$_.'\s*$' } @l;
    log::l("to put in $file ", join(", ", @l));

    substInFile { 
	$_ = '' if $l && /$l/;
	$_ .= join '', map { "$_\n" } @l if eof;
    } $file;
}

sub read_stage1_conf {
    mergein_conf($_[0]);
}

#-###############################################################################
#- pcmcia various
#-###############################################################################
sub configure_pcmcia {
    my ($pcic) = @_;

    #- try to setup pcmcia if cardmgr is not running.
    my $running if 0;
    return if $running;
    $running = 1;

    log::l("i try to configure pcmcia services");

    symlink "/tmp/stage2/$_", $_ foreach "/etc/pcmcia";

    eval {
	load("pcmcia_core");
	load($pcic);
	load("ds");
    };

    #- run cardmgr in foreground while it is configuring the card.
    run_program::run("cardmgr", "-f", "-m", "/modules");
    sleep(3);
    
    #- make sure to be aware of loaded module by cardmgr.
    read_already_loaded();
}

sub write_pcmcia {
    my ($prefix, $pcmcia) = @_;

    #- should be set after installing the package above otherwise the file will be renamed.
    setVarsInSh("$prefix/etc/sysconfig/pcmcia", {
	PCMCIA    => bool2yesno($pcmcia),
	PCIC      => $pcmcia,
	PCIC_OPTS => "",
        CORE_OPTS => "",
    });
}


#-###############################################################################
#- internal functions
#-###############################################################################
sub loaded_modules() { 
    map { /(\S+)/ } cat_("/proc/modules");
}
sub read_already_loaded() { 
    when_load($_) foreach reverse loaded_modules();
}

my $module_extension = c::kernel_version() =~ /^\Q2.4/ ? 'o' : 'ko';

sub name2file {
    my ($name) = @_;
    "$name.$module_extension";
}

sub when_load {
    my ($name, @options) = @_;

    $name = mapping_26_24($name); #- need to stay with 2.4 names, modutils will allow booting 2.4 and 2.6

    if ($name =~ /[uo]hci/) {
        -f '/proc/bus/usb/devices' or eval {
            require fs; fs::mount('/proc/bus/usb', '/proc/bus/usb', 'usbdevfs');
            #- ensure keyboard is working, the kernel must do the job the BIOS was doing
            sleep 4;
            load("usbkbd", "keybdev") if detect_devices::usbKeyboards();
        }
    }

    load('snd-pcm-oss') if $name =~ /^snd-/;
    add_alias('ieee1394-controller', $name) if member($name, 'ohci1394');
    add_probeall('usb-interface', $name) if member($name, qw(usb-uhci usb-ohci ehci-hcd uhci-hcd ohci-hcd));

    $conf{$name}{options} = join " ", @options if @options;

    if (my $category = module2category($name)) {
	if ($category =~ m,disk/(scsi|hardware_raid|usb|firewire),) {
	    add_probeall('scsi_hostadapter', $name);
	    eval { load('sd_mod') };
	}
	add_alias('sound-slot-0', $name) if $category =~ /sound/;
    }
}

sub cz_file() { 
    "/lib/modules" . (arch() eq 'sparc64' && "64") . ".cz-" . c::kernel_version();
}

sub extract_modules {
    my ($dir, @modules) = @_;
    my $cz = cz_file();
    if (!-e $cz) {
	unlink $_ foreach glob_("/lib/modules*.cz*");
	require install_any;
        install_any::getAndSaveFile("Mandrake/mdkinst$cz", $cz) or die "failed to get modules $cz: $!";
    }
    eval {
	require packdrake;
	my $packer = new packdrake($cz, quiet => 1);
	$packer->extract_archive($dir, map { name2file($_) } @modules);
	map { $dir . '/' . name2file($_) } @modules;
    };
}

sub load_raw {
    my @l = @_;

    extract_modules('/tmp', map { $_->[0] } @l);
    my @failed = grep {
	my $m = '/tmp/' . name2file($_->[0]);
	if (-e $m) {
            my $stdout;
            my $rc = run_program::run(["/usr/bin/insmod_", "insmod"], '2>', \$stdout, $m, @{$_->[1]});
            log::l(chomp_($stdout)) if $stdout;
            if ($rc) {
                unlink $m;
                '';
            } else {
                -e $m;
            }
	} else {
	    log::l("missing module $_->[0]") if !-e $m;
            -e $m;
	}
    } @l;

    die "insmod'ing module " . join(", ", map { $_->[0] } @failed) . " failed" if @failed;

}

sub get_parameters {
    map { if_(/(.*)=(.*)/, $1 => $2) } split(' ', get_options($_[0]));
}


1;
pan>->{pcmcia} ||= !$::testing && c::pcmcia_probe()) { my $w = $o->wait_message(_("PCMCIA"), _("Configuring PCMCIA cards...")); my $results = modules::configure_pcmcia($o->{pcmcia}); $w = undef; $results and $o->ask_warn('', $results); } } { my $w = $o->wait_message(_("IDE"), _("Configuring IDE")); modules::load_category('disk/cdrom'); } any::load_category($o, 'disk/scsi|hardware_raid', !$::expert && !$clicked, 0, $o->{pcmcia}); install_interactive::tellAboutProprietaryModules($o) if !$clicked; } sub ask_mntpoint_s { my ($o, $fstab) = @_; $o->set_help('ask_mntpoint_s'); my @fstab = grep { isTrueFS($_) } @$fstab; @fstab = grep { isSwap($_) } @$fstab if @fstab == 0; @fstab = @$fstab if @fstab == 0; die _("No partition available") if @fstab == 0; { my $w = $o->wait_message('', _("Scanning partitions to find mount points")); install_any::suggest_mount_points($fstab, $o->{prefix}, 'uniq'); log::l("default mntpoint $_->{mntpoint} $_->{device}") foreach @fstab; } if (@fstab == 1) { $fstab[0]{mntpoint} = '/'; } else { $o->ask_from('', _("Choose the mount points"), [ map { { label => partition_table::description($_), val => \$_->{mntpoint}, not_edit => 0, list => [ '', fsedit::suggestions_mntpoint(fsedit::empty_all_hds()) ] } } grep { !$_->{real_mntpoint} || common::usingRamdisk() } @fstab ]) or return; } $o->SUPER::ask_mntpoint_s($fstab); } #------------------------------------------------------------------------------ sub doPartitionDisks { my ($o) = @_; my $warned; install_any::getHds($o, sub { my ($err) = @_; $warned = 1; if ($o->ask_yesorno(_("Error"), _("I can't read your partition table, it's too corrupted for me :( I can try to go on, erasing over bad partitions (ALL DATA will be lost!). The other solution is to not allow DrakX to modify the partition table. (the error is %s) Do you agree to loose all the partitions? ", $err))) { 0; } else { $o->{partitioning}{readonly} = 1; 1; } }) or $warned or $o->ask_warn('', _("DiskDrake failed to read correctly the partition table. Continue at your own risk!")); if (arch() =~ /ppc/ && detect_devices::get_mac_generation =~ /NewWorld/) { #- need to make bootstrap part if NewWorld machine - thx Pixel ;^) if (defined $partition_table_mac::bootstrap_part) { #- don't do anything if we've got the bootstrap setup #- otherwise, go ahead and create one somewhere in the drive free space } else { if (defined $partition_table_mac::freepart_start && $partition_table_mac::freepart_size >= 1) { my ($hd) = $partition_table_mac::freepart_device; log::l("creating bootstrap partition on drive /dev/$hd->{device}, block $partition_table_mac::freepart_start"); $partition_table_mac::bootstrap_part = $partition_table_mac::freepart_part; log::l("bootstrap now at $partition_table_mac::bootstrap_part"); fsedit::add($hd, { start => $partition_table_mac::freepart_start, size => 1 << 11, type => 0x401, mntpoint => '' }, $o->{all_hds}, { force => 1, primaryOrExtended => 'Primary' }); $new_bootstrap = 1; } else { $o->ask_warn('',_("No free space for 1MB bootstrap! Install will continue, but to boot your system, you'll need to create the bootstrap partition in DiskDrake")); } } } if ($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}); if (!$p) { my @l = install_any::find_root_parts($o->{fstab}, $o->{prefix}) or die _("No root partition found to perform an upgrade"); $p = $o->ask_from_listf(_("Root Partition"), _("What is the root partition (/) of your system?"), \&partition_table::description, \@l) or die "setstep exitInstall\n"; } install_any::use_root_part($o->{all_hds}, $p, $o->{prefix}); } elsif ($::expert && $o->isa('interactive_gtk')) { install_interactive::partition_with_diskdrake($o, $o->{all_hds}); } else { install_interactive::partitionWizard($o); } } #------------------------------------------------------------------------------ sub rebootNeeded { my ($o) = @_; $o->ask_warn('', _("You need to reboot for the partition table modifications to take place")); install_steps::rebootNeeded($o); } #------------------------------------------------------------------------------ sub choosePartitionsToFormat { my ($o, $fstab) = @_; $o->SUPER::choosePartitionsToFormat($fstab); my @l = grep { !$_->{isMounted} && $_->{mntpoint} && (!isSwap($_) || $::expert) && (!isFat($_) || $_->{notFormatted} || $::expert) && (!isOtherAvailableFS($_) || $::expert || $_->{toFormat}) } @$fstab; $_->{toFormat} = 1 foreach grep { isSwap($_) && !$::expert } @$fstab; return if @l == 0 || !$::expert && 0 == grep { ! $_->{toFormat} } @l; #- keep it temporary until the guy has accepted $_->{toFormatTmp} = $_->{toFormat} || $_->{toFormatUnsure} foreach @l; $o->ask_from_( { messages => _("Choose the partitions you want to format"), advanced_messages => _("Check bad blocks?"), }, [ map { my $e = $_; ({ text => partition_table::description($e), type => 'bool', val => \$e->{toFormatTmp} }, if_(!isLoopback($_) && !isThisFs("reiserfs", $_) && !isThisFs("xfs", $_) && !isThisFs("jfs", $_), { text => partition_table::description($e), type => 'bool', advanced => 1, disabled => sub { !$e->{toFormatTmp} }, val => \$e->{toFormatCheck} })) } @l ] ) or die 'already displayed'; #- ok now we can really set toFormat foreach (@l) { $_->{toFormat} = delete $_->{toFormatTmp}; $_->{isFormatted} = 0; } } sub formatMountPartitions { my ($o, $fstab) = @_; my $w; fs::formatMount_all($o->{all_hds}{raids}, $o->{fstab}, $o->{prefix}, sub { my ($part) = @_; $w ||= $o->wait_message('', _("Formatting partitions")); $w->set(isLoopback($part) ? _("Creating and formatting file %s", $part->{loopback_file}) : _("Formatting partition %s", $part->{device})); }); die _("Not enough swap space to fulfill installation, please add some") if availableMemory < 40 * 1024; } #------------------------------------------------------------------------------ sub setPackages { my ($o, $rebuild_needed) = @_; my $w = $o->wait_message('', $rebuild_needed ? _("Looking for available packages and rebuilding rpm database...") : _("Looking for available packages...")); install_any::setPackages($o, $rebuild_needed); if ($rebuild_needed) { $w->set(_("Finding packages to upgrade...")); pkgs::selectPackagesToUpgrade($o->{packages}, $o->{prefix}, $o->{base}, $o->{toRemove}, $o->{toSave}); } else { $w->set(_("Looking at packages already installed...")); pkgs::selectPackagesAlreadyInstalled($o->{packages}, $o->{prefix}); } } #------------------------------------------------------------------------------ sub choosePackages { my ($o, $packages, $compssUsers, $first_time) = @_; #- this is done at the very beginning to take into account #- selection of CD by user if using a cdrom. $o->chooseCD($packages) if $o->{method} eq 'cdrom' && !$::oem; my $availableC = install_steps::choosePackages(@_); my $individual = $::expert; require pkgs; my $min_size = pkgs::selectedSize($packages); $min_size < $availableC or die _("Your system does not have enough space left for installation or upgrade (%d > %d)", $min_size, $availableC); my $min_mark = $::expert ? 3 : 4; my $b = pkgs::saveSelected($packages); my $level = pkgs::setSelectedFromCompssList($packages, { map { $_ => 1 } map { @{$compssUsers->{$_}{flags}} } @{$o->{compssUsersSorted}} }, $min_mark, 0); my $max_size = pkgs::selectedSize($packages) + 1; #- avoid division by zero. log::l("max size (level $min_mark) is : " . formatXiB($max_size)); pkgs::restoreSelected($b); $o->chooseGroups($packages, $compssUsers, $min_mark, \$individual, $max_size) if !$::corporate; ($o->{packages_}{ind}) = pkgs::setSelectedFromCompssList($packages, $o->{compssUsersChoice}, $min_mark, $availableC); $o->choosePackagesTree($packages) if $individual; install_any::warnAboutNaughtyServers($o); } sub choosePackagesTree { my ($o, $packages, $limit_to_medium) = @_; $o->ask_many_from_list('', _("Choose the packages you want to install"), { list => [ grep { !$limit_to_medium || pkgs::packageMedium($packages, $_) == $limit_to_medium } @{$packages->{depslist}} ], value => \&URPM::Package::flag_selected, label => \&URPM::Package::name, sort => 1, }); } sub loadSavePackagesOnFloppy { my ($o, $packages) = @_; my $choice = $o->ask_from_listf('', _("Please choose load or save package selection on floppy. The format is the same as auto_install generated floppies."), sub { $_[0]{text} }, [ { text => _("Load from floppy"), code => sub { while (1) { my $w = $o->wait_message(_("Package selection"), _("Loading from floppy")); log::l("load package selection from floppy"); my $O = eval { install_any::loadO({}, 'floppy') }; if ($@) { $w = undef; #- close wait message. $o->ask_okcancel('', _("Insert a floppy containing package selection")) or return; } else { install_any::unselectMostPackages($o); foreach (@{$O->{default_packages} || []}) { my $pkg = pkgs::packageByName($packages, $_); pkgs::selectPackage($packages, $pkg) if $pkg; } return 1; } } } }, { text => _("Save on floppy"), code => sub { log::l("save package selection to floppy"); install_any::g_default_packages($o, 'quiet'); } }, { text => _("Cancel") }, ]); $choice->{code} and $choice->{code}(); } sub chooseGroups { my ($o, $packages, $compssUsers, $min_level, $individual, $max_size) = @_; #- for all groups available, determine package which belongs to each one. #- this will enable getting the size of each groups more quickly due to #- limitation of current implementation. #- use an empty state for each one (no flag update should be propagated). #- OLD VERSION my $b = pkgs::saveSelected($packages); install_any::unselectMostPackages($o); pkgs::setSelectedFromCompssList($packages, {}, $min_level, $max_size); my $system_size = pkgs::selectedSize($packages); my ($sizes, $pkgs) = pkgs::computeGroupSize($packages, $min_level); pkgs::restoreSelected($b); log::l("system_size: $system_size"); my @groups = @{$o->{compssUsersSorted}}; my %stable_flags = grep_each { $::b } %{$o->{compssUsersChoice}}; delete $stable_flags{$_} foreach map { @{$compssUsers->{$_}{flags}} } @groups; my $compute_size = sub { my %pkgs; my %flags = %stable_flags; @flags{@_} = (); my $total_size; A: while (my ($k, $size) = each %$sizes) { Or: foreach (split "\t", $k) { foreach (split "&&") { exists $flags{$_} or next Or; } $total_size += $size; $pkgs{$_} = 1 foreach @{$pkgs->{$k}}; next A; } } log::l("computed size $total_size"); log::l("chooseGroups: ", join(" ", sort keys %pkgs)); int $total_size; }; my %val = map { $_ => ! grep { ! $o->{compssUsersChoice}{$_} } @{$compssUsers->{$_}{flags}} } @groups; # @groups = grep { $size{$_} = round_down($size{$_} / sqr(1024), 10) } @groups; #- don't display the empty or small one (eg: because all packages are below $min_level) my ($all, $size, $unselect_all); my $available_size = install_any::getAvailableSpace($o) / sqr(1024); my $size_to_display = sub { my $lsize = $system_size + $compute_size->(map { @{$compssUsers->{$_}{flags}} } grep { $val{$_} } @groups); #- if a profile is deselected, deselect everything (easier than deselecting the profile packages) $unselect_all ||= $size > $lsize; $size = $lsize; _("Total size: %d / %d MB", pkgs::correctSize($size / sqr(1024)), $available_size); }; while (1) { if ($available_size < 140) { # too small to choose anything. Defaulting to no group chosen $val{$_} = 0 foreach %val; last; } $o->reallyChooseGroups($size_to_display, $individual, \%val) or return; last if pkgs::correctSize($size / sqr(1024)) < $available_size; $o->ask_warn('', _("Selected size is larger than available space")); } $o->{compssUsersChoice}{$_} = 0 foreach map { @{$compssUsers->{$_}{flags}} } grep { !$val{$_} } keys %val; $o->{compssUsersChoice}{$_} = 1 foreach map { @{$compssUsers->{$_}{flags}} } grep { $val{$_} } keys %val; log::l("compssUsersChoice: " . (!$val{$_} && "not ") . "selected [$_] as [$o->{compssUsers}{$_}{label}]") foreach keys %val; $unselect_all and install_any::unselectMostPackages($o); #- if no group have been chosen, ask for using base system only, or no X, or normal. unless ($o->{isUpgrade} || grep { $val{$_} } keys %val) { my $docs = !$o->{excludedocs}; my $minimal = !grep { $_ } values %{$o->{compssUsersChoice}}; $o->ask_from(_("Type of install"), _("You haven't selected any group of packages. Please choose the minimal installation you want:"), [ { val => \$o->{compssUsersChoice}{X}, type => 'bool', text => _("With X"), disabled => sub { $minimal } }, if_($::expert || $minimal, { val => \$docs, type => 'bool', text => _("With basic documentation (recommended!)"), disabled => sub { $minimal } }, { val => \$minimal, type => 'bool', text => _("Truly minimal install (especially no urpmi)") }, ), ], changed => sub { $o->{compssUsersChoice}{X} = $docs = 0 if $minimal }, ) or return &chooseGroups; $o->{excludedocs} = !$docs || $minimal; #- reselect according to user selection. if ($minimal) { $o->{compssUsersChoice}{$_} = 0 foreach keys %{$o->{compssUsersChoice}}; } else { my $X = $o->{compssUsersChoice}{X}; #- don't let setDefaultPackages modify this one install_any::setDefaultPackages($o, 'clean'); $o->{compssUsersChoice}{X} = $X; } $unselect_all or install_any::unselectMostPackages($o); } 1; } sub reallyChooseGroups { my ($o, $size_to_display, $individual, $val) = @_; my $size_text = &$size_to_display; my ($path, $all); $o->ask_from('', _("Package Group Selection"), [ { val => \$size_text, type => 'label' }, {}, (map {; my $old = $path; $path = $o->{compssUsers}{$_}{path}; if_($old ne $path, { val => translate($path) }), { val => \$val->{$_}, type => 'bool', disabled => sub { $all }, text => translate($o->{compssUsers}{$_}{label}), help => translate($o->{compssUsers}{$_}{descr}), } } @{$o->{compssUsersSorted}}), if_($o->{meta_class} eq 'desktop', { text => _("All"), val => \$all, type => 'bool' }), if_($individual, { text => _("Individual package selection"), val => $individual, advanced => 1, type => 'bool' }), ], changed => sub { $size_text = &$size_to_display }) or return; if ($all) { $val->{$_} = 1 foreach keys %$val; } 1; } sub chooseCD { my ($o, $packages) = @_; my @mediums = grep { $_ != $install_any::boot_medium } pkgs::allMediums($packages); my @mediumsDescr = (); my %mediumsDescr = (); if (!common::usingRamdisk()) { #- mono-cd in case of no ramdisk foreach (@mediums) { pkgs::mediumDescr($packages, $install_any::boot_medium) eq pkgs::mediumDescr($packages, $_) and next; undef $packages->{mediums}{$_}{selected}; } log::l("low memory install, using single CD installation (as it is not ejectable)"); return; } #- the boot medium is already selected. $mediumsDescr{pkgs::mediumDescr($packages, $install_any::boot_medium)} = 1; #- build mediumDescr according to mediums, this avoid asking multiple times #- all the medium grouped together on only one CD. foreach (@mediums) { my $descr = pkgs::mediumDescr($packages, $_); exists $mediumsDescr{$descr} or push @mediumsDescr, $descr; $mediumsDescr{$descr} ||= $packages->{mediums}{$_}{selected}; } #- if no other medium available or a poor beginner, we are choosing for him! #- note first CD is always selected and should not be unselected! return if @mediumsDescr == () || !$::expert; $o->set_help('chooseCD'); $o->ask_many_from_list('', _("If you have all the CDs in the list below, click Ok. If you have none of those CDs, click Cancel. If only some CDs are missing, unselect them, then click Ok."), { list => \@mediumsDescr, label => sub { _("Cd-Rom labeled \"%s\"", $_[0]) }, val => sub { \$mediumsDescr{$_[0]} }, }) or do { $mediumsDescr{$_} = 0 foreach @mediumsDescr; #- force unselection of other CDs. }; $o->set_help('choosePackages'); #- restore true selection of medium (which may have been grouped together) foreach (@mediums) { my $descr = pkgs::mediumDescr($packages, $_); $packages->{mediums}{$_}{selected} = $mediumsDescr{$descr};