diff options
Diffstat (limited to 'perl-install/install/media.pm')
| -rw-r--r-- | perl-install/install/media.pm | 512 | 
1 files changed, 201 insertions, 311 deletions
| diff --git a/perl-install/install/media.pm b/perl-install/install/media.pm index d889f9141..149deffc3 100644 --- a/perl-install/install/media.pm +++ b/perl-install/install/media.pm @@ -1,4 +1,4 @@ -package install::media; # $Id$ +package install::media;  use strict; @@ -6,13 +6,15 @@ our @ISA = qw(Exporter);  our @EXPORT_OK = qw(getFile_ getAndSaveFile_ getAndSaveFile_media_info packageMedium);  use common; +use Data::Dumper; +# Make sure report.bug are more easily comparable: +$Data::Dumper::Sortkeys = 1;  use fs::type; - +use urpm::download; +use urpm::media;  #- list of fields for {phys_medium} :  #-	device -#-	finalpath -#-	from_iso  #-	fs_type  #-	is_suppl (is a supplementary media)  #-	isMounted @@ -26,57 +28,40 @@ use fs::type;  #-	url  #- list of fields for {media} : -#-	end (last rpm id, undefined iff not selected) +#-	end (last rpm id, undefined if not selected)  #-	fakemedium ("$name ($rpmsdir)", used locally by urpmi)  #-	rel_hdlist -#-	hdlist_size -#-	key_ids (hashref, values are key ids) +#-	key-ids  #-	name (text description)  #-	pubkey (array containing all the keys to import)  #-	phys_medium  #-	rpmsdir -#-	selected +#-	ignore  #-	size (in MB) -#-	start (first rpm id, undefined iff not selected) -#-	synthesis_hdlist_size +#-	start (first rpm id, undefined if ignored)  #-	update (for install_urpmi)  our $postinstall_rpms = '';  my %mounted_media; -sub free_medium_id { -    my ($media) = @_; -    int(@$media); -} -  sub allMediums {      my ($packages) = @_;      @{$packages->{media}};  } -sub phys_media { +sub _phys_media {      my ($packages) = @_;      uniq(map { $_->{phys_medium} } @{$packages->{media}});  } -sub pkg2media { -   my ($media, $p) = @_;  -   $p or internal_error("invalid package"); - -   find { -       $_->{selected} && -	 $p->id >= $_->{start} && $p->id <= $_->{end}; -   } @$media; -} -  sub packageMedium {     my ($packages, $p) = @_; - -   pkg2media($packages->{media}, $p) || {}; +   URPM::pkg2media($packages->{media}, $p) || {};  } +  sub packagesOfMedium {      my ($packages, $medium) = @_; @@ -94,16 +79,6 @@ sub path {      ($phys_m->{real_mntpoint} || fs::get::mntpoint_prefixed($phys_m)) . $phys_m->{rel_path} . '/' . $f;  } -sub rel_rpm_file { -    my ($medium, $f) = @_; -    if (my ($arch) = $f =~ m|\.([^\.]*)\.rpm$|) { -	$f = "$medium->{rpmsdir}/$f"; -	$f =~ s/%{ARCH}/$arch/g; -	$f =~ s,^/+,,g; -    } -    $f; -} -  sub umount_phys_medium {      my ($phys_m) = @_; @@ -118,7 +93,8 @@ sub umount_phys_medium {      }      $ok;  } -sub mount_phys_medium { + +sub _mount_phys_medium {      my ($phys_m, $o_rel_file, $b_force_change) = @_;      if (!$b_force_change) { @@ -138,25 +114,19 @@ sub umount_media {      #- we don't bother umounting first phys medium if clp is not on disk      #- (this is mainly for nfs installs using install/stage2/live) -    my @l = phys_media($packages); +    my @l = _phys_media($packages);      shift @l if !$install::any::compressed_image_on_disk && $l[0]{is_stage2_phys_medium};      umount_phys_medium($_) foreach @l;      umount_phys_medium($_) foreach grep { $_ } map { $_->{loopback_device} } @l;  } -sub url_respect_privacy { -    my ($url) = @_; - -    $url =~ s!ftp://.*?\@!ftp://xxx@!; -    $url; -}  sub phys_medium_to_string {      my ($phys_m) = @_; -    url_respect_privacy($phys_m->{url}) . ($phys_m->{name} ? " ($phys_m->{name})" : ''); +    urpm::download::url_obscuring_password($phys_m->{url}) . ($phys_m->{name} ? " ($phys_m->{name})" : '');  } -sub stage2_mounted_medium { +sub _stage2_mounted_medium {      my ($method, $rel_path) = @_;      my ($device, $real_mntpoint, $fs_type, $url); @@ -190,7 +160,7 @@ sub stage2_phys_medium {  	my $user = $ENV{LOGIN} && ($ENV{LOGIN} . ($ENV{PASSWORD} && ":$ENV{PASSWORD}") . '@');  	$ENV{URLPREFIX} = "ftp://$user$ENV{HOST}/$ENV{PREFIX}";      } -    if ($method eq 'http' || $method eq 'ftp') { +    if (member($method, qw(http ftp))) {  	{ method => $method, url => $ENV{URLPREFIX} };      } elsif ($method =~ /(.*)-iso$/) {  	my $dir_method = $1; @@ -199,8 +169,8 @@ sub stage2_phys_medium {  	my $rel_iso = $ENV{ISOPATH} =~ m!media/*(/.*)! ? $1 : '';  	my ($dir_url, $iso) = (dirname($rel_iso), basename($rel_iso)); -	my $dir_medium = stage2_mounted_medium($dir_method, $dir_url eq '/' ? '' : $dir_url); -	my $phys_m = iso_phys_media($dir_medium, $iso, ''); +	my $dir_medium = _stage2_mounted_medium($dir_method, $dir_url eq '/' ? '' : $dir_url); +	my $phys_m = _iso_phys_media($dir_medium, $iso, '');  	$phys_m->{real_mntpoint} = '/tmp/loop';  	$phys_m->{real_device} = cat_("/proc/mounts") =~ m!(/dev/\S+)\s+/tmp/loop\s! && $1;  	$phys_m->{isMounted} = 1; @@ -208,7 +178,7 @@ sub stage2_phys_medium {  	$phys_m;      } else {  	my $rel_path = readlink('/tmp/image') =~ m!media/*(/.*)! ? $1 : ''; -	stage2_mounted_medium($method, $rel_path); +	_stage2_mounted_medium($method, $rel_path);      }  } @@ -228,16 +198,16 @@ sub change_phys_medium {      my $force_change = $phys_m->{method} eq 'cdrom' && $mounted_media{cdrom};      if (my $current = $mounted_media{$phys_m->{method}}) { -	setup_postinstall_rpms($::o, $o_packages, $current) if $o_packages && $phys_m->{method} eq 'cdrom' && $::o->isa('interactive'); +	_setup_postinstall_rpms($::o, $o_packages, $current) if $o_packages && $phys_m->{method} eq 'cdrom' && $::o->isa('interactive');  	umount_phys_medium($current) or return;  	delete $mounted_media{$phys_m->{method}};      } -    mount_phys_medium($phys_m, $o_rel_file, $force_change) or return; -    phys_medium_is_mounted($phys_m); +    _mount_phys_medium($phys_m, $o_rel_file, $force_change) or return; +    _phys_medium_is_mounted($phys_m);      1;  } -sub phys_medium_is_mounted { +sub _phys_medium_is_mounted {      my ($phys_m) = @_;      if (member($phys_m->{method}, 'cdrom', 'iso')) {  	#- we can't have more than one cdrom mounted at once @@ -246,16 +216,16 @@ sub phys_medium_is_mounted {      }  } -sub associate_phys_media { +sub _associate_phys_media {      my ($all_hds, $main_phys_medium, $hdlists) = @_;      my ($main_name, @other_names) = uniq(map { $_->{name} } @$hdlists);      my @other_phys_media =         $main_phys_medium->{method} eq 'iso' ? -	get_phys_media_iso($all_hds, $main_phys_medium, \@other_names) : +	_get_phys_media_iso($all_hds, $main_phys_medium, \@other_names) :        $main_phys_medium->{method} eq 'cdrom' ? -	(map { get_phys_media_cdrom($main_phys_medium, $_) } @other_names) : +	(map { _get_phys_media_cdrom($main_phys_medium, $_) } @other_names) :  	  ();      if (@other_phys_media) { @@ -269,7 +239,7 @@ sub associate_phys_media {  		log::l("setting medium $medium->{name} phys_medium to $phys_m->{url}");  		$medium->{phys_medium} = $phys_m;  	    } else { -		$medium->{selected} = 0; +		$medium->{ignore} = 1;  		log::l("deselecting missing medium $medium->{rpmsdir}");  	    }  	} @@ -280,14 +250,14 @@ sub associate_phys_media {      }  } -sub get_phys_media_cdrom { +sub _get_phys_media_cdrom {      my ($main_phys_m, $name) = @_;      #- exactly the same as $main_phys_m, but for {name}, {isMounted} and {real_mntpoint}      +{ %$main_phys_m, name => $name, isMounted => 0, real_mntpoint => undef };  } -sub iso_phys_media { +sub _iso_phys_media {      my ($dir_medium, $iso, $rel_path) = @_;      my $mntpoint = "/mnt/$iso"; @@ -304,19 +274,21 @@ sub iso_phys_media {  	mntpoint => $mntpoint, rel_path => $rel_path,      };  } -sub get_phys_media_iso { + +sub _get_phys_media_iso {      my ($all_hds, $main_phys_m, $names) = @_; -    my @ISOs = grep { member($_->{app_id}, @$names) } look_for_ISO_images($main_phys_m->{device}); +    my @ISOs = grep { member($_->{app_id}, @$names) } _look_for_ISO_images($main_phys_m->{device});      map { -	my $m = iso_phys_media($main_phys_m->{loopback_device}, $_->{file}, $main_phys_m->{rel_path}); +	my $m = _iso_phys_media($main_phys_m->{loopback_device}, $_->{file}, $main_phys_m->{rel_path});  	$m->{name} = $_->{app_id};  	push @{$all_hds->{loopbacks}}, $m;  	$m;      } @ISOs;  } -sub look_for_ISO_images { + +sub _look_for_ISO_images {      my ($main_iso) = @_;      my $iso_dir = dirname($main_iso); @@ -341,17 +313,18 @@ sub look_for_ISO_images {  } -sub getFile_media_info { +sub _getFile_media_info {      my ($packages, $f) = @_;      getFile_(first_medium($packages)->{phys_medium}, $f);  } -sub open_file_and_size { +sub _open_file_and_size {      my ($f) = @_;      my $size = -s $f;      my $fh = common::open_file($f) or return;      $size, $fh;  } +  sub getFile_ {      my ($phys_m, $f) = @_;      log::l("getFile $f on " . phys_medium_to_string($phys_m) . ""); @@ -359,47 +332,47 @@ sub getFile_ {      my ($_size, $fh) = get_file_and_size($phys_m, $f) or return;      $fh;  } +  sub get_file_and_size {      my ($phys_m, $f) = @_; -    if ($f =~ m|^http://|) { +    if ($f =~ m|^https?://|) {  	require install::http;  	install::http::get_file_and_size($f); -    } elsif ($phys_m->{method} eq "ftp") { -	require install::ftp; -	install::ftp::get_file_and_size($f, $phys_m->{url}); -    } elsif ($phys_m->{method} eq "http") { +    } elsif (member($phys_m->{method}, qw(ftp http https))) {  	require install::http;  	install::http::get_file_and_size_($f, $phys_m->{url});      } elsif ($f =~ m!^/!) { -	open_file_and_size($f); +	_open_file_and_size($f);      } elsif ($postinstall_rpms && -e "$postinstall_rpms/$f") { -	open_file_and_size("$postinstall_rpms/$f"); +	_open_file_and_size("$postinstall_rpms/$f");      } else {  	my $f2 = path($phys_m, $f);  	if (! -f $f2) {  	    change_phys_medium($phys_m, $f, $::o->{packages});  	} -	open_file_and_size($f2); +	_open_file_and_size($f2);      }  }  sub getAndSaveFile_ {      my ($phys_m, $file, $local) = @_;      my $fh = getFile_($phys_m, $file) or return; -    getAndSaveFile_raw($fh, $local); +    _getAndSaveFile_raw($fh, $local);  } -sub getAndSaveFile_progress { + +sub _getAndSaveFile_progress {      my ($in_wait, $msg, $phys_m, $file, $local) = @_;      my ($size, $fh) = get_file_and_size($phys_m, $file) or return;      if ($size) { -	getAndSaveFile_progress_raw($in_wait, $msg, $size, $fh, $local); +	_getAndSaveFile_progress_raw($in_wait, $msg, $size, $fh, $local);      } else { -	getAndSaveFile_raw($fh, $local); +	_getAndSaveFile_raw($fh, $local);      }  } -sub getAndSaveFile_raw { + +sub _getAndSaveFile_raw {      my ($fh, $local) = @_;      local $/ = \ (16 * 1024); @@ -409,17 +382,19 @@ sub getAndSaveFile_raw {      while (<$fh>) { syswrite($F, $_) or unlink($local), die("getAndSaveFile($local): $!") }      1;  } -sub getAndSaveFile_progress_raw { + +sub _getAndSaveFile_progress_raw {      my ($in_wait, $msg, $size, $fh, $local) = @_;      unlink $local;      open(my $out, ">$local") or log::l("getAndSaveFile(opening $local): $!"), return; -    print_with_progress($in_wait, $msg, $size, $fh, $out) or unlink($local), die("getAndSaveFile($local): $!"); +    _print_with_progress($in_wait, $msg, $size, $fh, $out) or unlink($local), die("getAndSaveFile($local): $!");  } -sub print_with_progress { + +sub _print_with_progress {      my ($in_wait, $msg, $size, $in, $out) = @_; -    my ($_wait, $wait_message) = $in_wait->wait_message_with_progress_bar(N("Please wait")); +    my ($_wait, $wait_message) = $in_wait->wait_message_with_progress_bar(N("Please wait, retrieving file"));      $wait_message->($msg);      my $current = 0; @@ -440,20 +415,13 @@ sub print_with_progress {      1;  } -  sub urpmidir() {      my $v = "$::prefix/var/lib/urpmi";      -l $v && !-e $v and unlink $v and mkdir $v, 0755; #- dangling symlink      -w $v ? $v : '/tmp';  } -sub hdlist_on_disk { -    my ($m) = @_; - -    urpmidir() . "/hdlist.$m->{fakemedium}.cz"; -} - -sub allow_copy_rpms_on_disk { +sub _allow_copy_rpms_on_disk {      my ($medium, $hdlists) = @_;      $medium->{device} && $medium->{method} ne 'iso' or return; @@ -462,7 +430,7 @@ sub allow_copy_rpms_on_disk {      my $totalsize = sum(map { $_->{size} } @$hdlists) || -1; #- don't check size, total medium size unknown      if ($totalsize >= 0) { -	my $availvar = install::any::getAvailableSpace_mounted("$::prefix/var"); +	my $availvar = fs::any::getAvailableSpace_mounted("$::prefix/var");  	$availvar /= 1024 * 1024; #- Mo  	log::l("totalsize=$totalsize, avail on $::prefix/var=$availvar");  	$totalsize < $availvar * 0.6; @@ -472,7 +440,7 @@ sub allow_copy_rpms_on_disk {      }  } -sub parse_media_cfg { +sub _parse_media_cfg {      my ($cfg) = @_;      require MDV::Distribconf; @@ -497,62 +465,83 @@ sub parse_media_cfg {      $distribconf, \@hdlists;  } -sub parse_hdlists { -    my ($cfg) = @_; - -    my (%main_options, @hdlists); -    foreach (cat_($cfg)) { -        chomp; -        s/\s*#.*$//; -        /^\s*$/ and next; -        #- we'll ask afterwards for supplementary CDs, if the hdlists file contains -        #- a line that begins with "suppl" -        if (/^suppl/) { $main_options{suppl} = 1; next } -        #- if the hdlists contains a line "askmedia", deletion of media found -        #- in this hdlist is allowed -        if (/^askmedia/) { $main_options{askmedia} = 1; next } -        my ($noauto, $hdlist, $rpmsdir, $name, $size) = m!^\s*(noauto:)?(hdlist\S*\.cz)\s+[^/]*/(\S+)\s*([^(]*)(?:\((.+)\))?$! -            or die qq(invalid hdlist description "$_" in hdlists file); -        $name =~ s/\s+$//; -        $size =~ s/MB?$//i; -        push @hdlists, { rel_hdlist => "media_info/$hdlist", rpmsdir => $rpmsdir, name => $name, selected => !$noauto, size => $size }; +sub select_only_some_media { +    my ($media_list, $selected_names) = @_; +    my @names = split(',', $selected_names); +    foreach my $m (@$media_list) { +        my $bool = !member($m->{name}, @names); +        # workaround urpmi transforming "ignore => ''" or "ignore => 0" into "ignore => 1": +        undef $bool if !$bool; +        log::l("disabling '$m->{name}' medium: " . to_bool($bool)); +        urpm::media::_tempignore($m, $bool); +        # make sure we update un-ignored media (eg: */Testing and the like): +        $m->{modified} = 1 if !$bool;      } -    (\%main_options, \@hdlists); +} + +sub update_media { +    my ($packages) = @_; +    urpm::media::update_media($packages, distrib => 1, callback => \&urpm::download::sync_logger) or +        log::l('updating media failed');  }  sub get_media {      my ($o, $media, $packages) = @_; -    my ($suppl_CDs, $copy_rpms_on_disk); +    my ($suppl_CDs, $copy_rpms_on_disk, $phys_m);      foreach (@$media) {  	if ($_->{type} eq 'media_cfg') { -	    my $phys_m = url2mounted_phys_medium($o, $_->{url}, 'media_info'); -	    ($suppl_CDs, $copy_rpms_on_disk) = get_media_cfg($o, $phys_m, $packages, $_->{selected_names}, $_->{force_rpmsrate}); +	    $phys_m = url2mounted_phys_medium($o, $_->{url}, 'media_info'); +            local $phys_m->{is_suppl} = $_->{url} ne "drakx://media"; # so that _get_media_url() works +            ($suppl_CDs, $copy_rpms_on_disk) = get_media_cfg($o, $phys_m, $packages, $_->{selected_names}, $_->{force_rpmsrate});  	} elsif ($_->{type} eq 'media') { -	    my $phys_m = url2mounted_phys_medium($o, $_->{url}); +	    $phys_m = url2mounted_phys_medium($o, $_->{url});  	    get_standalone_medium($o, $phys_m, $packages, { name => $_->{id} =~ /media=(.*)/ && $1 });  	} elsif ($_->{type} eq 'media_cfg_isos') {  	    my ($dir_url, $iso, $rel_path) = $_->{url} =~ m!(.*)/(.*\.iso):(/.*)! or die "bad media_cfg_isos url $_->{url}";  	    my $dir_medium = url2mounted_phys_medium($o, $dir_url);  	    $dir_medium->{options} =~ s/\bnoauto\b,?//; -	    my $phys_m = iso_phys_media($dir_medium, $iso, $rel_path); +	    $phys_m = _iso_phys_media($dir_medium, $iso, $rel_path);  	    push @{$o->{all_hds}{loopbacks}}, $phys_m;  	    ($suppl_CDs, $copy_rpms_on_disk) = get_media_cfg($o, $phys_m, $packages, $_->{selected_names}, $_->{force_rpmsrate});  	} else {  	    log::l("unknown media type $_->{type}, skipping");  	}      } +      log::l("suppl_CDs=$suppl_CDs copy_rpms_on_disk=$copy_rpms_on_disk");      $suppl_CDs, $copy_rpms_on_disk;  } +sub adjust_paths_in_urpmi_cfg { +    my ($urpm) = @_; + +    require Clone; +    local $urpm->{media} = Clone::clone($urpm->{media}); +    foreach my $medium (@{$urpm->{media}}) { +        my $phys_m = $medium->{phys_medium}; +        if ($phys_m->{method} eq 'cdrom') { +            $medium->{url} =~ s!^.*?/media/!$phys_m->{url}/!; +        } elsif (member($phys_m->{method}, qw(disk nfs))) { +            # use the real mount point: +            if ($medium->{url} =~ m!/tmp/image(/media)?!) { +                $medium->{url} =~ s!/tmp/image(/media)?!$phys_m->{mntpoint}$phys_m->{rel_path}!; +            } else { +                # just remove $::prefix and we already have the real mount point: +                $medium->{url} =~ s!^$::prefix!!; +            } +        } +    } +    urpm::media::write_config($urpm); +} +  sub remove_from_fstab {      my ($all_hds, $phys_m) = @_;      @{$all_hds->{nfss}} = grep { $_ != $phys_m } @{$all_hds->{nfss}} if $phys_m->{method} eq 'nfs';  } -sub find_and_add_to_fstab { +sub _find_and_add_to_fstab {      my ($all_hds, $phys_m, $b_force_mount) = @_;      if (my $existant = find { $_->{device} eq $phys_m->{device} } fs::get::really_all_fstab($all_hds)) { @@ -582,24 +571,24 @@ sub find_and_add_to_fstab {  sub url2mounted_phys_medium {      my ($o, $url, $o_rel_file, $o_name) = @_; -    my $phys_m = url2phys_medium($o, $url); +    my $phys_m = _url2phys_medium($o, $url);      $phys_m->{name} = $o_name if $o_name; #- useful for CDs which prompts a name in change_phys_medium      change_phys_medium($phys_m, $o_rel_file, $o->{packages}) or return;      $phys_m;  } -sub url2phys_medium { +sub _url2phys_medium {      my ($o, $url) = @_;      my ($method, $path) = $url =~ m!([^:]*)://(.*)! or internal_error("bad url $url");      if ($method eq 'drakx') {  	my $m = { %{$o->{stage2_phys_medium}}, is_stage2_phys_medium => 1 };  	if ($m->{loopback_device}) { -	    $m->{loopback_device} = find_and_add_to_fstab($o->{all_hds}, $m->{loopback_device}, 'force_mount'); +	    $m->{loopback_device} = _find_and_add_to_fstab($o->{all_hds}, $m->{loopback_device}, 'force_mount');  	}  	$m->{url} .= "/$path";  	$m->{rel_path} .= "/$path" if $m->{device}; -	$m = find_and_add_to_fstab($o->{all_hds}, $m) if $m->{device}; -	phys_medium_is_mounted($m); +	$m = _find_and_add_to_fstab($o->{all_hds}, $m) if $m->{device}; +	_phys_medium_is_mounted($m);  	$m;      } elsif ($method eq 'cdrom') {  	my $cdrom = first(detect_devices::cdroms()); @@ -607,10 +596,10 @@ sub url2phys_medium {  	    url => $url, method => $method, fs_type => 'iso9660', device => $cdrom->{device},   	    rel_path => "/$path",  	}; -	my $m_ = find_and_add_to_fstab($o->{all_hds}, $m); +	my $m_ = _find_and_add_to_fstab($o->{all_hds}, $m);  	if ($m_->{name}) {  	    #- we need a new phys medium, different from current CD -	    $m_ = get_phys_media_cdrom($m_, ''); +	    $m_ = _get_phys_media_cdrom($m_, '');  	    #- we also need to enforce what we want, especially rel_path  	    put_in_hash($m_, $m);  	} @@ -622,150 +611,97 @@ sub url2phys_medium {  	    url => $url, method => $method,  	    fs_type => 'nfs', device => "$server:$nfs_dir", faked_device => 1,  	}; -	find_and_add_to_fstab($o->{all_hds}, $m); +	_find_and_add_to_fstab($o->{all_hds}, $m);      } else {  	{ url => $url, method => $method };      }  } +sub _get_media_url { +    my ($o, $phys_medium) = @_; +    my $uri; +    if ($phys_medium->{is_suppl}) { +        if (member($phys_medium->{method}, qw(ftp http https))) { +            $uri = $phys_medium->{url}; +            $uri =~ s!/media$!!; +        } elsif (member($phys_medium->{method}, qw(cdrom nfs))) { +            $uri = "$::prefix/$phys_medium->{mntpoint}"; +            my $arch = arch() =~ /i.86/ ? $MDK::Common::System::compat_arch{arch()} : arch(); +            $uri .= "/$arch" if -d "$uri/$arch"; +        } +    } else { +        $uri = $o->{stage2_phys_medium}{url} =~ m!^(https?|ftp)://! && $o->{stage2_phys_medium}{url} || +          $phys_medium->{method} =~ m!^(ftp|https?)://! && $phys_medium->{method} || '/tmp/image'; +    } +    $uri; + } +  sub get_media_cfg {      my ($o, $phys_medium, $packages, $selected_names, $force_rpmsrate) = @_; -    my ($distribconf, $hdlists); +    my @media = @{$packages->{media}}; + +    my ($distribconf);      if (getAndSaveFile_($phys_medium, 'media_info/media.cfg', '/tmp/media.cfg')) { -	($distribconf, $hdlists) = parse_media_cfg('/tmp/media.cfg'); +	($distribconf) = _parse_media_cfg('/tmp/media.cfg');      } else { -	getAndSaveFile_($phys_medium, 'media_info/hdlists', '/tmp/hdlists') -	  or die "media.cfg not found"; -	($distribconf, $hdlists) = parse_hdlists('/tmp/hdlists'); -    } - -    if (defined $selected_names) { -        my @names = split ',', $selected_names; -        foreach my $h (@$hdlists) { -            $h->{selected} = member($h->{name}, @names); -        } +        die "media.cfg not found";      } -    my $suppl_CDs = $distribconf->{suppl} || $o->{supplmedia} || 0; +    my $suppl_CDs = defined $o->{supplmedia} ? $o->{supplmedia} : $distribconf->{suppl} || 0;      my $deselectionAllowed = $distribconf->{askmedia} || $o->{askmedia} || 0; -    associate_phys_media($o->{all_hds}, $phys_medium, $hdlists); +    log::l(Data::Dumper->Dump([ $phys_medium ], [ 'phys_medium' ])); +    log::l(Data::Dumper->Dump([ $o->{stage2_phys_medium} ], [ 'stage2_phys_medium' ])); +    my $uri = _get_media_url($o, $phys_medium); +    log::l("adding distrib media from $uri"); -    if ($deselectionAllowed && !@{$packages->{media}}) { -	my $allow = allow_copy_rpms_on_disk($phys_medium, $hdlists); -	$o->ask_deselect_media__copy_on_disk($hdlists, $allow && \$o->{copy_rpms_on_disk}) if $allow || @$hdlists > 1; -    } +    urpm::media::add_distrib_media($packages, undef, $uri, ask_media => undef); #allmedia => 1 + +    my @new_media = difference2($packages->{media}, \@media); +    _associate_phys_media($o->{all_hds}, $phys_medium, \@new_media); -    foreach my $h (@$hdlists) { -	get_medium($o, $phys_medium, $packages, $h); +    select_only_some_media(\@new_media, $selected_names) if defined $selected_names; + +    if ($deselectionAllowed && !@{$packages->{media}}) { +	my $allow = _allow_copy_rpms_on_disk($phys_medium, $packages->{media}); +	$o->ask_deselect_media__copy_on_disk($packages->{media}, $allow && \$o->{copy_rpms_on_disk}) if $allow || @{$packages->{media}} > 1;      }      log::l("get_media_cfg read " . int(@{$packages->{depslist}}) . " headers"); +    _get_compsUsers_pl($phys_medium, $force_rpmsrate); + +    $suppl_CDs, $o->{copy_rpms_on_disk}; +} +sub _get_compsUsers_pl { +    my ($phys_medium, $force_rpmsrate) = @_;      #- copy latest compssUsers.pl and rpmsrate somewhere locally      if ($force_rpmsrate || ! -e '/tmp/rpmsrate') { -	getAndSaveFile_($phys_medium, "media_info/compssUsers.pl", "/tmp/compssUsers.pl");  	getAndSaveFile_($phys_medium, "media_info/rpmsrate", "/tmp/rpmsrate");      } - - -    $suppl_CDs, $o->{copy_rpms_on_disk}; +    if ($force_rpmsrate || ! -e '/tmp/compssUsers.pl') { +	getAndSaveFile_($phys_medium, "media_info/compssUsers.pl", "/tmp/compssUsers.pl"); +    }  }  sub get_standalone_medium {      my ($in, $phys_m, $packages, $m) = @_; -    add2hash($m, { phys_medium => $phys_m, selected => 1, rel_hdlist => 'media_info/hdlist.cz' }); -    get_medium($in, $phys_m, $packages, $m); +    add2hash($m, { phys_medium => $phys_m, rel_hdlist => 'media_info/hdlist.cz' }); +    local $phys_m->{is_suppl} = 1; # so that _get_media_url() works +    _get_medium($in, $phys_m, $packages, $m);  } -sub get_medium { -    my ($in_wait, $phys_m, $packages, $m) = @_; - -    $m->{selected} or log::l("ignoring packages in $m->{rel_hdlist}"), return; - -    my $medium_id = int @{$packages->{media}}; -    $m->{fakemedium} = $m->{name} || $phys_m->{method}; -    $m->{fakemedium} =~ s!/!_!g; #- remove "/" from name -    if (find { $m->{fakemedium} eq $_->{fakemedium} } allMediums($packages)) { -	$m->{fakemedium} .= " (" . ($m->{rpmsdir} || $medium_id) . ")"; -	$m->{fakemedium} =~ s!/!_!g; #- remove "/" from rpmsdir -    } - -    log::l("trying to read $m->{rel_hdlist} for medium '$m->{fakemedium}'"); -     -    #- copy hdlist file directly to urpmi directory, this will be used -    #- for getting header of package during installation or after by urpmi. -    my $hdlist = hdlist_on_disk($m); -    { -	getAndSaveFile_progress($in_wait, N("Downloading file %s...", $m->{rel_hdlist}), -				$phys_m, $m->{rel_hdlist}, $hdlist) or die "no $m->{rel_hdlist} found"; - -	$m->{hdlist_size} = -s $hdlist; #- keep track of size for post-check. -    } +sub _get_medium { +    my ($_in_wait, $phys_m, $packages, $m) = @_; -    my $synthesis = urpmidir() . "/synthesis.hdlist.$m->{fakemedium}.cz"; -    { -	my $rel_synthesis = $m->{rel_hdlist}; -	$rel_synthesis =~ s!/hdlist!/synthesis.hdlist! or internal_error("bad {rel_hdlist} $m->{rel_hdlist}"); -	#- copy existing synthesis file too. -	getAndSaveFile_progress($in_wait, N("Downloading file %s...", $rel_synthesis), -				$phys_m, $rel_synthesis, $synthesis); -	$m->{synthesis_hdlist_size} = -s $synthesis; #- keep track of size for post-check. -    } - -    #- get all keys corresponding in the right pubkey file, -    #- they will be added in rpmdb later if not found. -    if (!$m->{pubkey}) { -	my $rel_pubkey = $m->{rel_hdlist}; -	$rel_pubkey =~ s!/hdlist(.*)\.cz!/pubkey$1! or internal_error("bad {rel_hdlist} $m->{rel_hdlist}"); -	if (my $pubkey = getFile_($phys_m, $rel_pubkey)) { -	    $m->{pubkey} = [ $packages->parse_armored_file($pubkey) ]; -	} -    } -    $m->{pubkey} ||= []; - -    #- for standalone medium not using media.cfg -    $phys_m->{name} ||= $m->{name}; - -    #- integrate medium in media list, only here to avoid download error (update) to be propagated. -    push @{$packages->{media}}, $m; - -    #- parse synthesis (if available) of directly hdlist (with packing). -    { -	my $nb_suppl_pkg_skipped = 0; -	my $callback = sub { -	    my (undef, $p) = @_; -	    my $uniq_pkg_seen = $packages->{uniq_pkg_seen} ||= {}; -	    if ($uniq_pkg_seen->{$p->fullname}++) { -		log::l("skipping " . scalar $p->fullname); -		++$nb_suppl_pkg_skipped; -		return 0; -	    } else { -		return 1; -	    } -	}; -	my $error; -	if (-s $synthesis) { -	    ($m->{start}, $m->{end}) = $packages->parse_synthesis($synthesis, callback => $callback) -	      or $error = "bad synthesis $synthesis for $m->{fakemedium}"; -	} elsif (-s $hdlist) { -	    ($m->{start}, $m->{end}) = $packages->parse_hdlist($hdlist, callback => $callback) -	      or $error = "bad hdlist $hdlist for $m->{fakemedium}"; -	} else { -	    $error = "fatal: no hdlist nor synthesis to read for $m->{fakemedium}"; -	} +    !$m->{ignore} or log::l("ignoring packages in $m->{rel_hdlist}"), return; -	if ($error) { -	    pop @{$packages->{media}}; -	    unlink $hdlist, $synthesis; -	    die $error; -	} else { -	    log::l("medium " . phys_medium_to_string($phys_m) . ", read " . ($m->{end} - $m->{start} + 1) . " packages in $m->{rel_hdlist}, $nb_suppl_pkg_skipped skipped"); -	} -    } +    my $url = _get_media_url({}, $phys_m); +    log::l("trying '$url'\n"); +    urpm::media::add_medium($packages, $m->{name} || 'Supplementary medium', $url, 0) or $packages->{fatal}(10, N("unable to add medium"));  } @@ -773,7 +709,7 @@ sub get_medium {  #-######################################################################################  #- Post installation RPMS from cdrom only, functions  #-###################################################################################### -sub setup_postinstall_rpms { +sub _setup_postinstall_rpms {      my ($in, $packages, $current_phys_m) = @_;      $postinstall_rpms and return; @@ -840,7 +776,7 @@ sub clean_postinstall_rpms() {  sub copy_rpms_on_disk {      my ($o) = @_; -    my $dest_dir = '/var/ftp/pub/Mandrivalinux/media'; +    my $dest_dir = '/var/ftp/pub/Mageialinux/media';      #- don't be afraid, cleanup old RPMs if upgrade      eval { rm_rf("$::prefix$dest_dir") if $o->{isUpgrade} };      mkdir_p("$::prefix$dest_dir"); @@ -865,17 +801,22 @@ sub copy_rpms_on_disk {  		#- keep in mind the asked medium has been refused.  		#- this means it is no longer selected.  		#- (but do not unselect supplementary CDs.) -		$m->{selected} = 0; +		$m->{ignore} = 1;  	    }  	} +	my $dest_medium_dir = $dest_dir . '/' . basename($rpmsdir); +	#- handle rpmsdir being ../../i586/media/main: we flatten it +	-e "$::prefix$dest_medium_dir" and $dest_medium_dir .= '32'; +	-e "$::prefix$dest_medium_dir" and next;  	my $total = install::any::count_files($rpmsdir); -	log::l("copying $rpmsdir to $::prefix$dest_dir ($total files)"); +	log::l("copying $rpmsdir to $::prefix$dest_medium_dir ($total files)");  	eval { -	    install::any::cp_with_progress($wait_message, 0, $total, $rpmsdir, "$::prefix$dest_dir"); +	    install::any::cp_with_progress_({}, $wait_message, $total, [$rpmsdir], "$::prefix$dest_medium_dir");  	};  	log::l($@) if $@; +	$m->{rpmsdir} = basename($dest_medium_dir);  	$m->{phys_medium} = $dest_phys_medium;      }      undef $wait; @@ -883,36 +824,13 @@ sub copy_rpms_on_disk {      our $copied_rpms_on_disk = 1;  } -sub install_urpmi__generate_names { -    my ($packages, $medium) = @_; - -    #- build a names file -    output("$::prefix/var/lib/urpmi/names.$medium->{fakemedium}", -	   map { $packages->{depslist}[$_]->name . "\n" } $medium->{start} .. $medium->{end}); -} -sub install_urpmi__generate_synthesis { -    my ($packages, $medium) = @_; - -    my $synthesis = "/var/lib/urpmi/synthesis.hdlist.$medium->{fakemedium}.cz"; - -    #- build synthesis file if there are still not existing (ie not copied from mirror). -    -s "$::prefix$synthesis" <= 32 or return; - -    log::l("building $synthesis"); - -    eval { $packages->build_synthesis( -	start     => $medium->{start}, -	end       => $medium->{end}, -	synthesis => "$::prefix$synthesis", -    ) }; -    $@ and log::l("build_synthesis failed: $@"); -} - -#- copied from urpm/media.pm -sub parse_url_with_login { -    my ($url) = @_; -    $url =~ m!([^:]*)://([^/:\@]*)(:([^/:\@]*))?\@([^/]*)(.*)! && -      { proto => $1, login => $2, password => $4, machine => $5, dir => $6 }; +sub _get_medium_dir { +    my ($phys_m) = @_; +    if (member($phys_m->{method}, qw(ftp http https cdrom))) { +        $phys_m->{url}; +    } else { +        "$phys_m->{mntpoint}$phys_m->{rel_path}"; +    }  }  sub install_urpmi { @@ -924,48 +842,23 @@ sub install_urpmi {      #- clean to avoid opening twice the rpm db.      delete $packages->{rpmdb}; -    #- import pubkey in rpmdb. -    my $db = install::pkgs::open_rpm_db_rw(); -    $packages->parse_pubkeys(db => $db); -    foreach my $medium (@media) { -	$packages->import_needed_pubkeys($medium->{pubkey}, db => $db, callback => sub { -					     my (undef, undef, $_k, $id, $imported) = @_; -					     if ($id) { -						 log::l(($imported ? "imported" : "found") . " key=$id for medium $medium->{name}"); -						 $medium->{key_ids}{$id} = undef; -					     } -					 }); -    } -      my (@cfg, @netrc);      foreach my $medium (@media) { -	if ($medium->{selected}) { -            my ($dir, $removable_device, $static); +	if (!$medium->{ignore}) { +            my ($dir, $removable_device);  	    my $phys_m = $medium->{phys_medium}; -            if ($phys_m->{method} eq 'ftp' || $phys_m->{method} eq 'http') { -		$dir = $phys_m->{url}; -	    } else { -		#- for cdrom, removable://... is best since it mounts *and* umounts cdrom -		#- for iso files, removable://... doesn't work correctly -		my $urpmi_method = $phys_m->{method} eq 'cdrom' ? 'removable' : 'file'; -		$dir = "$urpmi_method:/$phys_m->{mntpoint}$phys_m->{rel_path}"; -		if ($phys_m->{method} eq 'iso') { -		    $removable_device = $phys_m->{loopback_device}{mntpoint} . $phys_m->{loopback_file}; -		} elsif ($phys_m->{method} eq 'cdrom') { -		    $removable_device = devices::make($phys_m->{device}); -		    $static = 1; -		} -	    } +            $dir = _get_medium_dir($phys_m); -	    $dir = MDK::Common::File::concat_symlink($dir, $medium->{rpmsdir}); +            if ($phys_m->{method} eq 'iso') { +                $removable_device = $phys_m->{loopback_device}{mntpoint} . $phys_m->{loopback_file}; +            } -	    install_urpmi__generate_names($packages, $medium); -	    install_urpmi__generate_synthesis($packages, $medium); +	    $dir = MDK::Common::File::concat_symlink($dir, $medium->{rpmsdir});  	    my ($qname, $qdir) = ($medium->{fakemedium}, $dir); -	    if (my $u = parse_url_with_login($qdir)) { +	    if (my $u = urpm::download::parse_url_with_login($qdir)) {  		$qdir = sprintf('%s://%s@%s%s', $u->{proto}, $u->{login}, $u->{machine}, $u->{dir});  		push @netrc, sprintf("machine %s login %s password %s\n", $u->{machine}, $u->{login}, $u->{password});  	    } @@ -975,15 +868,12 @@ sub install_urpmi {  	    #- output new urpmi.cfg format here.  	    push @cfg, map { "$_\n" }   	      "$qname $qdir {",  -	      "  media_info_dir: media_info", -		if_(keys(%{$medium->{key_ids}}),  -	      "  key-ids: " . join(',', keys %{$medium->{key_ids}})), +		if_($medium->{'key-ids'}, +	      "  key-ids: " . $medium->{'key-ids'}),  		if_($removable_device,   	      "  removable: $removable_device"),  		if_($medium->{update},  	      "  update"),  -		if_($static, -	      "  static"),  	      "}";  	} else {  	    #- remove deselected media by removing copied hdlist and synthesis files | 
