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