aboutsummaryrefslogtreecommitdiff
path: root/sboupgrade
diff options
context:
space:
mode:
Diffstat (limited to 'sboupgrade')
-rwxr-xr-xsboupgrade121
1 files changed, 69 insertions, 52 deletions
diff --git a/sboupgrade b/sboupgrade
index 6d92d1c..7b7b46d 100755
--- a/sboupgrade
+++ b/sboupgrade
@@ -10,14 +10,13 @@
# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
use 5.12.3;
+use strict;
+use warnings FATAL => 'all';
use SBO::Lib;
use File::Basename;
use Getopt::Std;
use File::Copy;
-use strict;
-use warnings FATAL => 'all';
-my %config = %SBO::Lib::config;
my $self = basename ($0);
sub show_usage () {
@@ -96,8 +95,8 @@ sub get_inst_names ($) {
}
# this subroutine may be getting a little out of hand.
-sub grok_requirements ($$) {
- exists $_[1] or script_error 'grok_requirements requires two arguments';
+sub get_requires ($$) {
+ exists $_[1] or script_error 'get_requires requires two arguments';
return if $no_reqs;
my ($sbo, $readme) = @_;
my $readme_orig = $readme;
@@ -133,58 +132,68 @@ sub grok_requirements ($$) {
splice @deps, $rem, 1;
$_-- for @remove;
}
- return unless exists $deps[0];
- FIRST: for my $need (@deps) {
- # compare against installed slackbuilds
- my $tempname = $compat32 eq 'TRUE' ? "$need-compat32" : $need;
+ return \@deps;
+
+# ask to install any requirements found
+sub ask_requires ($$$) {
+ exists $_[2] or script_error 'ask_requires requires three arguments.';
+ my ($requires, $readme, $sbo) = shift;
+ FIRST: for my $req (@$requires) {
+ my $name = $compat32 ? "$req-compat32" : $req;
my $inst = get_installed_sbos;
my $inst_names = get_inst_names $inst;
- next FIRST if $tempname ~~ @$inst_names;
- print "\n". $readme_orig;
- print "\nIt looks like this slackbuild requires $tempname; shall I";
+ next FIRST if $name ~~ @$inst_names;
+ say $readme;
+ print "\nIt looks like this slackbuild requires $name; shall I";
print " attempt to install it first? [y] ";
if (<STDIN> =~ /^[Yy\n]/) {
- my @args = ("/usr/sbin/sboupgrade", '-oN');
+ my @args = ('/usr/sbin/sboupgrade', '-oN');
# populate args so that they carry over correctly
- push @args, "-c" if exists $options{c};
- push @args, "-d" if exists $options{d};
+ for my $arg (qw(c d p)) {
+ push @args, "-$arg" if exists $options{$arg};
+ }
push @args, "-j $options{j}" if exists $options{j};
- push @args, "-p" if $compat32;
- push @args, $need;
- system (@args) == 0 or
- die "Requirement failure, unable to proceed.\n";
+ system (@args, $req) == 0 or die "$name failed to install.\n";
}
}
return;
}
# look for any (user|group)add commands in the README
-sub grok_user_group ($) {
- exists $_[0] or script_error 'grok_user_group requires an argument';
+sub get_user_group ($) {
+ exists $_[0] or script_error 'get_user_group requires an argument';
my $readme = shift;
- my $readme_array = [split /\n/, $readme];
- my $cmd_regex = qr/^\s*#\s+((user|group)add.*)/;
- my @cmds;
- push @cmds, ($_ =~ $cmd_regex)[0] for @$readme_array;
- return unless exists $cmds[0];
+ my @cmds = $readme =~ /^\s*#*\s*(useradd.*|groupadd.*)/mg;
+ return \@cmds;
+}
+
+# offer to run any user/group add commands
+sub ask_user_group ($$) {
+ exists $_[1] or script_error 'ask_user_group requires two arguments';
+ my ($cmds, $readme) = shift;
say "\n". $readme;
- print "\nIt looks like this slackbuild requires the following command(s)";
- say ' to be run first:';
- say " # $_" for @cmds;
+ print "\nIt looks like this slackbuild requires the following";
+ say " command(s) to be run first:";
+ say " # $_" for @$cmds;
print "Shall I run it/them now? [y] ";
if (<STDIN> =~ /^[Yy\n]/) {
- for my $cmd (@cmds) {
- system ($cmd == 0) or warn "\"$cmd\" exited non-zero\n";
+ for my $cmd (@$cmds) {
+ system ($cmd) == 0 or warn "\"$cmd\" exited non-zero\n";
}
}
- return 1;
}
# see if the README mentions any options
-sub grok_options ($) {
- exists $_[0] or script_error 'grok_options requires an argument';
+sub get_opts ($) {
+ exists $_[0] or script_error 'get_opts requires an argument';
+ my $readme = shift;
+ return $readme =~ /[A-Z]+=[^\s]/ ? 1 : undef;
+}
+
+# provide an opportunity to set options
+sub ask_opts ($) {
+ exists $_[0] or script_error 'ask_opts requires an argument';
my $readme = shift;
- return unless $readme =~ /[A-Z]+=[^\s]/;
say "\n". $readme;
print "\nIt looks this slackbuilds has options; would you like to set any";
print " when the slackbuild is run? [n] ";
@@ -196,10 +205,10 @@ sub grok_options ($) {
return $opts;
};
my $kv_regex = qr/[A-Z]+=[^\s]+(|\s([A-Z]+=[^\s]+){0,})/;
- my $opts = &$ask ();
+ my $opts = &$ask;
FIRST: while ($opts !~ $kv_regex) {
warn "Invalid input received.\n";
- $opts = &$ask ();
+ $opts = &$ask;
}
return $opts;
}
@@ -213,10 +222,15 @@ sub readme_prompt ($) {
my $fh = open_read (get_readme_path $sbo);
my $readme = do {local $/; <$fh>};
close $fh;
- # check for requirements, useradd/groupadd, options
- grok_requirements $sbo, $readme;
- grok_user_group $readme;
- my $opts = grok_options $readme;
+ # check for requirements, offer to install any found
+ my $requires = get_requires $sbo, $readme;
+ ask_requires $requires, $readme, $sbo if ref $requires eq 'ARRAY';
+ # check for user/group add commands, offer to run any found
+ my $user_group = get_user_group $readme;
+ ask_user_group $user_group, $readme if ref $user_group eq 'ARRAY';
+ # check for options mentioned in the README
+ my $opts;
+ $opts = ask_opts $readme if get_opts $readme;
print "\n". $readme unless $opts;
# present the name as -compat32 if appropriate
my $name = $compat32 ? "$sbo-compat32" : $sbo;
@@ -229,7 +243,7 @@ sub readme_prompt ($) {
sub process_sbos ($) {
exists $_[0] or script_error 'process_sbos requires an argument.';
my $todo = shift;
- my @failures;
+ my %failures;
FIRST: for my $sbo (@$todo) {
my $opts = 0;
$opts = readme_prompt $sbo unless $no_readme;
@@ -243,7 +257,7 @@ sub process_sbos ($) {
COMPAT32 => $compat32,
); };
if ($@) {
- push @failures, $sbo;
+ $failures{$sbo} = $@;
} else {
unless ($distclean eq 'TRUE') {
make_clean $sbo, $src, $version unless $noclean eq 'TRUE';
@@ -272,13 +286,16 @@ sub process_sbos ($) {
}
}
}
- return @failures;
+ return %failures;
}
-sub print_failures (;@) {
+sub print_failures (;%) {
if (exists $_[0]) {
+ my %failures = @_;
say "Failures:";
- say " $_" for @_;
+ while (my ($key, $val) = each %failures) {
+ say " $key: $val";
+ }
exit 1;
}
}
@@ -306,20 +323,20 @@ unless ($force) {
push @$todo_upgrade, $sbo if $sbo ~~ @$inst_names;
}
}
-my @failures = process_sbos $todo_upgrade if exists $$todo_upgrade[0];
-print_failures @failures;
+my %failures = process_sbos $todo_upgrade if exists $$todo_upgrade[0];
+print_failures %failures;
INSTALL_NEW:
exit 0 unless $install_new;
my $todo_install;
FIRST: for my $sbo (@ARGV) {
my $name = $compat32 ? "$sbo-compat32" : $sbo;
- my $inst = get_installed_sbos;
+ my $inst = get_installed_sbos;
my $inst_names = get_inst_names $inst;;
warn "$name already installed\n", next FIRST if $name ~~ @$inst_names;
# if compat32 is TRUE, we need to see if the non-compat version exists.
if ($compat32) {
- my $inst = get_installed_sbos;
+ my $inst = get_installed_sbos;
my $inst_names = get_inst_names $inst;
unless ($sbo ~~ @$inst_names) {
print "\nYou are attempting to install $name, however, $sbo is not";
@@ -334,7 +351,7 @@ FIRST: for my $sbo (@ARGV) {
}
push @$todo_install, $sbo;
}
-@failures = process_sbos $todo_install if exists $$todo_install[0];
-print_failures @failures;
+%failures = process_sbos $todo_install if exists $$todo_install[0];
+print_failures %failures;
exit 0;