From 997c0c134f4af389626eb02c88baec390cba269c Mon Sep 17 00:00:00 2001 From: xocel Date: Tue, 9 Oct 2012 02:29:34 +1300 Subject: sboremove --- sboremove | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100755 sboremove (limited to 'sboremove') diff --git a/sboremove b/sboremove new file mode 100755 index 0000000..fc9cadc --- /dev/null +++ b/sboremove @@ -0,0 +1,133 @@ +#!/usr/bin/env perl +# +# vim: set ts=4:noet +# +# sboremove +# script to remove an installed SlackBuild. +# +# author: Luke Williams +# license: WTFPL + +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 show_usage () { + print < \$help, + 'version|v' => \$vers, + 'nointeractive|r' => \$non_int, + 'norequirements|R' => \$no_reqs, + 'exclude|e=s' => \@excluded, +); + +show_usage and exit 0 if $help; +show_version and exit 0 if $vers; +show_usage and exit 0 unless exists $ARGV[0]; + +my $remove_queue; +push(@$remove_queue, $ARGV[0]); +my %ignore; + +unless ($no_reqs) { + for my $ex (@excluded) { + $ignore{$ex}="excluded by user"; + } + $remove_queue = get_build_queue($ARGV[0]); + my $installed = get_installed_sbos; + my $inst_names = get_inst_names $installed; + #print files... + for my $pkg (@$inst_names) { + unless ($pkg ~~ @$remove_queue) { + my $location = get_sbo_location($pkg); + my $requires = get_from_info (LOCATION => $location, GET => 'REQUIRES'); + next unless $$requires[0]; + for my $req (@$requires) { + if ($req ~~ @$remove_queue) { + $ignore{$req}="required by $pkg"; + push(@excluded, $req); + } + } + } + } +} +my $queue = join(" ", @$remove_queue); +say "Remove: $queue\n"; +# Removed excluded +my $exclude; +my @new = (); +for my $sb (@$remove_queue) { + $exclude = 0; + foreach (@excluded) { + if ( $_ eq $sb ) { + $exclude = 1; + } + } + unless ($exclude) { + push(@new, $sb); + } +} + +$remove_queue = \@new; + +# Show ignored +my $ignore_count = keys(%ignore); +if ($ignore_count) { + say "Ignoring $ignore_count package(s)."; + while ( my ($key, $value) = each(%ignore) ) { + say "$key : $value"; + } + print "\n"; +} + +# Show remove queue +my $remove_count = @$remove_queue; +if ($remove_count) { + say "Removing $remove_count package(s)."; + for my $i (@$remove_queue) { + print "$i\n"; + } + print "\n"; +} else { + say "Nothing to remove."; + exit 0; +} + +print 'Do you wish to proceed? [n] '; +unless ( =~ /^[Yy]/) { + say "Exiting."; + exit 0; +} + +for my $instpkg (@$remove_queue) { + system("/sbin/removepkg $instpkg"); +} + +say "All operations completed successfully." -- cgit v1.2.3