aboutsummaryrefslogtreecommitdiff
path: root/ports-mgmt
diff options
context:
space:
mode:
authorPav Lucistnik <pav@FreeBSD.org>2003-12-27 23:08:05 +0000
committerPav Lucistnik <pav@FreeBSD.org>2003-12-27 23:08:05 +0000
commitc9f4bc97737d7ef02455c3f490cfedbd0ca5e6c3 (patch)
treec4e899d7b144305399779de639396421727f9bf0 /ports-mgmt
parent9eb13332703747f8ab8b6728c8386fb5890b6a63 (diff)
downloadports-c9f4bc97737d7ef02455c3f490cfedbd0ca5e6c3.tar.gz
ports-c9f4bc97737d7ef02455c3f490cfedbd0ca5e6c3.zip
Notes
Diffstat (limited to 'ports-mgmt')
-rw-r--r--ports-mgmt/pkg_cutleaves/Makefile5
-rw-r--r--ports-mgmt/pkg_cutleaves/pkg-descr7
-rw-r--r--ports-mgmt/pkg_cutleaves/src/pkg_cutleaves56
-rw-r--r--ports-mgmt/pkg_cutleaves/src/pkg_cutleaves.113
4 files changed, 52 insertions, 29 deletions
diff --git a/ports-mgmt/pkg_cutleaves/Makefile b/ports-mgmt/pkg_cutleaves/Makefile
index fa5b982f2faf..ca3d8e2a5ce4 100644
--- a/ports-mgmt/pkg_cutleaves/Makefile
+++ b/ports-mgmt/pkg_cutleaves/Makefile
@@ -8,7 +8,7 @@
#
PORTNAME= pkg_cutleaves
-PORTVERSION= 20031115
+PORTVERSION= 20031227
CATEGORIES= sysutils
MASTER_SITES= # none
DISTFILES= # none
@@ -44,6 +44,9 @@ post-patch:
's,/usr/local/sbin/pkg_deinstall,${LOCALBASE}/sbin/pkg_deinstall,' \
${WRKDIR}/pkg_cutleaves
@${REINPLACE_CMD} -e \
+ 's,/usr/local/sbin/pkgdb,${LOCALBASE}/sbin/pkgdb,' \
+ ${WRKDIR}/pkg_cutleaves
+ @${REINPLACE_CMD} -e \
's,/var/db/pkg,${PKG_DBDIR},' \
${WRKDIR}/pkg_cutleaves
@${REINPLACE_CMD} -e 's,/usr/bin/perl,${PERL},' \
diff --git a/ports-mgmt/pkg_cutleaves/pkg-descr b/ports-mgmt/pkg_cutleaves/pkg-descr
index 02d99d329a1b..7aa045b16eac 100644
--- a/ports-mgmt/pkg_cutleaves/pkg-descr
+++ b/ports-mgmt/pkg_cutleaves/pkg-descr
@@ -1,10 +1,3 @@
pkg_cutleaves finds installed 'leaf' packages, i.e. packages that are
not referenced by any other installed package, and lets you decide for
each one if you want to keep or deinstall it (via pkg_deinstall(1)).
-
-Usage: pkg_cutleaves [-l] [-x] [-R]
- -l: List leaf packages only, one per line, and don't ask for anything
- to be deinstalled.
- -x: Exclude packages matching expressions given in the exclude file.
- -R: Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall', so packages
- the removed leaf packages depend(ed) on will be deinstalled, too.
diff --git a/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves b/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves
index 874f28a4dd08..394692e91947 100644
--- a/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves
+++ b/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves
@@ -30,19 +30,21 @@
# Interactive script for deinstalling "leaf" packages;
# requires the portupgrade tools
#
-# Syntax: pkg_cutleaves [-c] [-l] [-x] [-R]
+# Syntax: pkg_cutleaves [-c] [-F] [-l] [-R] [-x]
# Options:
# -c: Show comments, too; only works with '-l' (ignored otherwise)
+# -F: Fix package db after each deinstallation run (via 'pkgdb -F')
# -l: List leaf packages only, don't ask if they should be deinstalled
-# -x: Honor exclude list in $excludefile
# -R: Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall'
+# -x: Honor exclude list in $excludefile
use strict;
my $dbdir = "/var/db/pkg";
my $excludefile = "/usr/local/etc/pkg_leaves.exclude";
my $pkgdeinstall = "/usr/local/sbin/pkg_deinstall";
-my ($opt_comments, $opt_listonly, $opt_excludelist, $opt_recursive);
+my @pkgdb_args = ("/usr/local/sbin/pkgdb", "-F");
+my ($opt_comments, $opt_listonly, $opt_excludelist, $opt_recursive, $opt_pkgdb);
my $exclpattern;
# Read the exclude list if the file exists
@@ -84,7 +86,7 @@ sub get_leaves {
my $reqlist = $path . '/+REQUIRED_BY';
my $commentfile = $path . '/+COMMENT';
# Exclude non-directories, "." and ".."
- if (($file ne ".") && ($file ne "..") && (-d $path) && (!-e $reqlist)) {
+ if (($file ne ".") && ($file ne "..") && (-d $path) && (!-s $reqlist)) {
# Exclude packages matching exclude pattern, if requested
unless ($file =~ m/$excl_pattern/) {
# Read package's short description/comment
@@ -107,17 +109,20 @@ sub get_leaves {
# Examine command line arguments
while(@ARGV) {
my $arg = shift(@ARGV);
- if ($arg eq "-x") {
- $opt_excludelist = 1;
+ if ($arg eq "-c") {
+ $opt_comments = 1;
+ }
+ elsif ($arg eq "-F") {
+ $opt_pkgdb = 1;
}
elsif ($arg eq "-l") {
$opt_listonly = 1;
}
- elsif ($arg eq "-c") {
- $opt_comments = 1;
- }
elsif ($arg eq "-R") {
$opt_recursive = 1;
+ }
+ elsif ($arg eq "-x") {
+ $opt_excludelist = 1;
} else {
warn "Unrecognized command line argument $arg ignored.\n";
}
@@ -149,8 +154,11 @@ if ($opt_listonly) {
# Loop while the user wants to
my $again = "y";
ROUND: while($again eq "y") {
- # Get list of packages and put them into an array
+ # Get list of leaf packages and put them into a hash
my %leaves = get_leaves($dbdir, $exclpattern);
+ # Always start with an empty list of leaves to cut
+ %leavestocut = ();
+
LEAVESLOOP: foreach my $leaf (sort keys %leaves) {
if (!$leavestokeep{$leaf}) {
print "$leaf - $leaves{$leaf}\n";
@@ -175,10 +183,14 @@ if ($opt_listonly) {
}
}
} # LEAVESLOOP
-
+
+ # Initialize 'progress meter'
+ my $ncuts = keys %leavestocut;
+ my $noff = 0;
# loop through packages marked for removal and pkg_deinstall them
foreach my $leaf (sort keys %leavestocut) {
- print "Deleting $leaf.\n";
+ $noff++;
+ print "Deleting $leaf, package $noff of $ncuts.\n";
my @deinstall_args;
if ($opt_recursive) {
@deinstall_args = ($pkgdeinstall, '-R', $leaf);
@@ -186,22 +198,32 @@ if ($opt_listonly) {
@deinstall_args = ($pkgdeinstall, $leaf);
}
if ((my $status = system(@deinstall_args) >> 8) != 0) {
- print "\nError: pkg_deinstall returned $status - exiting, fix this first.\n\n";
+ print "\npkg_cutleaves: pkg_deinstall returned $status - exiting, fix this first.\n\n";
last ROUND;
}
@cutleaves = (@cutleaves, $leaf);
- delete $leavestocut{$leaf};
}
-
- print "Once more ((y)es/[no])? ";
+
+ # Run 'pkgdb -F' if requested
+ if ($opt_pkgdb) {
+ print "Running 'pkgdb -F'.\n";
+ if ((my $status = system(@pkgdb_args) >> 8) != 0) {
+ print "\npkg_cutleaves: pkgdb returned $status - exiting, fix this first.\n\n";
+ last ROUND;
+ }
+ }
+
+ print "Go on with new leaf packages ((y)es/[no])? ";
$again = substr(lc(<STDIN>), 0, 1);
print "\n";
} # ROUND
- # print list of removed packages, sorted lexically
+ # print list of removed packages, sorted lexically, and their number
print "** Deinstalled packages:\n";
foreach my $cutleaf (sort @cutleaves) {
print "$cutleaf\n";
}
+ my $noff = @cutleaves;
+ print "** Number of deinstalled packages: $noff\n";
}
diff --git a/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves.1 b/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves.1
index 39d22f272bb3..1ebbbe6d006e 100644
--- a/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves.1
+++ b/ports-mgmt/pkg_cutleaves/src/pkg_cutleaves.1
@@ -2,7 +2,7 @@
.SH NAME
pkg_cutleaves \- deinstall 'leaf' packages
.SH SYNOPSIS
-.B pkg_cutleaves [-c] [-l] [-x] [-R]
+.B pkg_cutleaves [-c] [-F] [-l] [-R] [-x]
.SH DESCRIPTION
.B pkg_cutleaves
finds installed 'leaf' packages, i.e. packages that are not referenced
@@ -21,14 +21,19 @@ running pkg_cutleaves.
.IP -c
When listing leaf packages, also print their comments/short
descriptions. Will be ignored unless the '-l' parameter is given, too.
+.IP -F
+Run 'pkgdb -F' after each deinstallation run, to make sure the package
+registry database is up to date. (Note: This is mostly for convenience;
+it shouldn't be necessary to run 'pkgdb -F' after each run, but it
+doesn't hurt, either.)
.IP -l
List leaf packages only, one per line, and don't ask for anything to be
deinstalled.
-.IP -x
-Exclude packages matching expressions given in the exclude file.
.IP -R
Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall', so packages the
removed leaf packages depend(ed) on will be deinstalled, too.
+.IP -x
+Exclude packages matching expressions given in the exclude file.
.SH FILES
.I /usr/local/etc/pkg_leaves.exclude
.RS
@@ -40,4 +45,4 @@ exclude all packages with names starting with 'XFree86').
.SH AUTHOR
Stefan Walter <sw@gegenunendlich.de>
.SH SEE ALSO
-pkg_deinstall(1), portsclean(1)
+pkg_deinstall(1), pkgdb(1), portsclean(1)