1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
#!/usr/bin/env perl
#
# vim: set ts=4:noet
#
# sboremove
# script to remove an installed SlackBuild and any unused dependencies
#
# author: Luke Williams <xocel@iquidus.org>
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
use 5.16.0;
use strict;
use warnings FATAL => 'all';
use SBO::Lib;
use Getopt::Long qw(:config bundling);
use File::Basename;
my $self = basename ($0);
sub get_requires ($) {
my $location = get_sbo_location($_[0]);
my $requires = get_from_info (LOCATION => $location, GET => 'REQUIRES');
return $requires;
}
sub show_usage () {
print <<EOF
Usage: $self [options] sbo
Options (defaults shown first where applicable):
-h|--help:
this screen.
-v|--version:
version information.
-r|--nointeractive:
non-interactive; skips all prompts.
-R|--norequirements:
do not parse requirements.
-f|--force:
force remove, even if required by other packages on system.
Note: optional dependencies need to be removed separately.
EOF
}
my ($help, $vers, $non_int, $no_reqs, $force, @excluded);
GetOptions (
'help|h' => \$help,
'version|v' => \$vers,
'nointeractive|r' => \$non_int,
'norequirements|R' => \$no_reqs,
'force|f' => \$force,
);
show_usage and exit 0 if $help;
show_version and exit 0 if $vers;
show_usage and exit 0 unless exists $ARGV[0];
my $rootpkg = $ARGV[0];
my $test = get_sbo_location $rootpkg;
die "Unable to locate $rootpkg in the SlackBuilds.org tree.\n" unless
defined $test;
my $remove_queue;
my %required_by;
my @confirmed;
# Determine dependencies
unless ($no_reqs) {
$remove_queue = get_build_queue($rootpkg);
@$remove_queue = reverse(@$remove_queue);
} else {
push(@$remove_queue, $rootpkg);
}
my $inst_names;
# Determine required by
unless ($force) {
my $installed = get_installed_sbos;
$inst_names = get_inst_names $installed;
for my $inst (@$inst_names) {
my $requires = get_requires "$inst";
next unless $$requires[0];
for my $req (@$requires) {
unless ( $req eq "%README%" ) {
if ( $req ~~ $inst_names ) {
push(@{$required_by{$req}}, $inst);
}
}
}
}
}
# Make sure packages in remove queue are installed on system.
my @temp;
if ($inst_names) {
for my $i (@$remove_queue) {
if ($i ~~ $inst_names) {
push(@temp, $i);
}
}
$remove_queue = \@temp;
}
my $queue = join(" ", @$remove_queue);
say "Remove: $queue\n";
# separate ignored packages from confirmed.
my $ignore;
my %ignore_data;
for my $pkg (@$remove_queue) {
$ignore = 0;
while ( my ($key, $value) = each(%required_by) ) {
if ( $key eq $pkg ) {
for my $v (@$value) {
unless ($v ~~ @confirmed) {
$ignore = 1;
push(@{$ignore_data{$key}}, $v);
}
}
}
}
unless ($ignore) {
push(@confirmed, $pkg);
}
}
# Show ignored packages
my $ignore_count = keys(%ignore_data);
if ($ignore_count) {
say "Ignoring $ignore_count package(s)";
while ( my ($key, $value) = each(%ignore_data) ) {
print "$key : required by";
for my $v (@$value) {
print " $v";
}
print "\n";
}
print "\n";
}
# Show remove queue
my $remove_count = @confirmed;
if ($remove_count) {
say "Removing $remove_count package(s)";
for my $pkg (@confirmed) {
print "$pkg\n";
}
print "\n";
} else {
say "Nothing to remove.";
exit 0;
}
unless ($non_int) {
print 'Do you wish to proceed? [n] ';
unless (<STDIN> =~ /^[Yy]/) {
say "Exiting.";
exit 0;
}
}
for my $instpkg (@confirmed) {
system("/sbin/removepkg $instpkg");
}
say "All operations completed successfully."
|