View | Details | Raw Unified | Return to bug 196762
Collapse All | Expand All

(-)Makefile (-18 / +1 lines)
Lines 17-29 Link Here
17
17
18
PLIST_FILES=	sbin/pkg_cutleaves man/man1/pkg_cutleaves.1.gz
18
PLIST_FILES=	sbin/pkg_cutleaves man/man1/pkg_cutleaves.1.gz
19
19
20
.include <bsd.port.pre.mk>
21
22
.if defined(WITH_PKGNG)
23
EXTRA_PATCHES+=	${FILESDIR}/extra-patch-pkg_cutleaves \
24
		${FILESDIR}/extra-patch-pkg_cutleaves.1
25
.endif
26
27
do-extract:
20
do-extract:
28
	${MKDIR} ${WRKSRC}
21
	${MKDIR} ${WRKSRC}
29
	${CP} ${FILESDIR}/pkg_cutleaves ${FILESDIR}/pkg_cutleaves.1 ${WRKSRC}
22
	${CP} ${FILESDIR}/pkg_cutleaves ${FILESDIR}/pkg_cutleaves.1 ${WRKSRC}
Lines 32-38 Link Here
32
	@${REINPLACE_CMD} -e \
25
	@${REINPLACE_CMD} -e \
33
	  's,/usr/local/etc/pkg_leaves.exclude,${PREFIX}/etc/pkg_leaves.exclude,' \
26
	  's,/usr/local/etc/pkg_leaves.exclude,${PREFIX}/etc/pkg_leaves.exclude,' \
34
	  ${WRKSRC}/pkg_cutleaves.1
27
	  ${WRKSRC}/pkg_cutleaves.1
35
.if defined(WITH_PKGNG)
36
	@${REINPLACE_CMD} \
28
	@${REINPLACE_CMD} \
37
	  -e 's,/usr/local/etc/pkg_leaves.exclude,${PREFIX}/etc/pkg_leaves.exclude,' \
29
	  -e 's,/usr/local/etc/pkg_leaves.exclude,${PREFIX}/etc/pkg_leaves.exclude,' \
38
	  -e 's,/usr/local/sbin/pkg delete -y,${PKG_DELETE},' \
30
	  -e 's,/usr/local/sbin/pkg delete -y,${PKG_DELETE},' \
Lines 39-56 Link Here
39
	  -e 's,/usr/local/sbin/pkg query,${PKG_QUERY},' \
31
	  -e 's,/usr/local/sbin/pkg query,${PKG_QUERY},' \
40
	  -e 's,/usr/bin/perl,${PERL},' \
32
	  -e 's,/usr/bin/perl,${PERL},' \
41
	  ${WRKSRC}/pkg_cutleaves
33
	  ${WRKSRC}/pkg_cutleaves
42
.else
43
	@${REINPLACE_CMD} \
44
	  -e 's,/usr/local/etc/pkg_leaves.exclude,${PREFIX}/etc/pkg_leaves.exclude,' \
45
	  -e 's,/usr/sbin/pkg_delete,${PKG_DELETE},' \
46
	  -e 's,/usr/local/sbin/pkgdb,${LOCALBASE}/sbin/pkgdb,' \
47
	  -e 's,/var/db/pkg,${PKG_DBDIR},' \
48
	  -e 's,/usr/bin/perl,${PERL},' \
49
	  ${WRKSRC}/pkg_cutleaves
50
.endif
51
34
52
do-install:
35
do-install:
53
	${INSTALL_SCRIPT} ${WRKSRC}/pkg_cutleaves ${STAGEDIR}${PREFIX}/sbin/pkg_cutleaves
36
	${INSTALL_SCRIPT} ${WRKSRC}/pkg_cutleaves ${STAGEDIR}${PREFIX}/sbin/pkg_cutleaves
54
	${INSTALL_MAN} ${WRKSRC}/pkg_cutleaves.1 ${STAGEDIR}${MAN1PREFIX}/man/man1
37
	${INSTALL_MAN} ${WRKSRC}/pkg_cutleaves.1 ${STAGEDIR}${MAN1PREFIX}/man/man1
55
38
56
.include <bsd.port.post.mk>
39
.include <bsd.port.mk>
(-)files/extra-patch-pkg_cutleaves (-117 lines)
Lines 1-117 Link Here
1
Index: pkg_cutleaves
2
===================================================================
3
RCS file: /home/ncvs/ports/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves,v
4
retrieving revision 1.3
5
diff -u -r1.3 pkg_cutleaves
6
--- pkg_cutleaves	12 Aug 2009 17:50:48 -0000	1.3
7
+++ pkg_cutleaves	6 Mar 2012 12:39:29 -0000
8
@@ -28,10 +28,9 @@
9
 
10
 # Interactive script for deinstalling "leaf" packages
11
 #
12
-# Syntax: pkg_cutleaves [-cFgLlRVx]
13
+# Syntax: pkg_cutleaves [-cgLlRVx]
14
 # Options:
15
 #   -c: Show comments, too; only works with '-l' (ignored otherwise)
16
-#   -F: Fix package db after each deinstallation run (via 'pkgdb -F')
17
 #   -g: Generate exclude list from kept/installed leaf packages
18
 #   -L: Interpret exclude file as list of packages that *should* be installed
19
 #   -l: List leaf packages only, don't ask if they should be deinstalled
20
@@ -43,15 +42,14 @@
21
 use Getopt::Std;
22
 use strict;
23
 
24
-my $dbdir = "/var/db/pkg";
25
 my $excludefile = "/usr/local/etc/pkg_leaves.exclude";
26
-my $pkgdeinstall = "/usr/sbin/pkg_delete";
27
-my @pkgdb_args = ("/usr/local/sbin/pkgdb", "-F");
28
+my @pkgdeinstall = (qw{/usr/local/sbin/pkg delete -y});
29
+my @pkgquery = (qw{/usr/local/sbin/pkg query});
30
 my $exclpattern; 
31
 my %leavestokeep;
32
 my %opt;
33
 
34
-getopts('cFgLlRVx', \%opt);
35
+getopts('cgLlRVx', \%opt);
36
 set_excl_pattern();
37
 
38
 # LIST MODE
39
@@ -77,7 +75,7 @@
40
     my ($file, $required) = @$pkg;
41
     # Clobber any exclude patterns that match this package
42
     for (my $i = 0; $i < @excludes; $i++) {
43
-      if ($file =~ /\Q@excludes[$i]\E/) {
44
+      if ($file =~ /\Q$excludes[$i]\E/) {
45
         splice(@excludes, $i--, 1);
46
       }
47
     }
48
@@ -219,7 +217,7 @@
49
     foreach my $leaf (sort keys %leavestocut) {
50
       $noff++;
51
       print "Deleting $leaf (package $noff of $ncuts).\n";
52
-      my @deinstall_args = ($pkgdeinstall, $leaf);
53
+      my @deinstall_args = (@pkgdeinstall, $leaf);
54
       if ((my $status = system(@deinstall_args) >> 8) != 0) {
55
         print STDERR "\n\n$0: pkg_deinstall returned $status - exiting, fix this first.\n\n";
56
         last ROUND;
57
@@ -227,15 +225,6 @@
58
       push @cutleaves, $leaf;
59
     }
60
 
61
-    # Run 'pkgdb -F' if requested
62
-    if ($opt{F}) {
63
-      print "Running 'pkgdb -F'.\n";
64
-      if ((my $status = system(@pkgdb_args) >> 8) != 0) {
65
-        print STDERR "\n\n$0: pkgdb returned $status - exiting, fix this first.\n\n";
66
-        last ROUND;
67
-      }
68
-    }
69
-
70
     # Get new list of leaf packages and put them into a hash
71
     %leaves = get_leaves();
72
 
73
@@ -328,15 +317,13 @@
74
 #
75
 sub get_packages {
76
   my @pkgs;
77
-  opendir(DBDIR, $dbdir)
78
-    or die "Can't open package db directory $dbdir!";
79
-  while (defined(my $file = readdir(DBDIR))) {
80
-    my $path = join('/', $dbdir, $file);
81
-    unless ($file =~ /^\.+$/o || !(-d $path)) {
82
-      push @pkgs, [$file, -s $path . '/+REQUIRED_BY', join('/', $path, '+COMMENT')];
83
-    }
84
+  open(PKGQUERY, '-|', @pkgquery, '-a', '%n-%v\t%?r\t%c')
85
+    or die "Couldn't read output from $pkgquery[0]!";
86
+  while (my $p = <PKGQUERY>) {
87
+    chomp($p);
88
+    push(@pkgs, [ split(/\t/, $p) ]);
89
   }
90
-  closedir DBDIR;
91
+  close PKGQUERY;
92
   return @pkgs;
93
 }
94
 
95
@@ -347,19 +334,14 @@
96
   my %leaves;
97
   my @pkgs = get_packages(); 
98
   foreach my $pkg (@pkgs) {
99
-    my ($file, $required, $commentfile) = @$pkg;
100
+    my ($file, $required, $comment) = @$pkg;
101
     unless ($required) {
102
       if ($file =~ $exclpattern) {
103
         $leavestokeep{$file} = 1;
104
       }
105
       else {
106
-        # Read package's short description/comment
107
-        my $comment;
108
-        if ((-s $commentfile) && (open(COMMENT, $commentfile))) {
109
-          chomp($comment = <COMMENT>);
110
-        }
111
-        else {
112
-          $comment = 'No short description';
113
+        unless($comment) {
114
+	  $comment = 'No short description';
115
         }
116
         $leaves{$file} = $comment;
117
       }
(-)files/extra-patch-pkg_cutleaves.1 (-64 lines)
Lines 1-64 Link Here
1
Index: pkg_cutleaves.1
2
===================================================================
3
RCS file: /home/ncvs/ports/ports-mgmt/pkg_cutleaves/files/pkg_cutleaves.1,v
4
retrieving revision 1.2
5
diff -u -r1.2 pkg_cutleaves.1
6
--- pkg_cutleaves.1	25 Mar 2008 18:55:30 -0000	1.2
7
+++ pkg_cutleaves.1	6 Mar 2012 14:14:47 -0000
8
@@ -8,14 +8,14 @@
9
 .Nd deinstall 'leaf' packages
10
 .Sh SYNOPSIS
11
 .Nm
12
-.Op Fl cFglRVx
13
+.Op Fl cglRVx
14
 .Sh DESCRIPTION
15
 .Nm pkg_cutleaves
16
 finds installed 
17
 .Dq Li "leaf"
18
 packages, i.e. packages that are not referenced by any other installed package,
19
 and lets you decide for each one if you want to keep or deinstall it (via
20
-pkg_delete(1)). Once the packages marked for removal have been
21
+pkg-delete(1)). Once the packages marked for removal have been
22
 flushed/deinstalled, you'll be asked if you want to do another run (i.e. to see
23
 packages that have become 'leaves' now because you've deinstalled the package(s)
24
 that depended on them.
25
@@ -24,10 +24,6 @@
26
 .Fl R
27
 below to bypass interactive dependency removal). In every run you will be shown 
28
 only packages that you haven't marked for keeping, yet.
29
-.Pp
30
-Note that your package registry database should be up to date for this
31
-to work properly, so it might be a good idea to run pkgdb(1) before
32
-running
33
 .Nm .
34
 .Sh OPTIONS
35
 .Pp
36
@@ -40,16 +36,6 @@
37
 .Fl l
38
 parameter is given, too.
39
 .Pp
40
-.It Fl F
41
-Run
42
-.Dq Li "pkgdb -F"
43
-after each deinstallation run, to make sure the package registry database 
44
-is up to date. (
45
-.Ar Note:
46
-This is mostly for convenience; it shouldn't be necessary to run
47
-.Dq Li "pkgdb -F"
48
-after each run, but it doesn't hurt, either.)
49
-.Pp
50
 .It Fl L
51
 Interpret exclude file as a list of leaf packages that
52
 .Ar should
53
@@ -147,8 +133,9 @@
54
 .Xr vi 1 .
55
 .El
56
 .Sh SEE ALSO
57
-.Xr pkg_deinstall 1 ,
58
-.Xr pkgdb 1 ,
59
+.Xr pkg 8 ,
60
+.Xr pkg-info 8 ,
61
+.Xe pkg-delete 8 ,
62
 .Xr portsclean 1
63
 .Sh AUTHOR
64
 .An Stefan Walter <sw@gegenunendlich.de>
(-)files/pkg_cutleaves (-33 / +15 lines)
Lines 28-37 Link Here
28
28
29
# Interactive script for deinstalling "leaf" packages
29
# Interactive script for deinstalling "leaf" packages
30
#
30
#
31
# Syntax: pkg_cutleaves [-cFgLlRVx]
31
# Syntax: pkg_cutleaves [-cgLlRVx]
32
# Options:
32
# Options:
33
#   -c: Show comments, too; only works with '-l' (ignored otherwise)
33
#   -c: Show comments, too; only works with '-l' (ignored otherwise)
34
#   -F: Fix package db after each deinstallation run (via 'pkgdb -F')
35
#   -g: Generate exclude list from kept/installed leaf packages
34
#   -g: Generate exclude list from kept/installed leaf packages
36
#   -L: Interpret exclude file as list of packages that *should* be installed
35
#   -L: Interpret exclude file as list of packages that *should* be installed
37
#   -l: List leaf packages only, don't ask if they should be deinstalled
36
#   -l: List leaf packages only, don't ask if they should be deinstalled
Lines 43-57 Link Here
43
use Getopt::Std;
42
use Getopt::Std;
44
use strict;
43
use strict;
45
44
46
my $dbdir = "/var/db/pkg";
47
my $excludefile = "/usr/local/etc/pkg_leaves.exclude";
45
my $excludefile = "/usr/local/etc/pkg_leaves.exclude";
48
my $pkgdeinstall = "/usr/sbin/pkg_delete";
46
my @pkgdeinstall = (qw{/usr/local/sbin/pkg delete -y});
49
my @pkgdb_args = ("/usr/local/sbin/pkgdb", "-F");
47
my @pkgquery = (qw{/usr/local/sbin/pkg query});
50
my $exclpattern; 
48
my $exclpattern; 
51
my %leavestokeep;
49
my %leavestokeep;
52
my %opt;
50
my %opt;
53
51
54
getopts('cFgLlRVx', \%opt);
52
getopts('cgLlRVx', \%opt);
55
set_excl_pattern();
53
set_excl_pattern();
56
54
57
# LIST MODE
55
# LIST MODE
Lines 77-83 Link Here
77
    my ($file, $required) = @$pkg;
75
    my ($file, $required) = @$pkg;
78
    # Clobber any exclude patterns that match this package
76
    # Clobber any exclude patterns that match this package
79
    for (my $i = 0; $i < @excludes; $i++) {
77
    for (my $i = 0; $i < @excludes; $i++) {
80
      if ($file =~ /\Q@excludes[$i]\E/) {
78
      if ($file =~ /\Q$excludes[$i]\E/) {
81
        splice(@excludes, $i--, 1);
79
        splice(@excludes, $i--, 1);
82
      }
80
      }
83
    }
81
    }
Lines 219-225 Link Here
219
    foreach my $leaf (sort keys %leavestocut) {
217
    foreach my $leaf (sort keys %leavestocut) {
220
      $noff++;
218
      $noff++;
221
      print "Deleting $leaf (package $noff of $ncuts).\n";
219
      print "Deleting $leaf (package $noff of $ncuts).\n";
222
      my @deinstall_args = ($pkgdeinstall, $leaf);
220
      my @deinstall_args = (@pkgdeinstall, $leaf);
223
      if ((my $status = system(@deinstall_args) >> 8) != 0) {
221
      if ((my $status = system(@deinstall_args) >> 8) != 0) {
224
        print STDERR "\n\n$0: pkg_deinstall returned $status - exiting, fix this first.\n\n";
222
        print STDERR "\n\n$0: pkg_deinstall returned $status - exiting, fix this first.\n\n";
225
        last ROUND;
223
        last ROUND;
Lines 227-241 Link Here
227
      push @cutleaves, $leaf;
225
      push @cutleaves, $leaf;
228
    }
226
    }
229
227
230
    # Run 'pkgdb -F' if requested
231
    if ($opt{F}) {
232
      print "Running 'pkgdb -F'.\n";
233
      if ((my $status = system(@pkgdb_args) >> 8) != 0) {
234
        print STDERR "\n\n$0: pkgdb returned $status - exiting, fix this first.\n\n";
235
        last ROUND;
236
      }
237
    }
238
239
    # Get new list of leaf packages and put them into a hash
228
    # Get new list of leaf packages and put them into a hash
240
    %leaves = get_leaves();
229
    %leaves = get_leaves();
241
230
Lines 328-342 Link Here
328
#
317
#
329
sub get_packages {
318
sub get_packages {
330
  my @pkgs;
319
  my @pkgs;
331
  opendir(DBDIR, $dbdir)
320
  open(PKGQUERY, '-|', @pkgquery, '-a', '%n-%v\t%?r\t%c')
332
    or die "Can't open package db directory $dbdir!";
321
    or die "Couldn't read output from $pkgquery[0]!";
333
  while (defined(my $file = readdir(DBDIR))) {
322
  while (my $p = <PKGQUERY>) {
334
    my $path = join('/', $dbdir, $file);
323
    chomp($p);
335
    unless ($file =~ /^\.+$/o || !(-d $path)) {
324
    push(@pkgs, [ split(/\t/, $p) ]);
336
      push @pkgs, [$file, -s $path . '/+REQUIRED_BY', join('/', $path, '+COMMENT')];
337
    }
338
  }
325
  }
339
  closedir DBDIR;
326
  close PKGQUERY;
340
  return @pkgs;
327
  return @pkgs;
341
}
328
}
342
329
Lines 347-366 Link Here
347
  my %leaves;
334
  my %leaves;
348
  my @pkgs = get_packages(); 
335
  my @pkgs = get_packages(); 
349
  foreach my $pkg (@pkgs) {
336
  foreach my $pkg (@pkgs) {
350
    my ($file, $required, $commentfile) = @$pkg;
337
    my ($file, $required, $comment) = @$pkg;
351
    unless ($required) {
338
    unless ($required) {
352
      if ($file =~ $exclpattern) {
339
      if ($file =~ $exclpattern) {
353
        $leavestokeep{$file} = 1;
340
        $leavestokeep{$file} = 1;
354
      }
341
      }
355
      else {
342
      else {
356
        # Read package's short description/comment
343
        unless($comment) {
357
        my $comment;
344
	  $comment = 'No short description';
358
        if ((-s $commentfile) && (open(COMMENT, $commentfile))) {
359
          chomp($comment = <COMMENT>);
360
        }
345
        }
361
        else {
362
          $comment = 'No short description';
363
        }
364
        $leaves{$file} = $comment;
346
        $leaves{$file} = $comment;
365
      }
347
      }
366
    }
348
    }
(-)files/pkg_cutleaves.1 (-18 / +5 lines)
Lines 8-14 Link Here
8
.Nd deinstall 'leaf' packages
8
.Nd deinstall 'leaf' packages
9
.Sh SYNOPSIS
9
.Sh SYNOPSIS
10
.Nm
10
.Nm
11
.Op Fl cFglRVx
11
.Op Fl cglRVx
12
.Sh DESCRIPTION
12
.Sh DESCRIPTION
13
.Nm pkg_cutleaves
13
.Nm pkg_cutleaves
14
finds installed 
14
finds installed 
Lines 15-21 Link Here
15
.Dq Li "leaf"
15
.Dq Li "leaf"
16
packages, i.e. packages that are not referenced by any other installed package,
16
packages, i.e. packages that are not referenced by any other installed package,
17
and lets you decide for each one if you want to keep or deinstall it (via
17
and lets you decide for each one if you want to keep or deinstall it (via
18
pkg_delete(1)). Once the packages marked for removal have been
18
pkg-delete(1)). Once the packages marked for removal have been
19
flushed/deinstalled, you'll be asked if you want to do another run (i.e. to see
19
flushed/deinstalled, you'll be asked if you want to do another run (i.e. to see
20
packages that have become 'leaves' now because you've deinstalled the package(s)
20
packages that have become 'leaves' now because you've deinstalled the package(s)
21
that depended on them.
21
that depended on them.
Lines 24-33 Link Here
24
.Fl R
24
.Fl R
25
below to bypass interactive dependency removal). In every run you will be shown 
25
below to bypass interactive dependency removal). In every run you will be shown 
26
only packages that you haven't marked for keeping, yet.
26
only packages that you haven't marked for keeping, yet.
27
.Pp
28
Note that your package registry database should be up to date for this
29
to work properly, so it might be a good idea to run pkgdb(1) before
30
running
31
.Nm .
27
.Nm .
32
.Sh OPTIONS
28
.Sh OPTIONS
33
.Pp
29
.Pp
Lines 40-55 Link Here
40
.Fl l
36
.Fl l
41
parameter is given, too.
37
parameter is given, too.
42
.Pp
38
.Pp
43
.It Fl F
44
Run
45
.Dq Li "pkgdb -F"
46
after each deinstallation run, to make sure the package registry database 
47
is up to date. (
48
.Ar Note:
49
This is mostly for convenience; it shouldn't be necessary to run
50
.Dq Li "pkgdb -F"
51
after each run, but it doesn't hurt, either.)
52
.Pp
53
.It Fl L
39
.It Fl L
54
Interpret exclude file as a list of leaf packages that
40
Interpret exclude file as a list of leaf packages that
55
.Ar should
41
.Ar should
Lines 147-154 Link Here
147
.Xr vi 1 .
133
.Xr vi 1 .
148
.El
134
.El
149
.Sh SEE ALSO
135
.Sh SEE ALSO
150
.Xr pkg_deinstall 1 ,
136
.Xr pkg 8 ,
151
.Xr pkgdb 1 ,
137
.Xr pkg-info 8 ,
138
.Xe pkg-delete 8 ,
152
.Xr portsclean 1
139
.Xr portsclean 1
153
.Sh AUTHOR
140
.Sh AUTHOR
154
.An Stefan Walter <sw@gegenunendlich.de>
141
.An Stefan Walter <sw@gegenunendlich.de>

Return to bug 196762