This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=0c743389506a4cd44eeb48458c19722774c38103

commit 0c743389506a4cd44eeb48458c19722774c38103 (HEAD -> main)
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Mar 19 10:03:45 2022 +0100

    dpkg-fsys-usrunmess: Add options and prompt about regression prevention 
package
    
    By default this will be prompted about. Otherwise the action can be
    controlled, by using one of the new options to select what to do, either
    with --prevention or --no-prevention.
    
    Prompted-by: Paul Wise <[email protected]>
---
 man/dpkg-fsys-usrunmess.pod    | 14 +++++++++++-
 scripts/dpkg-fsys-usrunmess.pl | 51 +++++++++++++++++++++++++-----------------
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/man/dpkg-fsys-usrunmess.pod b/man/dpkg-fsys-usrunmess.pod
index 45b3f080b..12cdeb4b4 100644
--- a/man/dpkg-fsys-usrunmess.pod
+++ b/man/dpkg-fsys-usrunmess.pod
@@ -46,7 +46,8 @@ Check for dpkg database consistency and otherwise abort.
 
 =item *
 
-Generate and install a regression prevention package.
+Generate and install a regression prevention package, if requested on the
+command-line or otherwise on the prompt.
 
 =item *
 
@@ -132,6 +133,17 @@ and consider doing backups beforehand.
 Prompt at the time of no return, so that the debug output or the shadow
 hierarchy can be evaluated before proceeding.
 
+=item B<--prevention>
+
+=item B<--no-prevention>
+
+Enables or disables generating and installing a regression prevention package
+into the system.
+If no option has been specified, the action to take will be prompted.
+
+The generated package contains the B<Protected> field set to B<yes> to
+protect against accidental removal of the package.
+
 =item B<-n>, B<--no-act>
 
 =item B<--dry-run>
diff --git a/scripts/dpkg-fsys-usrunmess.pl b/scripts/dpkg-fsys-usrunmess.pl
index 1a0ec8f75..b39e18118 100755
--- a/scripts/dpkg-fsys-usrunmess.pl
+++ b/scripts/dpkg-fsys-usrunmess.pl
@@ -39,12 +39,14 @@ if ($@) {
 
 my $opt_noact = length $ENV{DPKG_USRUNMESS_NOACT} ? 1 : 0;
 my $opt_prompt = 0;
+my $opt_prevent = -1;
 
 my @options_spec = (
     'help|?' => sub { usage(); exit 0; },
     'version' => sub { version(); exit 0; },
     'dry-run|no-act|n' => \$opt_noact,
     'prompt|p' => \$opt_prompt,
+    'prevention!' => \$opt_prevent,
 );
 
 {
@@ -86,16 +88,20 @@ if (glob "$ADMINDIR/updates/*") {
     fatal('dpkg is in an inconsistent state, please fix that');
 }
 
-debug('building regression prevention measures');
-my $tmpdir = tempdir(CLEANUP => 1, TMPDIR => 1);
-my $pkgdir = "$tmpdir/pkg";
-my $pkgfile = "$tmpdir/dpkg-fsys-usrunmess.deb";
+$opt_prevent = prompt('Generate and install a regression prevention package')
+    if $opt_prevent < 0;
 
-mkdir "$pkgdir" or fatal('cannot create temporary package directory');
-mkdir "$pkgdir/DEBIAN" or fatal('cannot create temporary directory');
-open my $ctrl_fh, '>', "$pkgdir/DEBIAN/control"
-    or fatal('cannot create temporary control file');
-print { $ctrl_fh } <<"CTRL";
+if ($opt_prevent) {
+    debug('building regression prevention measures');
+    my $tmpdir = tempdir(CLEANUP => 1, TMPDIR => 1);
+    my $pkgdir = "$tmpdir/pkg";
+    my $pkgfile = "$tmpdir/dpkg-fsys-usrunmess.deb";
+
+    mkdir "$pkgdir" or fatal('cannot create temporary package directory');
+    mkdir "$pkgdir/DEBIAN" or fatal('cannot create temporary directory');
+    open my $ctrl_fh, '>', "$pkgdir/DEBIAN/control"
+        or fatal('cannot create temporary control file');
+    print { $ctrl_fh } <<"CTRL";
 Package: dpkg-fsys-usrunmess
 Version: $PROGVERSION
 Architecture: all
@@ -116,14 +122,17 @@ Description: prevention measure to avoid unsuspected 
filesystem breakage
  program.
 
 CTRL
-close $ctrl_fh or fatal('cannot write temporary control file');
+    close $ctrl_fh or fatal('cannot write temporary control file');
 
-system(('dpkg-deb', '-b', $pkgdir, $pkgfile)) == 0
-    or fatal('cannot create prevention package');
+    system(('dpkg-deb', '-b', $pkgdir, $pkgfile)) == 0
+        or fatal('cannot create prevention package');
 
-if (not $opt_noact) {
-    system(('dpkg', '-GBi', $pkgfile)) == 0
-        or fatal('cannot install prevention package');
+    if (not $opt_noact) {
+        system(('dpkg', '-GBi', $pkgfile)) == 0
+            or fatal('cannot install prevention package');
+    }
+} else {
+    print "Will not generate and install a regression prevention package.\n";
 }
 
 my $aliased_regex = '^(' . join('|', @aliased_dirs) . ')/';
@@ -558,11 +567,13 @@ sub usage
 'Usage: %s [<option>...]'
     . "\n\n" .
 'Options:
-  -p, --prompt      prompt before the point of no return.
-  -n, --no-act      just check and create the new structure, no switch.
-      --dry-run     ditto.
-  -?, --help        show this help message.
-      --version     show the version.'
+  -p, --prompt         prompt before the point of no return.
+      --prevention     enable regression prevention package installation.
+      --no-prevention  disable regression prevention package installation.
+  -n, --no-act         just check and create the new structure, no switch.
+      --dry-run        ditto.
+  -?, --help           show this help message.
+      --version        show the version.'
     . "\n", $PROGNAME;
 }
 

-- 
Dpkg.Org's dpkg

Reply via email to