aboutsummaryrefslogtreecommitdiff
path: root/sboupgrade
diff options
context:
space:
mode:
Diffstat (limited to 'sboupgrade')
-rwxr-xr-xsboupgrade183
1 files changed, 183 insertions, 0 deletions
diff --git a/sboupgrade b/sboupgrade
new file mode 100755
index 0000000..c68d276
--- /dev/null
+++ b/sboupgrade
@@ -0,0 +1,183 @@
+#!/usr/bin/env perl
+#
+# sboupgrade
+# script to update an installed SlackBuild.
+#
+# author: Jacob Pipkin <j@dawnrazor.net>
+# date: Boomtime, the 39th day of Discord in the YOLD 3178
+# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
+
+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 <<EOF
+Usage: $self (options) [package]
+
+Options:
+ -h: this screen.
+ -v: version information.
+ -c: do not clean working files/directories after the build.
+ -d: clean distfiles afterward.
+ -f: force an update, even if the "upgrade" version is the same or lower.
+ -N: install any new SBo's listed.
+ -r: skip viewing of the SBo README.
+
+Example:
+ $self -d libsexy
+ $self -ca
+
+EOF
+# -j: specify "-j" setting to make, for SMP systems; overrides conf file.
+}
+
+my %options;
+getopts('hvacdfj:Nr',\%options);
+
+
+show_usage() && exit(0) if exists $options{h};
+show_version() && exit(0) if exists $options{v};
+my $noclean = exists $options{c} ? 'FALSE' : $config{NOCLEAN};
+my $distclean = exists $options{d} ? 'TRUE' : $config{DISTCLEAN};
+my $force = exists $options{f} ? 'TRUE' : 'FALSE';
+#my $jobs = exists $options{j} ? $options{j} : $config{JOBS};
+my $jobs = 'FALSE';
+my $install_new = exists $options{N} ? 'TRUE' : 'FALSE';
+my $no_readme = exists $options{r} ? 'TRUE' : 'FALSE';
+
+show_usage() and exit(1) unless exists $ARGV[0];
+
+for my $sbo_name (@ARGV) {
+ check_sbo_name_validity($sbo_name);
+}
+
+sub get_readme_path {
+ script_error('get_readme_path requires an argument.') unless exists $_[0];
+ my $sbo = shift;
+ my $location = get_sbo_location($sbo);
+ return $location .'/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,'<',$readme_path;
+ print "\n",<$readme>;
+ close($readme);
+ print "\nProceed with $sbo? [yn]: ";
+ my $test = <STDIN>;
+ 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_slack_build($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);