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

(-)pkg_cutleaves/Makefile (-1 / +4 lines)
Lines 8-14 Link Here
8
#
8
#
9
9
10
PORTNAME=	pkg_cutleaves
10
PORTNAME=	pkg_cutleaves
11
PORTVERSION=	20031115
11
PORTVERSION=	20031227
12
CATEGORIES=	sysutils
12
CATEGORIES=	sysutils
13
MASTER_SITES=	# none
13
MASTER_SITES=	# none
14
DISTFILES=	# none
14
DISTFILES=	# none
Lines 42-47 Link Here
42
	  ${WRKDIR}/pkg_cutleaves
42
	  ${WRKDIR}/pkg_cutleaves
43
	@${REINPLACE_CMD} -e \
43
	@${REINPLACE_CMD} -e \
44
	  's,/usr/local/sbin/pkg_deinstall,${LOCALBASE}/sbin/pkg_deinstall,' \
44
	  's,/usr/local/sbin/pkg_deinstall,${LOCALBASE}/sbin/pkg_deinstall,' \
45
	  ${WRKDIR}/pkg_cutleaves
46
	@${REINPLACE_CMD} -e \
47
	  's,/usr/local/sbin/pkgdb,${LOCALBASE}/sbin/pkgdb,' \
45
	  ${WRKDIR}/pkg_cutleaves
48
	  ${WRKDIR}/pkg_cutleaves
46
	@${REINPLACE_CMD} -e \
49
	@${REINPLACE_CMD} -e \
47
	  's,/var/db/pkg,${PKG_DBDIR},' \
50
	  's,/var/db/pkg,${PKG_DBDIR},' \
(-)pkg_cutleaves/pkg-descr (-7 lines)
Lines 1-10 Link Here
1
pkg_cutleaves finds installed 'leaf' packages, i.e. packages that are
1
pkg_cutleaves finds installed 'leaf' packages, i.e. packages that are
2
not referenced by any other installed package, and lets you decide for
2
not referenced by any other installed package, and lets you decide for
3
each one if you want to keep or deinstall it (via pkg_deinstall(1)).
3
each one if you want to keep or deinstall it (via pkg_deinstall(1)).
4
5
Usage: pkg_cutleaves [-l] [-x] [-R]
6
  -l: List leaf packages only, one per line, and don't ask for anything
7
      to be deinstalled.
8
  -x: Exclude packages matching expressions given in the exclude file.
9
  -R: Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall', so packages
10
      the removed leaf packages depend(ed) on will be deinstalled, too.
(-)pkg_cutleaves/src/pkg_cutleaves (-18 / +40 lines)
Lines 25-48 Link Here
25
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26
# SUCH DAMAGE.
26
# SUCH DAMAGE.
27
#
27
#
28
# $FreeBSD: ports/sysutils/pkg_cutleaves/src/pkg_cutleaves,v 1.2 2003/11/16 18:50:53 pav Exp $
28
# $FreeBSD$
29
29
30
# Interactive script for deinstalling "leaf" packages;
30
# Interactive script for deinstalling "leaf" packages;
31
# requires the portupgrade tools
31
# requires the portupgrade tools
32
#
32
#
33
# Syntax: pkg_cutleaves [-c] [-l] [-x] [-R]
33
# Syntax: pkg_cutleaves [-c] [-F] [-l] [-R] [-x]
34
# Options:
34
# Options:
35
#   -c: Show comments, too; only works with '-l' (ignored otherwise)
35
#   -c: Show comments, too; only works with '-l' (ignored otherwise)
36
#   -F: Fix package db after each deinstallation run (via 'pkgdb -F')
36
#   -l: List leaf packages only, don't ask if they should be deinstalled
37
#   -l: List leaf packages only, don't ask if they should be deinstalled
37
#   -x: Honor exclude list in $excludefile
38
#   -R: Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall'
38
#   -R: Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall'
39
#   -x: Honor exclude list in $excludefile
39
40
40
use strict;
41
use strict;
41
42
42
my $dbdir = "/var/db/pkg";
43
my $dbdir = "/var/db/pkg";
43
my $excludefile = "/usr/local/etc/pkg_leaves.exclude";
44
my $excludefile = "/usr/local/etc/pkg_leaves.exclude";
44
my $pkgdeinstall = "/usr/local/sbin/pkg_deinstall";
45
my $pkgdeinstall = "/usr/local/sbin/pkg_deinstall";
45
my ($opt_comments, $opt_listonly, $opt_excludelist, $opt_recursive);
46
my @pkgdb_args = ("/usr/local/sbin/pkgdb", "-F");
47
my ($opt_comments, $opt_listonly, $opt_excludelist, $opt_recursive, $opt_pkgdb);
46
my $exclpattern;
48
my $exclpattern;
47
49
48
# Read the exclude list if the file exists
50
# Read the exclude list if the file exists
Lines 84-90 Link Here
84
		my $reqlist = $path . '/+REQUIRED_BY';
86
		my $reqlist = $path . '/+REQUIRED_BY';
85
		my $commentfile = $path . '/+COMMENT';
87
		my $commentfile = $path . '/+COMMENT';
86
		# Exclude non-directories, "." and ".."
88
		# Exclude non-directories, "." and ".."
87
		if (($file ne ".") && ($file ne "..") && (-d $path) && (!-e $reqlist)) {
89
		if (($file ne ".") && ($file ne "..") && (-d $path) && (!-s $reqlist)) {
88
			# Exclude packages matching exclude pattern, if requested
90
			# Exclude packages matching exclude pattern, if requested
89
			unless ($file =~ m/$excl_pattern/) {
91
			unless ($file =~ m/$excl_pattern/) {
90
				# Read package's short description/comment
92
				# Read package's short description/comment
Lines 107-123 Link Here
107
# Examine command line arguments
109
# Examine command line arguments
108
while(@ARGV) {
110
while(@ARGV) {
109
	my $arg = shift(@ARGV);
111
	my $arg = shift(@ARGV);
110
	if ($arg eq "-x") {
112
	if ($arg eq "-c") {
111
		$opt_excludelist = 1;
113
		$opt_comments = 1;
114
	}
115
	elsif ($arg eq "-F") {
116
		$opt_pkgdb = 1;
112
	}
117
	}
113
	elsif ($arg eq "-l") {
118
	elsif ($arg eq "-l") {
114
		$opt_listonly = 1;
119
		$opt_listonly = 1;
115
	}
120
	}
116
	elsif ($arg eq "-c") {
117
		$opt_comments = 1;
118
	}
119
	elsif ($arg eq "-R") {
121
	elsif ($arg eq "-R") {
120
		$opt_recursive = 1;
122
		$opt_recursive = 1;
123
	}
124
	elsif ($arg eq "-x") {
125
		$opt_excludelist = 1;
121
	} else {
126
	} else {
122
		warn "Unrecognized command line argument $arg ignored.\n";
127
		warn "Unrecognized command line argument $arg ignored.\n";
123
	}
128
	}
Lines 149-156 Link Here
149
	# Loop while the user wants to
154
	# Loop while the user wants to
150
	my $again = "y";
155
	my $again = "y";
151
	ROUND: while($again eq "y") {
156
	ROUND: while($again eq "y") {
152
		# Get list of packages and put them into an array
157
		# Get list of leaf packages and put them into a hash
153
		my %leaves = get_leaves($dbdir, $exclpattern);
158
		my %leaves = get_leaves($dbdir, $exclpattern);
159
		# Always start with an empty list of leaves to cut
160
		%leavestocut = ();
161
154
		LEAVESLOOP: foreach my $leaf (sort keys %leaves) {
162
		LEAVESLOOP: foreach my $leaf (sort keys %leaves) {
155
			if (!$leavestokeep{$leaf}) {
163
			if (!$leavestokeep{$leaf}) {
156
				print "$leaf - $leaves{$leaf}\n";
164
				print "$leaf - $leaves{$leaf}\n";
Lines 175-184 Link Here
175
				}
183
				}
176
			}
184
			}
177
		} # LEAVESLOOP
185
		} # LEAVESLOOP
178
		
186
187
		# Initialize 'progress meter'
188
		my $ncuts = keys %leavestocut;
189
		my $noff = 0;
179
		# loop through packages marked for removal and pkg_deinstall them
190
		# loop through packages marked for removal and pkg_deinstall them
180
		foreach my $leaf (sort keys %leavestocut) {
191
		foreach my $leaf (sort keys %leavestocut) {
181
			print "Deleting $leaf.\n";
192
			$noff++;
193
			print "Deleting $leaf, package $noff of $ncuts.\n";
182
			my @deinstall_args;
194
			my @deinstall_args;
183
			if ($opt_recursive) {
195
			if ($opt_recursive) {
184
				@deinstall_args = ($pkgdeinstall, '-R', $leaf);
196
				@deinstall_args = ($pkgdeinstall, '-R', $leaf);
Lines 186-207 Link Here
186
				@deinstall_args = ($pkgdeinstall, $leaf);
198
				@deinstall_args = ($pkgdeinstall, $leaf);
187
			}
199
			}
188
			if ((my $status = system(@deinstall_args) >> 8) != 0) {
200
			if ((my $status = system(@deinstall_args) >> 8) != 0) {
189
				print "\nError: pkg_deinstall returned $status - exiting, fix this first.\n\n";
201
				print "\npkg_cutleaves: pkg_deinstall returned $status - exiting, fix this first.\n\n";
190
				last ROUND;
202
				last ROUND;
191
			}
203
			}
192
			@cutleaves = (@cutleaves, $leaf);
204
			@cutleaves = (@cutleaves, $leaf);
193
			delete $leavestocut{$leaf};
194
		}
205
		}
195
		
206
196
		print "Once more ((y)es/[no])? ";
207
		# Run 'pkgdb -F' if requested
208
		if ($opt_pkgdb) {
209
			print "Running 'pkgdb -F'.\n";
210
			if ((my $status = system(@pkgdb_args) >> 8) != 0) {
211
				print "\npkg_cutleaves: pkgdb returned $status - exiting, fix this first.\n\n";
212
				last ROUND;
213
			}
214
		}
215
216
		print "Go on with new leaf packages ((y)es/[no])? ";
197
		$again = substr(lc(<STDIN>), 0, 1);
217
		$again = substr(lc(<STDIN>), 0, 1);
198
		print "\n";
218
		print "\n";
199
	} # ROUND
219
	} # ROUND
200
220
201
	# print list of removed packages, sorted lexically
221
	# print list of removed packages, sorted lexically, and their number
202
	print "** Deinstalled packages:\n";
222
	print "** Deinstalled packages:\n";
203
	foreach my $cutleaf (sort @cutleaves) {
223
	foreach my $cutleaf (sort @cutleaves) {
204
		print "$cutleaf\n";
224
		print "$cutleaf\n";
205
	}
225
	}
226
	my $noff = @cutleaves;
227
	print "** Number of deinstalled packages: $noff\n";
206
}
228
}
207
229
(-)pkg_cutleaves/src/pkg_cutleaves.1 (-4 / +9 lines)
Lines 2-8 Link Here
2
.SH NAME
2
.SH NAME
3
pkg_cutleaves \- deinstall 'leaf' packages
3
pkg_cutleaves \- deinstall 'leaf' packages
4
.SH SYNOPSIS
4
.SH SYNOPSIS
5
.B pkg_cutleaves [-c] [-l] [-x] [-R]
5
.B pkg_cutleaves [-c] [-F] [-l] [-R] [-x]
6
.SH DESCRIPTION
6
.SH DESCRIPTION
7
.B pkg_cutleaves
7
.B pkg_cutleaves
8
finds installed 'leaf' packages, i.e. packages that are not referenced
8
finds installed 'leaf' packages, i.e. packages that are not referenced
Lines 21-34 Link Here
21
.IP -c
21
.IP -c
22
When listing leaf packages, also print their comments/short
22
When listing leaf packages, also print their comments/short
23
descriptions. Will be ignored unless the '-l' parameter is given, too.
23
descriptions. Will be ignored unless the '-l' parameter is given, too.
24
.IP -F
25
Run 'pkgdb -F' after each deinstallation run, to make sure the package
26
registry database is up to date. (Note: This is mostly for convenience;
27
it shouldn't be necessary to run 'pkgdb -F' after each run, but it
28
doesn't hurt, either.)
24
.IP -l
29
.IP -l
25
List leaf packages only, one per line, and don't ask for anything to be
30
List leaf packages only, one per line, and don't ask for anything to be
26
deinstalled.
31
deinstalled.
27
.IP -x
28
Exclude packages matching expressions given in the exclude file.
29
.IP -R
32
.IP -R
30
Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall', so packages the
33
Run 'pkg_deinstall -R' instead of plain 'pkg_deinstall', so packages the
31
removed leaf packages depend(ed) on will be deinstalled, too.
34
removed leaf packages depend(ed) on will be deinstalled, too.
35
.IP -x
36
Exclude packages matching expressions given in the exclude file.
32
.SH FILES
37
.SH FILES
33
.I /usr/local/etc/pkg_leaves.exclude
38
.I /usr/local/etc/pkg_leaves.exclude
34
.RS
39
.RS
Lines 40-43 Link Here
40
.SH AUTHOR
45
.SH AUTHOR
41
Stefan Walter <sw@gegenunendlich.de>
46
Stefan Walter <sw@gegenunendlich.de>
42
.SH SEE ALSO
47
.SH SEE ALSO
43
pkg_deinstall(1), portsclean(1)
48
pkg_deinstall(1), pkgdb(1), portsclean(1)

Return to bug 60639