#!/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 File::Copy; use strict; use warnings FATAL => 'all'; my %config = %SBO::Lib::config; my $self = basename ($0); sub show_usage { print <; $test = 'y' if $test eq "\n"; if ($test =~ /^[Yy]/) { my $cmd = "/usr/sbin/sboupgrade"; my @args = ('-oN'); # populate args so that they carry over correctly push (@args, "-c") if exists $options{c}; push (@args, "-d") if exists $options{d}; push (@args, "-j $options{j}") if exists $options{j}; push (@args, "-p") if $compat32 eq 'TRUE'; push (@args, "$need"); system ($cmd, @args); } } } # prompt for the readme, and grok the readme at this time also. we grok the # readme within this subroutine so that if the readme_prompt is bypassed, the # requirement parsing will be as well - that should never be able to happen # w/o the user verifying its suggestions against the readme sub readme_prompt { script_error ('readme_prompt requires an argument.') unless exists $_[0]; my $sbo = shift; my $readme_path = get_readme_path ($sbo); open my $readme_file, '<', $readme_path; my $readme = do {local $/; <$readme_file>}; unless (grok_readme ($sbo, $readme) ) { print "\n". $readme; close ($readme_file); print "\nProceed with $sbo? [y]: "; my $test = ; $test = 'y' if $test eq "\n"; exit (0) unless $test =~ /^[Yy]/; return 1; } } # do the things with the provided sbos - whether upgrades or new installs. 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'; # switch compat32 on if upgrading a -compat32 # this should maybe happen not in this sub? $compat32 = 'TRUE' if $sbo =~ /-compat32$/; my $version; my $pkg; my $src; eval { ($version, $pkg, $src) = do_slackbuild ($jobs, $sbo, $locations{$sbo}, $compat32); }; if ($@) { push (@failures, $sbo); } else { unless ($distclean eq 'TRUE') { make_clean ($sbo, $src, $version) if $noclean eq 'FALSE'; } else { make_distclean ($sbo, $src, $version, $locations{$sbo}); } do_upgradepkg ($pkg) unless $no_install eq 'TRUE'; # move package to $config{PKG_DIR} if defined unless ($config{PKG_DIR} eq 'FALSE') { unless (-d $config{PKG_DIR}) { mkdir ($config{PKG_DIR}) or warn "Unable to create $config{PKG_DIR}\n"; } if (-d $config{PKG_DIR}) { move ($pkg, $config{PKG_DIR}); print "$pkg stored in $config{PKG_DIR}\n"; } else { warn "$pkg left in /tmp\n"; } } elsif ($distclean eq 'TRUE') { unlink ($pkg); } } } return @failures; } my @installed = get_installed_sbos (); my @failed; sub print_failures { if (exists $failed[0]) { print "Failures:\n"; print " $_\n" for (@failed); exit 1; } } # deal with any updates prior to any new installs; no reason to bother with all # this if only_new is specified - ie, if we are run from sboinstall, so can be # much faster with this separation of logic unless ($only_new eq 'TRUE') { # doesn't matter what's updatable and what's not if force is specified my @updates unless $force eq 'TRUE'; unless ($force eq 'TRUE') { my @updates_array = get_available_updates (); for my $key (keys @updates_array) { push(@updates, $updates_array[$key]{name}); } } my @todo_upgrade; # but without force, we only want to update what there are updates for unless ($force eq 'TRUE') { for my $sbo (@ARGV) { if ($sbo ~~ @updates) { push (@todo_upgrade, $sbo); } } } else { FIRST: for my $sbo (@ARGV) { SECOND: for my $key (keys @installed) { if ($sbo eq $installed[$key]{name}) { push (@todo_upgrade, $sbo); last SECOND; } } } } @failed = process_sbos (@todo_upgrade) if exists $todo_upgrade[0]; print_failures () unless $install_new eq 'TRUE'; } if ($install_new eq 'TRUE') { my @todo_install; my $has = 'FALSE'; FIRST: for my $sbo (@ARGV) { # rename to -compat32 if appropriate, so that we can see if it's # already installed my $name = $compat32 eq 'TRUE' ? "$sbo-compat32" : $sbo; SECOND: for my $key (keys @installed) { if ($name eq $installed[$key]{name}) { $has = 'TRUE'; last SECOND; } } unless ($has eq 'TRUE') { push (@todo_install, $sbo); } else { print "$name already installed.\n"; } $has = 'FALSE'; } @failed = process_sbos (@todo_install) if exists $todo_install[0]; print_failures (); } exit 0;