add --skip option

This commit is contained in:
Johannes 'josch' Schauer 2020-04-10 00:00:36 +02:00
parent 1076e9a78d
commit 46f477f339
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -2401,86 +2401,106 @@ sub run_install() {
sub run_cleanup() { sub run_cleanup() {
my $options = shift; my $options = shift;
# clean up temporary configuration file if (any { $_ eq 'cleanup/apt' } @{ $options->{skip} }) {
unlink "$options->{root}/etc/apt/apt.conf.d/00mmdebstrap" info "skipping cleanup/apt as requested";
or error "failed to unlink /etc/apt/apt.conf.d/00mmdebstrap: $!"; } else {
info "cleaning package lists and apt cache..."; info "cleaning package lists and apt cache...";
run_apt_progress({ run_apt_progress({
ARGV => [ ARGV => [
'apt-get', '--option', 'apt-get', '--option',
'Dir::Etc::SourceList=/dev/null', '--option', 'Dir::Etc::SourceList=/dev/null', '--option',
'Dir::Etc::SourceParts=/dev/null', 'update' 'Dir::Etc::SourceParts=/dev/null', 'update'
], ],
CHDIR => $options->{root}, CHDIR => $options->{root},
}); });
run_apt_progress( run_apt_progress(
{ ARGV => ['apt-get', 'clean'], CHDIR => $options->{root} }); { ARGV => ['apt-get', 'clean'], CHDIR => $options->{root} });
if (defined $ENV{APT_CONFIG} && -e $ENV{APT_CONFIG}) {
unlink $ENV{APT_CONFIG}
or error "failed to unlink $ENV{APT_CONFIG}: $!";
}
# apt since 1.6 creates the auxfiles directory. If apt inside the chroot # apt since 1.6 creates the auxfiles directory. If apt inside the
# is older than that, then it will not know how to clean it. # chroot is older than that, then it will not know how to clean it.
if (-e "$options->{root}/var/lib/apt/lists/auxfiles") { if (-e "$options->{root}/var/lib/apt/lists/auxfiles") {
rmdir "$options->{root}/var/lib/apt/lists/auxfiles" rmdir "$options->{root}/var/lib/apt/lists/auxfiles"
or die "cannot rmdir /var/lib/apt/lists/auxfiles: $!"; or die "cannot rmdir /var/lib/apt/lists/auxfiles: $!";
}
if (defined $options->{qemu}
and any { $_ eq $options->{mode} } ('root', 'unshare')) {
unlink "$options->{root}/usr/bin/qemu-$options->{qemu}-static"
or error "cannot unlink /usr/bin/qemu-$options->{qemu}-static: $!";
}
# clean up certain files to make output reproducible
foreach my $fname (
'/var/log/dpkg.log', '/var/log/apt/history.log',
'/var/log/apt/term.log', '/var/log/alternatives.log',
'/var/cache/ldconfig/aux-cache', '/var/log/apt/eipp.log.xz'
) {
my $path = "$options->{root}$fname";
if (!-e $path) {
next;
} }
unlink $path or error "cannot unlink $path: $!";
} }
if (-e "$options->{root}/etc/machine-id") { if (any { $_ eq 'cleanup/mmdebstrap' } @{ $options->{skip} }) {
# from machine-id(5): info "skipping cleanup/mmdebstrap as requested";
# For operating system images which are created once and used on } else {
# multiple machines, for example for containers or in the cloud, # clean up temporary configuration file
# /etc/machine-id should be an empty file in the generic file system unlink "$options->{root}/etc/apt/apt.conf.d/00mmdebstrap"
# image. An ID will be generated during boot and saved to this file if or error "failed to unlink /etc/apt/apt.conf.d/00mmdebstrap: $!";
# possible. Having an empty file in place is useful because it allows a
# temporary file to be bind-mounted over the real file, in case the if (defined $ENV{APT_CONFIG} && -e $ENV{APT_CONFIG}) {
# image is used read-only. unlink $ENV{APT_CONFIG}
unlink "$options->{root}/etc/machine-id" or error "failed to unlink $ENV{APT_CONFIG}: $!";
or error "cannot unlink /etc/machine-id: $!"; }
open my $fh, '>', "$options->{root}/etc/machine-id"
or error "failed to open(): $!"; if (defined $options->{qemu}
close $fh; and any { $_ eq $options->{mode} } ('root', 'unshare')) {
unlink "$options->{root}/usr/bin/qemu-$options->{qemu}-static"
or error
"cannot unlink /usr/bin/qemu-$options->{qemu}-static: $!";
}
} }
# remove any possible leftovers in /tmp but warn about it if (any { $_ eq 'cleanup/reproducible' } @{ $options->{skip} }) {
if (-d "$options->{root}/tmp") { info "skipping cleanup/reproducible as requested";
opendir(my $dh, "$options->{root}/tmp") } else {
or error "Can't opendir($options->{root}/tmp): $!"; # clean up certain files to make output reproducible
while (my $entry = readdir $dh) { foreach my $fname (
# skip the "." and ".." entries '/var/log/dpkg.log', '/var/log/apt/history.log',
next if $entry eq "."; '/var/log/apt/term.log', '/var/log/alternatives.log',
next if $entry eq ".."; '/var/cache/ldconfig/aux-cache', '/var/log/apt/eipp.log.xz'
warning "deleting files in /tmp: $entry"; ) {
remove_tree("$options->{root}/tmp/$entry", { error => \my $err }); my $path = "$options->{root}$fname";
if (@$err) { if (!-e $path) {
for my $diag (@$err) { next;
my ($file, $message) = %$diag; }
if ($file eq '') { warning "general error: $message"; } unlink $path or error "cannot unlink $path: $!";
else { warning "problem unlinking $file: $message"; } }
if (-e "$options->{root}/etc/machine-id") {
# from machine-id(5):
# For operating system images which are created once and used on
# multiple machines, for example for containers or in the cloud,
# /etc/machine-id should be an empty file in the generic file
# system image. An ID will be generated during boot and saved to
# this file if possible. Having an empty file in place is useful
# because it allows a temporary file to be bind-mounted over the
# real file, in case the image is used read-only.
unlink "$options->{root}/etc/machine-id"
or error "cannot unlink /etc/machine-id: $!";
open my $fh, '>', "$options->{root}/etc/machine-id"
or error "failed to open(): $!";
close $fh;
}
}
if (any { $_ eq 'cleanup/tmp' } @{ $options->{skip} }) {
info "skipping cleanup/tmp as requested";
} else {
# remove any possible leftovers in /tmp but warn about it
if (-d "$options->{root}/tmp") {
opendir(my $dh, "$options->{root}/tmp")
or error "Can't opendir($options->{root}/tmp): $!";
while (my $entry = readdir $dh) {
# skip the "." and ".." entries
next if $entry eq ".";
next if $entry eq "..";
warning "deleting files in /tmp: $entry";
remove_tree("$options->{root}/tmp/$entry",
{ error => \my $err });
if (@$err) {
for my $diag (@$err) {
my ($file, $message) = %$diag;
if ($file eq '') { warning "general error: $message"; }
else { warning "problem unlinking $file: $message"; }
}
} }
} }
closedir($dh);
} }
closedir($dh);
} }
return; return;
} }
@ -2908,6 +2928,7 @@ sub main() {
essential_hook => [], essential_hook => [],
customize_hook => [], customize_hook => [],
dryrun => 0, dryrun => 0,
skip => [],
}; };
my $logfile = undef; my $logfile = undef;
my $format = 'auto'; my $format = 'auto';
@ -2975,6 +2996,7 @@ sub main() {
# here prepare for long suffering in dependency hell. # here prepare for long suffering in dependency hell.
'simulate' => \$options->{dryrun}, 'simulate' => \$options->{dryrun},
'dry-run' => \$options->{dryrun}, 'dry-run' => \$options->{dryrun},
'skip=s@' => \$options->{skip},
) or pod2usage(-exitval => 2, -verbose => 1); ) or pod2usage(-exitval => 2, -verbose => 1);
if (defined($logfile)) { if (defined($logfile)) {