#!/usr/bin/env perl # # sboupgrade # script to update an installed SlackBuild. # # author: Jacob Pipkin # date: Boomtime, the 39th day of Discord in the YOLD 3178 # license: WTFPL use SBO::Lib; use File::Basename; use Getopt::Std; use Text::Tabulate; use File::Copy; use strict; use warnings FATAL => 'all'; my %config = %SBO::Lib::config; my $self = basename($0); sub show_usage { print <; close($readme); print "\nProceed with $sbo? [yn]: "; my $test = ; exit(0) unless $test =~ /^[Yy]/; return 1; } sub process_sbos { script_error('process_sbos requires an argument.') unless exists $_[0]; my @todo = @_; my @failures; for my $sbo (@todo) { readme_prompt($sbo) unless $no_readme eq 'TRUE'; my $version; eval { $version = do_slackbuild($jobs,$sbo); }; if ($@) { push(@failures,$sbo); } else { unless ($distclean eq 'TRUE') { if ($noclean eq 'FALSE') { make_clean($sbo,$version); } } else { make_distclean($sbo,$version); } my $pkg = do_upgradepkg($sbo,$version); unless ($config{PKG_DIR} eq 'FALSE') { unless (-d $config{PKG_DIR}) { mkdir($config{PKG_DIR}) or warn "Unable to create $config{PKG_DIR}\n"; } move($pkg,$config{PKG_DIR}) if -d $config{PKG_DIR}; print "$pkg stored in $config{PKG_DIR}\n"; } elsif ($distclean eq 'TRUE') { unlink($pkg); } } } return @failures; } # this can probably be redone to be faster overall. my @updates unless $force eq 'TRUE'; unless ($force eq 'TRUE') { my @updates_array = get_available_updates(); for my $index (keys @updates_array) { push(@updates,$updates_array[$index]{name}); } } my @installed = get_installed_sbos(); my @todo_upgrade; unless ($force eq 'TRUE') { for (@ARGV) { if ($_ ~~ @updates) { push(@todo_upgrade,$_); } } } else { for (@ARGV) { SECOND: for my $c (keys @installed) { if ($_ eq $installed[$c]{name}) { push(@todo_upgrade,$_); last SECOND; } } } } my @failed; @failed = process_sbos(@todo_upgrade) if exists $todo_upgrade[0]; sub print_failures { if (exists $failed[0]) { print "Failures:\n"; print " $_\n" for (@failed); exit(1); } } print_failures() unless $install_new eq 'TRUE'; my @todo_install; my $has = 'FALSE'; for (@ARGV) { SECOND: for my $index (keys @installed) { if ($_ eq $installed[$index]{name}) { $has = 'TRUE'; last SECOND; } } unless ($has eq 'TRUE') { push(@todo_install,$_); } else { print "$_ already installed.\n"; } $has = 'FALSE'; } @failed = process_sbos(@todo_install) if exists $todo_install[0]; print_failures(); exit(0);