Control: tag -1 + pending Attached patch seems to work.
diff --git a/mmdebstrap b/mmdebstrap index 6219035..003c1ca 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -1465,7 +1465,11 @@ sub setup { } # run setup hooks - run_hooks('setup', $options); + if (!$options->{dryrun}) { + run_hooks('setup', $options); + } else { + info "not running setup-hooks because of --dry-run"; + } info "running apt-get update..."; run_apt_progress({ @@ -1520,8 +1524,11 @@ sub setup { info "downloading packages with apt..."; run_apt_progress({ ARGV => [ - 'apt-get', '--yes', - '-oApt::Get::Download-Only=true', 'install' + 'apt-get', + '--yes', + '-oApt::Get::Download-Only=true', + $options->{dryrun} ? '-oAPT::Get::Simulate=true' : (), + 'install' ], PKGS => [@pkgs_to_install], }); @@ -1542,8 +1549,11 @@ sub setup { info "downloading packages with apt..."; run_apt_progress({ ARGV => [ - 'apt-get', '--yes', - '-oApt::Get::Download-Only=true', 'dist-upgrade' + 'apt-get', + '--yes', + '-oApt::Get::Download-Only=true', + $options->{dryrun} ? '-oAPT::Get::Simulate=true' : (), + 'dist-upgrade' ], }); } elsif ( @@ -1648,8 +1658,11 @@ sub setup { info "downloading packages with apt..."; run_apt_progress({ ARGV => [ - 'apt-get', '--yes', - '-oApt::Get::Download-Only=true', 'install' + 'apt-get', + '--yes', + '-oApt::Get::Download-Only=true', + $options->{dryrun} ? '-oAPT::Get::Simulate=true' : (), + 'install' ], PKGS => [keys %ess_pkgs], }); @@ -1659,7 +1672,7 @@ sub setup { # extract the downloaded packages my @essential_pkgs; - { + if (!$options->{dryrun}) { my $apt_archives = "/var/cache/apt/archives/"; opendir my $dh, "$options->{root}/$apt_archives" or error "cannot read $apt_archives"; @@ -1674,28 +1687,30 @@ sub setup { push @essential_pkgs, $deb; } close $dh; - } - if (scalar @essential_pkgs == 0) { - # check if a file:// URI was used - open(my $pipe_apt, '-|', 'apt-get', 'indextargets', '--format', - '$(URI)', 'Created-By: Packages') - or error "cannot start apt-get indextargets: $!"; - while (my $uri = <$pipe_apt>) { - if ($uri =~ /^file:\/\//) { - error - "nothing got downloaded -- use copy:// instead of file://"; + if (scalar @essential_pkgs == 0) { + # check if a file:// URI was used + open(my $pipe_apt, '-|', 'apt-get', 'indextargets', '--format', + '$(URI)', 'Created-By: Packages') + or error "cannot start apt-get indextargets: $!"; + while (my $uri = <$pipe_apt>) { + if ($uri =~ /^file:\/\//) { + error "nothing got downloaded -- use copy:// instead of" + . " file://"; + } } + error "nothing got downloaded"; } - error "nothing got downloaded"; } # We have to extract the packages from @essential_pkgs either if we run in # chrootless mode and extract variant or in any other mode. # In other words, the only scenario in which the @essential_pkgs are not # extracted are in chrootless mode in any other than the extract variant. - if ($options->{mode} eq 'chrootless' and $options->{variant} ne 'extract') - { + # + # or: if this is a dry run + if (($options->{mode} eq 'chrootless' and $options->{variant} ne 'extract') + or $options->{dryrun}) { # nothing to do } else { info "extracting archives..."; @@ -1742,7 +1757,8 @@ sub setup { '-oDPkg::Options::=--force-not-root', '-oDPkg::Options::=--force-script-chrootless', '-oDPkg::Options::=--root=' . $options->{root}, - '-oDPkg::Options::=--log=' . "$options->{root}/var/log/dpkg.log" + '-oDPkg::Options::=--log=' . "$options->{root}/var/log/dpkg.log", + $options->{dryrun} ? '-oAPT::Get::Simulate=true' : (), ); if (defined $options->{qemu}) { # The binfmt support on the outside is used, so qemu needs to know @@ -1773,7 +1789,11 @@ sub setup { ) ) { # run essential hooks - run_hooks('essential', $options); + if (!$options->{dryrun}) { + run_hooks('essential', $options); + } else { + info "not running essential-hooks because of --dry-run"; + } if (scalar @pkgs_to_install > 0) { run_apt_progress({ @@ -2001,23 +2021,26 @@ sub setup { # into account and thus doesn't install them in the right order # And the --predep-package option is broken: #539133 info "installing packages..."; - run_chroot( - sub { - run_dpkg_progress({ - ARGV => [ - @chrootcmd, 'env', - '--unset=TMPDIR', 'dpkg', - '--install', '--force-depends' - ], - PKGS => \@essential_pkgs, - }); - }, - $options - ); + if (!$options->{dryrun}) { + run_chroot( + sub { + run_dpkg_progress({ + ARGV => [ + @chrootcmd, 'env', + '--unset=TMPDIR', 'dpkg', + '--install', '--force-depends' + ], + PKGS => \@essential_pkgs, + }); + }, + $options + ); + } # if the path-excluded option was added to the dpkg config, # reinstall all packages - if (-e "$options->{root}/etc/dpkg/dpkg.cfg.d/99mmdebstrap") { + if ((!$options->{dryrun}) + and -e "$options->{root}/etc/dpkg/dpkg.cfg.d/99mmdebstrap") { open(my $fh, '<', "$options->{root}/etc/dpkg/dpkg.cfg.d/99mmdebstrap") or error "cannot open /etc/dpkg/dpkg.cfg.d/99mmdebstrap: $!"; @@ -2045,7 +2068,11 @@ sub setup { # run essential hooks if ($options->{variant} ne 'custom') { - run_hooks('essential', $options); + if (!$options->{dryrun}) { + run_hooks('essential', $options); + } else { + info "not running essential-hooks because of --dry-run"; + } } if ($options->{variant} ne 'custom' @@ -2098,67 +2125,89 @@ sub setup { . (join ', ', @pkgs_to_install_from_outside) . "..."; run_apt_progress({ ARGV => [ - 'apt-get', '--yes', - '-oApt::Get::Download-Only=true', 'install' + 'apt-get', + '--yes', + '-oApt::Get::Download-Only=true', + $options->{dryrun} + ? '-oAPT::Get::Simulate=true' + : (), + 'install' ], PKGS => [@pkgs_to_install_from_outside], }); - my @debs_to_install; - my $apt_archives = "/var/cache/apt/archives/"; - opendir my $dh, "$options->{root}/$apt_archives" - or error "cannot read $apt_archives"; - while (my $deb = readdir $dh) { - if ($deb !~ /\.deb$/) { - next; - } - $deb = "$apt_archives/$deb"; - if (!-f "$options->{root}/$deb") { - next; + if (!$options->{dryrun}) { + my @debs_to_install; + my $apt_archives = "/var/cache/apt/archives/"; + opendir my $dh, "$options->{root}/$apt_archives" + or error "cannot read $apt_archives"; + while (my $deb = readdir $dh) { + if ($deb !~ /\.deb$/) { + next; + } + $deb = "$apt_archives/$deb"; + if (!-f "$options->{root}/$deb") { + next; + } + push @debs_to_install, $deb; } - push @debs_to_install, $deb; - } - close $dh; - if (scalar @debs_to_install == 0) { - warning "nothing got downloaded -- maybe the packages" - . " were already installed?"; - } else { - # we need --force-depends because dpkg does not take - # Pre-Depends into account and thus doesn't install - # them in the right order - info 'installing ' - . (join ', ', @pkgs_to_install_from_outside) . "..."; - run_dpkg_progress({ - ARGV => [ - @chrootcmd, 'env', - '--unset=TMPDIR', 'dpkg', - '--install', '--force-depends' - ], - PKGS => \@debs_to_install, - }); - foreach my $deb (@debs_to_install) { - unlink "$options->{root}/$deb" - or error "cannot unlink $deb: $!"; + close $dh; + if (scalar @debs_to_install == 0) { + warning + "nothing got downloaded -- maybe the packages" + . " were already installed?"; + } else { + # we need --force-depends because dpkg does not take + # Pre-Depends into account and thus doesn't install + # them in the right order + info 'installing ' + . (join ', ', @pkgs_to_install_from_outside) + . "..."; + run_dpkg_progress({ + ARGV => [ + @chrootcmd, 'env', + '--unset=TMPDIR', 'dpkg', + '--install', '--force-depends' + ], + PKGS => \@debs_to_install, + }); + foreach my $deb (@debs_to_install) { + unlink "$options->{root}/$deb" + or error "cannot unlink $deb: $!"; + } } } } - run_chroot( - sub { - info - "installing remaining packages inside the chroot..."; - run_apt_progress({ - ARGV => [ - @chrootcmd, 'env', - '--unset=APT_CONFIG', '--unset=TMPDIR', - 'apt-get', '--yes', - 'install' - ], - PKGS => [@pkgs_to_install], - }); - }, - $options - ); - + if (!$options->{dryrun}) { + run_chroot( + sub { + info "installing remaining packages inside the" + . " chroot..."; + run_apt_progress({ + ARGV => [ + @chrootcmd, + 'env', + '--unset=APT_CONFIG', + '--unset=TMPDIR', + 'apt-get', + '--yes', + 'install' + ], + PKGS => [@pkgs_to_install], + }); + }, + $options + ); + } else { + info "installing remaining packages inside the chroot..."; + run_apt_progress({ + ARGV => [ + 'apt-get', '--yes', + '-oAPT::Get::Simulate=true', 'install' + ], + PKGS => [@pkgs_to_install], + }); + } } } else { error "unknown variant: $options->{variant}"; @@ -2167,7 +2216,11 @@ sub setup { error "unknown mode: $options->{mode}"; } - run_hooks('customize', $options); + if (!$options->{dryrun}) { + run_hooks('customize', $options); + } else { + info "not running customize-hooks because of --dry-run"; + } # clean up temporary configuration file unlink "$options->{root}/etc/apt/apt.conf.d/00mmdebstrap" @@ -2534,6 +2587,7 @@ sub main() { setup_hook => [], essential_hook => [], customize_hook => [], + dryrun => 0, }; my $logfile = undef; Getopt::Long::Configure('default', 'bundling', 'auto_abbrev', @@ -2587,6 +2641,8 @@ sub main() { 'setup-hook=s@' => \$options->{setup_hook}, 'essential-hook=s@' => \$options->{essential_hook}, 'customize-hook=s@' => \$options->{customize_hook}, + 'simulate' => \$options->{dryrun}, + 'dry-run' => \$options->{dryrun}, ) or pod2usage(-exitval => 2, -verbose => 1); if (defined($logfile)) { @@ -2598,6 +2654,14 @@ sub main() { . " with some debootstrap wrappers."; } + if ($options->{dryrun}) { + foreach my $hook ('setup', 'essential', 'customize') { + if (scalar @{ $options->{"${hook}_hook"} } > 0) { + warning "In dry-run mode, --$hook-hook options have no effect"; + } + } + } + my @valid_variants = ( 'extract', 'custom', 'essential', 'apt', 'required', 'minbase', 'buildd', 'important', @@ -3245,9 +3309,14 @@ sub main() { # try to fail early if target tarball or squashfs image cannot be # opened for writing if ($options->{target} ne '-') { - open my $fh, '>', $options->{target} - or error "cannot open $options->{target} for writing: $!"; - close $fh; + if ($options->{dryrun}) { + info + "not overwriting $options->{target} because in dry-run mode"; + } else { + open my $fh, '>', $options->{target} + or error "cannot open $options->{target} for writing: $!"; + close $fh; + } } # since the output is a tarball, we create the rootfs in a temporary # directory @@ -3918,14 +3987,19 @@ sub main() { } else { if ($options->{makesqfs} or defined $tar_compressor) { my @argv = (); - if ($options->{makesqfs}) { - push @argv, 'tar2sqfs', - '--quiet', '--no-skip', '--force', '--exportable', - '--compressor', 'xz', - '--block-size', '1048576', - $options->{target}; + if ($options->{dryrun}) { + push @argv, 'cat'; } else { - push @argv, @{$tar_compressor}; + if ($options->{makesqfs}) { + push @argv, 'tar2sqfs', + '--quiet', '--no-skip', '--force', + '--exportable', + '--compressor', 'xz', + '--block-size', '1048576', + $options->{target}; + } else { + push @argv, @{$tar_compressor}; + } } POSIX::sigprocmask(SIG_BLOCK, $sigset) or error "Can't block signals: $!"; @@ -3942,7 +4016,7 @@ sub main() { POSIX::sigprocmask(SIG_UNBLOCK, $sigset) or error "Can't unblock signals: $!"; - if ($options->{makesqfs}) { + if ($options->{makesqfs} or $options->{dryrun}) { open(STDOUT, '>', '/dev/null') or error "cannot open /dev/null for writing: $!"; } else {
signature.asc
Description: signature