forked from josch/mmdebstrap
add --skip option
This commit is contained in:
parent
1076e9a78d
commit
46f477f339
1 changed files with 93 additions and 71 deletions
56
mmdebstrap
56
mmdebstrap
|
@ -2401,9 +2401,9 @@ 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 => [
|
||||||
|
@ -2415,24 +2415,38 @@ sub run_cleanup() {
|
||||||
});
|
});
|
||||||
run_apt_progress(
|
run_apt_progress(
|
||||||
{ ARGV => ['apt-get', 'clean'], CHDIR => $options->{root} });
|
{ ARGV => ['apt-get', 'clean'], CHDIR => $options->{root} });
|
||||||
|
|
||||||
|
# apt since 1.6 creates the auxfiles directory. If apt inside the
|
||||||
|
# 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: $!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (any { $_ eq 'cleanup/mmdebstrap' } @{ $options->{skip} }) {
|
||||||
|
info "skipping cleanup/mmdebstrap as requested";
|
||||||
|
} else {
|
||||||
|
# clean up temporary configuration file
|
||||||
|
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}) {
|
if (defined $ENV{APT_CONFIG} && -e $ENV{APT_CONFIG}) {
|
||||||
unlink $ENV{APT_CONFIG}
|
unlink $ENV{APT_CONFIG}
|
||||||
or error "failed to 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
|
|
||||||
# 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: $!";
|
|
||||||
}
|
|
||||||
|
|
||||||
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: $!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (any { $_ eq 'cleanup/reproducible' } @{ $options->{skip} }) {
|
||||||
|
info "skipping cleanup/reproducible as requested";
|
||||||
|
} else {
|
||||||
# clean up certain files to make output reproducible
|
# clean up certain files to make output reproducible
|
||||||
foreach my $fname (
|
foreach my $fname (
|
||||||
'/var/log/dpkg.log', '/var/log/apt/history.log',
|
'/var/log/dpkg.log', '/var/log/apt/history.log',
|
||||||
|
@ -2450,18 +2464,22 @@ sub run_cleanup() {
|
||||||
# from machine-id(5):
|
# from machine-id(5):
|
||||||
# For operating system images which are created once and used on
|
# For operating system images which are created once and used on
|
||||||
# multiple machines, for example for containers or in the cloud,
|
# multiple machines, for example for containers or in the cloud,
|
||||||
# /etc/machine-id should be an empty file in the generic file system
|
# /etc/machine-id should be an empty file in the generic file
|
||||||
# image. An ID will be generated during boot and saved to this file if
|
# system image. An ID will be generated during boot and saved to
|
||||||
# possible. Having an empty file in place is useful because it allows a
|
# this file if possible. Having an empty file in place is useful
|
||||||
# temporary file to be bind-mounted over the real file, in case the
|
# because it allows a temporary file to be bind-mounted over the
|
||||||
# image is used read-only.
|
# real file, in case the image is used read-only.
|
||||||
unlink "$options->{root}/etc/machine-id"
|
unlink "$options->{root}/etc/machine-id"
|
||||||
or error "cannot unlink /etc/machine-id: $!";
|
or error "cannot unlink /etc/machine-id: $!";
|
||||||
open my $fh, '>', "$options->{root}/etc/machine-id"
|
open my $fh, '>', "$options->{root}/etc/machine-id"
|
||||||
or error "failed to open(): $!";
|
or error "failed to open(): $!";
|
||||||
close $fh;
|
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
|
# remove any possible leftovers in /tmp but warn about it
|
||||||
if (-d "$options->{root}/tmp") {
|
if (-d "$options->{root}/tmp") {
|
||||||
opendir(my $dh, "$options->{root}/tmp")
|
opendir(my $dh, "$options->{root}/tmp")
|
||||||
|
@ -2471,7 +2489,8 @@ sub run_cleanup() {
|
||||||
next if $entry eq ".";
|
next if $entry eq ".";
|
||||||
next if $entry eq "..";
|
next if $entry eq "..";
|
||||||
warning "deleting files in /tmp: $entry";
|
warning "deleting files in /tmp: $entry";
|
||||||
remove_tree("$options->{root}/tmp/$entry", { error => \my $err });
|
remove_tree("$options->{root}/tmp/$entry",
|
||||||
|
{ error => \my $err });
|
||||||
if (@$err) {
|
if (@$err) {
|
||||||
for my $diag (@$err) {
|
for my $diag (@$err) {
|
||||||
my ($file, $message) = %$diag;
|
my ($file, $message) = %$diag;
|
||||||
|
@ -2482,6 +2501,7 @@ sub run_cleanup() {
|
||||||
}
|
}
|
||||||
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…
Reference in a new issue