add --skip option

debextract
parent 1076e9a78d
commit 46f477f339
Signed by untrusted user: josch
GPG Key ID: F2CBA5C78FBD83E1

@ -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} # apt since 1.6 creates the auxfiles directory. If apt inside the
or error "failed to unlink $ENV{APT_CONFIG}: $!"; # chroot is older than that, then it will not know how to clean it.
if (-e "$options->{root}/var/lib/apt/lists/auxfiles") {
rmdir "$options->{root}/var/lib/apt/lists/auxfiles"
or die "cannot rmdir /var/lib/apt/lists/auxfiles: $!";
}
} }
# apt since 1.6 creates the auxfiles directory. If apt inside the chroot if (any { $_ eq 'cleanup/mmdebstrap' } @{ $options->{skip} }) {
# is older than that, then it will not know how to clean it. info "skipping cleanup/mmdebstrap as requested";
if (-e "$options->{root}/var/lib/apt/lists/auxfiles") { } else {
rmdir "$options->{root}/var/lib/apt/lists/auxfiles" # clean up temporary configuration file
or die "cannot rmdir /var/lib/apt/lists/auxfiles: $!"; unlink "$options->{root}/etc/apt/apt.conf.d/00mmdebstrap"
} or error "failed to unlink /etc/apt/apt.conf.d/00mmdebstrap: $!";
if (defined $ENV{APT_CONFIG} && -e $ENV{APT_CONFIG}) {
unlink $ENV{APT_CONFIG}
or error "failed to unlink $ENV{APT_CONFIG}: $!";
}
if (defined $options->{qemu} if (defined $options->{qemu}
and any { $_ eq $options->{mode} } ('root', 'unshare')) { and any { $_ eq $options->{mode} } ('root', 'unshare')) {
unlink "$options->{root}/usr/bin/qemu-$options->{qemu}-static" unlink "$options->{root}/usr/bin/qemu-$options->{qemu}-static"
or error "cannot unlink /usr/bin/qemu-$options->{qemu}-static: $!"; or error
"cannot unlink /usr/bin/qemu-$options->{qemu}-static: $!";
}
} }
# clean up certain files to make output reproducible if (any { $_ eq 'cleanup/reproducible' } @{ $options->{skip} }) {
foreach my $fname ( info "skipping cleanup/reproducible as requested";
'/var/log/dpkg.log', '/var/log/apt/history.log', } else {
'/var/log/apt/term.log', '/var/log/alternatives.log', # clean up certain files to make output reproducible
'/var/cache/ldconfig/aux-cache', '/var/log/apt/eipp.log.xz' foreach my $fname (
) { '/var/log/dpkg.log', '/var/log/apt/history.log',
my $path = "$options->{root}$fname"; '/var/log/apt/term.log', '/var/log/alternatives.log',
if (!-e $path) { '/var/cache/ldconfig/aux-cache', '/var/log/apt/eipp.log.xz'
next; ) {
my $path = "$options->{root}$fname";
if (!-e $path) {
next;
}
unlink $path or error "cannot unlink $path: $!";
}
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;
} }
unlink $path or error "cannot unlink $path: $!";
}
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;
} }
# remove any possible leftovers in /tmp but warn about it if (any { $_ eq 'cleanup/tmp' } @{ $options->{skip} }) {
if (-d "$options->{root}/tmp") { info "skipping cleanup/tmp as requested";
opendir(my $dh, "$options->{root}/tmp") } else {
or error "Can't opendir($options->{root}/tmp): $!"; # remove any possible leftovers in /tmp but warn about it
while (my $entry = readdir $dh) { if (-d "$options->{root}/tmp") {
# skip the "." and ".." entries opendir(my $dh, "$options->{root}/tmp")
next if $entry eq "."; or error "Can't opendir($options->{root}/tmp): $!";
next if $entry eq ".."; while (my $entry = readdir $dh) {
warning "deleting files in /tmp: $entry"; # skip the "." and ".." entries
remove_tree("$options->{root}/tmp/$entry", { error => \my $err }); next if $entry eq ".";
if (@$err) { next if $entry eq "..";
for my $diag (@$err) { warning "deleting files in /tmp: $entry";
my ($file, $message) = %$diag; remove_tree("$options->{root}/tmp/$entry",
if ($file eq '') { warning "general error: $message"; } { error => \my $err });
else { warning "problem unlinking $file: $message"; } 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)) {

Loading…
Cancel
Save