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 |
|