forked from josch/mmdebstrap
Factor out downloading packages with apt
This commit is contained in:
parent
8b58dc583e
commit
487237f9ae
1 changed files with 49 additions and 67 deletions
116
mmdebstrap
116
mmdebstrap
|
@ -977,6 +977,27 @@ sub run_apt_progress {
|
|||
return;
|
||||
}
|
||||
|
||||
sub run_apt_download_progress {
|
||||
my $options = shift;
|
||||
my %result = shift;
|
||||
if ($options->{dryrun}) {
|
||||
info "simulate downloading packages with apt...";
|
||||
} else {
|
||||
info "downloading packages with apt...";
|
||||
}
|
||||
return run_apt_progress({
|
||||
ARGV => [
|
||||
'apt-get',
|
||||
'--yes',
|
||||
'-oDebug::pkgDpkgPm=1',
|
||||
'-oDir::Log=/dev/null',
|
||||
$options->{dryrun} ? '-oAPT::Get::Simulate=true' : (),
|
||||
@{ $options->{APT_ARGV} },
|
||||
],
|
||||
%result
|
||||
});
|
||||
}
|
||||
|
||||
sub run_chroot {
|
||||
my $cmd = shift;
|
||||
my $options = shift;
|
||||
|
@ -2079,12 +2100,20 @@ sub run_download() {
|
|||
# apt and libapt treats apt as essential. If we want to install less
|
||||
# (essential variant) then we have to compute the package set ourselves.
|
||||
# Same if we want to install priority based variants.
|
||||
my %result = ();
|
||||
if (not $options->{dryrun}) {
|
||||
# if there are already packages in /var/cache/apt/archives/,
|
||||
# we need to know which are part of the solution by apt
|
||||
if (scalar @cached_debs > 0) {
|
||||
$result{EIPP_RES} = \@dl_debs;
|
||||
}
|
||||
}
|
||||
if (any { $_ eq $options->{variant} } ('extract', 'custom')) {
|
||||
if (scalar @{ $options->{include} } == 0) {
|
||||
info "nothing to download -- skipping...";
|
||||
return ([], []);
|
||||
}
|
||||
my %pkgs_to_install;
|
||||
my @apt_argv = ['install'];
|
||||
for my $incl (@{ $options->{include} }) {
|
||||
for my $pkg (split /[,\s]+/, $incl) {
|
||||
# strip leading and trailing whitespace
|
||||
|
@ -2093,33 +2122,16 @@ sub run_download() {
|
|||
if ($pkg eq '') {
|
||||
next;
|
||||
}
|
||||
$pkgs_to_install{$pkg} = ();
|
||||
push @apt_argv, $pkg;
|
||||
}
|
||||
}
|
||||
|
||||
my %result = ();
|
||||
if ($options->{dryrun}) {
|
||||
info "simulate downloading packages with apt...";
|
||||
} else {
|
||||
# if there are already packages in /var/cache/apt/archives/, we
|
||||
# need to know which are part of the solution by apt
|
||||
if (scalar @cached_debs > 0) {
|
||||
$result{EIPP_RES} = \@dl_debs;
|
||||
}
|
||||
info "downloading packages with apt...";
|
||||
}
|
||||
run_apt_progress({
|
||||
ARGV => [
|
||||
'apt-get',
|
||||
'--yes',
|
||||
'-oDebug::pkgDpkgPm=1',
|
||||
'-oDir::Log=/dev/null',
|
||||
$options->{dryrun} ? '-oAPT::Get::Simulate=true' : (),
|
||||
'install'
|
||||
],
|
||||
PKGS => [keys %pkgs_to_install],
|
||||
%result
|
||||
});
|
||||
run_apt_download_progress({
|
||||
APT_ARGV => @apt_argv,
|
||||
dryrun => $options->{dryrun},
|
||||
},
|
||||
%result
|
||||
);
|
||||
} elsif ($options->{variant} eq 'apt') {
|
||||
# if we just want to install Essential:yes packages, apt and their
|
||||
# dependencies then we can make use of libapt treating apt as
|
||||
|
@ -2134,28 +2146,12 @@ sub run_download() {
|
|||
# remind me in 5+ years that I said that after I wrote
|
||||
# in the bugreport: "Are you crazy?!? Nobody in his
|
||||
# right mind would even suggest depending on it!")
|
||||
my %result = ();
|
||||
if ($options->{dryrun}) {
|
||||
info "simulate downloading packages with apt...";
|
||||
} else {
|
||||
# if there are already packages in /var/cache/apt/archives/, we
|
||||
# need to know which are part of the solution by apt
|
||||
if (scalar @cached_debs > 0) {
|
||||
$result{EIPP_RES} = \@dl_debs;
|
||||
}
|
||||
info "downloading packages with apt...";
|
||||
}
|
||||
run_apt_progress({
|
||||
ARGV => [
|
||||
'apt-get',
|
||||
'--yes',
|
||||
'-oDebug::pkgDpkgPm=1',
|
||||
'-oDir::Log=/dev/null',
|
||||
$options->{dryrun} ? '-oAPT::Get::Simulate=true' : (),
|
||||
'dist-upgrade'
|
||||
],
|
||||
%result
|
||||
});
|
||||
run_apt_download_progress({
|
||||
APT_ARGV => ['dist-upgrade'],
|
||||
dryrun => $options->{dryrun},
|
||||
},
|
||||
%result
|
||||
);
|
||||
} elsif (
|
||||
any { $_ eq $options->{variant} }
|
||||
('essential', 'standard', 'important', 'required', 'buildd')
|
||||
|
@ -2164,24 +2160,8 @@ sub run_download() {
|
|||
# 17:27 < DonKult> (?essential includes 'apt' through)
|
||||
# 17:30 < josch> DonKult: no, because pkgCacheGen::ForceEssential ",";
|
||||
# 17:32 < DonKult> touché
|
||||
my %result = ();
|
||||
if ($options->{dryrun}) {
|
||||
info "simulate downloading packages with apt...";
|
||||
} else {
|
||||
# if there are already packages in /var/cache/apt/archives/, we
|
||||
# need to know which are part of the solution by apt
|
||||
if (scalar @cached_debs > 0) {
|
||||
$result{EIPP_RES} = \@dl_debs;
|
||||
}
|
||||
info "downloading packages with apt...";
|
||||
}
|
||||
run_apt_progress({
|
||||
ARGV => [
|
||||
'apt-get',
|
||||
'--yes',
|
||||
'-oDebug::pkgDpkgPm=1',
|
||||
'-oDir::Log=/dev/null',
|
||||
$options->{dryrun} ? '-oAPT::Get::Simulate=true' : (),
|
||||
run_apt_download_progress({
|
||||
APT_ARGV => [
|
||||
'install',
|
||||
'?narrow('
|
||||
. (
|
||||
|
@ -2196,8 +2176,10 @@ sub run_download() {
|
|||
. $options->{nativearch}
|
||||
. '),?essential)'
|
||||
],
|
||||
%result
|
||||
});
|
||||
dryrun => $options->{dryrun},
|
||||
},
|
||||
%result
|
||||
);
|
||||
} else {
|
||||
error "unknown variant: $options->{variant}";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue