aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxocel <xocel@iquidus.org>2012-10-15 17:59:10 +1300
committerxocel <xocel@iquidus.org>2012-10-15 17:59:10 +1300
commit901c1458ec200d341703bd92e79f35f5049c3368 (patch)
treefe02ae6b9531c98d50b8a27b6dd47906b053e608
parentb58b73ea8a5686ecdc2d31acfba5999d32436619 (diff)
downloadsbotools2-901c1458ec200d341703bd92e79f35f5049c3368.tar.xz
sboremove: %README% support + general improvements
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm54
-rwxr-xr-xsbofind10
-rwxr-xr-xsboremove146
3 files changed, 115 insertions, 95 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index d084b14..e90f1e1 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -15,6 +15,7 @@ use 5.16.0;
use strict;
use warnings FATAL => 'all';
+
package SBO::Lib 1.1;
my $version = '1.1';
@@ -55,6 +56,7 @@ use File::Copy;
use File::Path qw(make_path remove_tree);
use File::Temp qw(tempdir tempfile);
use File::Find;
+use File::Basename;
use Fcntl qw(F_SETFD F_GETFD);
our $tempdir = tempdir (CLEANUP => 1);
@@ -718,38 +720,48 @@ sub do_upgradepkg ($) {
return 1;
}
-# add slackbuild plus reqs to build queue.
-sub add_to_queue (%);
-sub add_to_queue (%) {
- my %args = %{$_[0]};
- my $location = get_sbo_location($args{NAME});
- push(@{$_[0]}{QUEUE}, $args{NAME});
- return 1 unless $args{RECURSIVE};
+
+# avoid being called to early to check prototype when add_to_queue calls itself
+sub add_to_queue ($);
+# used by get_build_queue.
+sub add_to_queue ($) {
+ my $args = shift;
+ my $sbo = \${$args}{NAME};
+ return unless $$sbo;
+ push(@{$args}{QUEUE}, $$sbo);
+ my @locations = get_sbo_location $$sbo;
+ my $location;
+ for my $loc (@locations) {
+ $location = $loc if basename($loc) eq $$sbo;
+ }
+ return unless $location;
my $requires = get_from_info (LOCATION => $location, GET => 'REQUIRES');
- return unless $$requires[0];
for my $req (@$requires) {
- unless (( $req eq "%README%") or ($req eq $args{NAME})) {
- $args{NAME} = $req;
- add_to_queue(\%args)
+ next if $req eq $$sbo;
+ if ($req eq "%README%") {
+ ${$args}{WARNINGS}{$$sbo}="%README%";
+ } else {
+ $$sbo = $req;
+ add_to_queue($args);
}
}
}
-# get full build queue.
-sub get_build_queue ($) {
- exists $_[0] or script_error 'get_build_queue requires an argument.';
- my @temp_queue = ();
- my @build_queue = ();
+# recursively add a sbo's requirements to the build queue.
+sub get_build_queue ($$) {
+ unless ($_[0] && $_[1]) {
+ script_error 'get_build_queue requires two arguments.';
+ }
+ my (@temp_queue, @build_queue);
my %args = (
QUEUE => \@temp_queue,
NAME => $_[0],
- RECURSIVE => 1
+ WARNINGS => \%{$_[1]}
);
add_to_queue(\%args);
- @temp_queue = reverse(@temp_queue);
- # Remove duplicate entries (leaving first occurance)
- my %seen = ();
- for my $sb( @temp_queue ) {
+ # Remove duplicate entries (leaving first occurrence)
+ my %seen;
+ for my $sb( reverse(@temp_queue) ) {
next if $seen{ $sb }++;
push @build_queue, $sb;
}
diff --git a/sbofind b/sbofind
index ec2fb3e..b0cc7e5 100755
--- a/sbofind
+++ b/sbofind
@@ -7,6 +7,8 @@
#
# author: Jacob Pipkin <j@dawnrazor.net>
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
+#
+# modified by: Luke Williams <xocel@iquidus.org>
use 5.16.0;
use strict;
@@ -93,10 +95,12 @@ sub get_file_contents ($) {
return $contents;
}
+# get build queue and return it as a single line.
sub show_build_queue ($) {
- exists $_[0] or script_error 'prepare_queue requires an argument.';
- my $queue = join(" ", get_build_queue($_[0]));
- return "$queue";
+ exists $_[0] or script_error 'show_build_queue requires an argument.';
+ my %warnings;
+ my $queue = get_build_queue($_[0], \%warnings);
+ return join(" ", @$queue);
}
my $findings = perform_search $search;
diff --git a/sboremove b/sboremove
index 11d7883..e572b27 100755
--- a/sboremove
+++ b/sboremove
@@ -3,7 +3,7 @@
# vim: set ts=4:noet
#
# sboremove
-# script to remove an installed SlackBuild and any unused dependencies
+# script to remove an installed SlackBuild
#
# author: Luke Williams <xocel@iquidus.org>
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
@@ -26,26 +26,21 @@ Options (defaults shown first where applicable):
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.
+ prompt to 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,
);
@@ -61,19 +56,20 @@ die "Unable to locate $rootpkg in the SlackBuilds.org tree.\n" unless
my $remove_queue;
my %required_by;
+my %warnings;
my @confirmed;
sub get_requires ($) {
- my $location = get_sbo_location($_[0]);
+ my $location = get_sbo_location(shift);
my $requires = get_from_info (LOCATION => $location, GET => 'REQUIRES');
return $requires;
}
sub get_required_by ($) {
- my $pkg = $_[0];
- my @dep_of = ();
- if ( $required_by{$pkg} ) {
- for my $req_by (@{$required_by{$pkg}}) {
+ my $sbo = shift;
+ my @dep_of;
+ if ( $required_by{$sbo} ) {
+ for my $req_by (@{$required_by{$sbo}}) {
unless ($req_by ~~ @confirmed) {
push (@dep_of, $req_by);
}
@@ -83,76 +79,83 @@ sub get_required_by ($) {
}
sub confirm_remove ($) {
- unless ($_[0] ~~ @confirmed) {
- push(@confirmed, $_[0]);
+ my $sbo = shift;
+ unless ($sbo ~~ @confirmed) {
+ push(@confirmed, $sbo);
}
}
-# Determine dependencies of root package
-unless ($no_reqs) {
- $remove_queue = get_build_queue($rootpkg);
- @$remove_queue = reverse(@$remove_queue);
-} else {
+
+# Determine dependencies & warnings of root package
+$remove_queue = get_build_queue($rootpkg, \%warnings);
+@$remove_queue = reverse(@$remove_queue);
+if ($no_reqs) {
+ @$remove_queue = ();
push(@$remove_queue, $rootpkg);
}
-my $inst_names;
# Determine required by for all installed sbo's
-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);
- }
- }
- }
- }
+my $installed = get_installed_sbos;
+my $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.
+# Check if packages in queue are actually installed on system
my @temp;
if ($inst_names) {
- for my $i (@$remove_queue) {
- if ($i ~~ $inst_names) {
- push(@temp, $i);
+ for my $sbo (@$remove_queue) {
+ if ($sbo ~~ $inst_names) {
+ push(@temp, $sbo);
}
}
$remove_queue = \@temp;
}
-if ( $non_int) {
- my $ignore;
- 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;
- }
- }
- }
- }
- unless ($ignore) {
- confirm_remove $pkg;
- }
+
+# Gather instructions from user
+my ($req_by_line, @req_by, $req_count, $cnf_count);
+my $is_rootpkg = 1;
+for my $pkg (@$remove_queue) {
+ $req_by_line = get_required_by $pkg;
+ @req_by = split(" ", $req_by_line);
+ $req_count = @req_by;
+ $cnf_count = 0;
+ for my $val (@req_by) {
+ if ( $val ~~ @confirmed ) { $cnf_count++; }
}
-} else {
- for my $pkg (@$remove_queue) {
+ if ($cnf_count == $req_count or $is_rootpkg or $force) {
say $pkg;
- my $req_by_line = get_required_by $pkg;
- my $default = "y";
if ( $req_by_line ) {
- say "required by : $req_by_line";
- $default = "n";
+ say "Required by: $req_by_line";
+ } else {
+ unless ($is_rootpkg) {
+ say "It appears $pkg is no longer required on your system";
+ }
}
- print "Remove? [$default] : ";
- my $userin = <STDIN>;
- chomp($userin);
- $userin = $default unless $userin;
+ $is_rootpkg = 0;
+ if ( exists $warnings{$pkg} ) {
+ say "$pkg suggests you view its README before proceeding,";
+ print "view now? [y] : ";
+ chomp(my $viewrm = <STDIN>);
+ if ($viewrm =~ /^[Yy]/) {
+ print "\n";
+ my $locrm = get_sbo_location $pkg;
+ $locrm .= '/README';
+ open(README, '<', $locrm) or die "could not open $locrm";
+ for my $line (<README>) {
+ print $line;
+ }
+ }
+ }
+ print "Remove $pkg? [n] : ";
+ chomp(my $userin = <STDIN>);
if ($userin =~ /^[Yy]/) {
confirm_remove $pkg;
say "* added $pkg to remove queue\n";
@@ -161,6 +164,7 @@ if ( $non_int) {
}
}
}
+
# Show remove queue
my $remove_count = @confirmed;
if ($remove_count) {
@@ -170,16 +174,16 @@ if ($remove_count) {
}
say "\n";
} else {
- say "Nothing to remove.";
+ say 'Nothing to remove.';
exit 0;
}
-unless ($non_int) {
- print 'Do you wish to proceed? [n] ';
- unless (<STDIN> =~ /^[Yy]/) {
- say "Exiting.";
- exit 0;
- }
+
+print 'Are you sure you want to continue? [n] : ';
+unless (<STDIN> =~ /^[Yy]/) {
+ say 'Exiting.';
+ exit 0;
}
+
for my $instpkg (@confirmed) {
system("/sbin/removepkg $instpkg");