aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ Pipkin <j@dawnrazor.net>2013-01-12 07:14:20 -0600
committerJ Pipkin <j@dawnrazor.net>2013-01-12 07:14:20 -0600
commit32abf3c7e9183cfe79019c748e588496722f7426 (patch)
tree7d9cd861e15595abebdda688fb6066e82febba62
parentb2a26f795d32e398bfc3dbfc13882419bd3ba929 (diff)
parentf177c4e5c4311e696373c77e593df452c7602d13 (diff)
downloadsbotools2-32abf3c7e9183cfe79019c748e588496722f7426.tar.xz
Merge branch 'exit_ask', fixes #41, fixes #37
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm292
-rw-r--r--man1/sboclean.111
-rw-r--r--man1/sboconfig.114
-rw-r--r--man1/sbofind.113
-rw-r--r--man1/sboinstall.137
-rw-r--r--man1/sboremove.110
-rw-r--r--man1/sbosnap.110
-rw-r--r--man1/sboupgrade.137
-rwxr-xr-xsbocheck13
-rwxr-xr-xsboclean2
-rwxr-xr-xsboconfig35
-rwxr-xr-xsbofind12
-rwxr-xr-xsboinstall23
-rwxr-xr-xsboremove22
-rwxr-xr-xsboupgrade15
-rwxr-xr-xt/prep.pl31
-rwxr-xr-xt/test.t28
-rwxr-xr-xtools/masstest_sbo.sh28
18 files changed, 451 insertions, 182 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index c138846..83fbe3c 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -13,7 +13,6 @@ use 5.16.0;
use strict;
use warnings FATAL => 'all';
-
package SBO::Lib;
our $VERSION = '1.4';
@@ -58,7 +57,24 @@ our @EXPORT = qw(
%config
);
-$< == 0 or die "This script requires root privileges.\n";
+use constant {
+ _ERR_USAGE => 1, # usage errors
+ _ERR_SCRIPT => 2, # errors with the scripts themselves
+ _ERR_BUILD => 3, # errors during the slackbuild process
+ _ERR_MD5SUM => 4, # md5sum verification
+ _ERR_DOWNLOAD => 5, # errors with downloading things
+ _ERR_OPENFH => 6, # opening file handles
+ _ERR_NOINFO => 7, # missing information
+ _ERR_F_SETFD => 8, # unsetting exec-on-close bit
+ _ERR_NOMULTILIB => 9, # lacking multilib where required
+ _ERR_CONVERTPKG => 10, # errors while running convertpkg-compat32
+ _ERR_NOCONVERTPKG => 11, # lacking convertpkg-compat32 where required
+};
+
+unless ($< == 0) {
+ warn "This script requires root privileges.\n";
+ exit _ERR_USAGE;
+}
use Tie::File;
use Sort::Versions;
@@ -70,11 +86,6 @@ use File::Find;
use File::Basename;
use Fcntl qw(F_SETFD F_GETFD);
-# define error statuses
-use constant {
- _ERR_USAGE => 1,
-};
-
our $tempdir = tempdir(CLEANUP => 1);
# define this to facilitate unit testing - should only ever be modified from
@@ -83,8 +94,9 @@ our $pkg_db = '/var/log/packages';
# subroutine for throwing internal script errors
sub script_error(;$) {
- exists $_[0] ? die "A fatal script error has occurred:\n$_[0]\nExiting.\n"
- : die "A fatal script error has occurred. Exiting.\n";
+ exists $_[0] ? warn "A fatal script error has occurred:\n$_[0]\nExiting.\n"
+ : warn "A fatal script error has occurred. Exiting.\n";
+ exit _ERR_SCRIPT;
}
# subroutine for usage errors
@@ -100,7 +112,12 @@ sub open_fh {
-f $_[0] or script_error "open_fh, $_[0] is not a file";
}
my ($file, $op) = @_;
- open my $fh, $op, $file or die "Unable to open $file.\n";
+ my $fh;
+ unless (open $fh, $op, $file) {
+ my $warn = "Unable to open $file.\n";
+ my $exit = _ERR_OPENFH;
+ return ($warn, $exit);
+ }
return $fh;
}
@@ -123,7 +140,12 @@ our %config = (
sub read_config() {
my %conf_values;
if (-f $conf_file) {
- my $fh = open_read $conf_file;
+ my ($fh, $exit) = open_read $conf_file;
+ if ($exit) {
+ warn $fh;
+ $config{SBO_HOME} = '/usr/sbo';
+ return;
+ }
my $text = do {local $/; <$fh>};
%conf_values = $text =~ /^(\w+)=(.*)$/mg;
close $fh;
@@ -153,11 +175,15 @@ sub show_version() {
# but it's already future-proofed, so leave it.
sub get_slack_version() {
my %supported = ('14.0' => '14.0');
- my $fh = open_read '/etc/slackware-version';
+ my ($fh, $exit) = open_read '/etc/slackware-version';
+ if ($exit) {
+ warn $fh;
+ exit $exit;
+ }
chomp(my $line = <$fh>);
close $fh;
my $version = ($line =~ /\s+(\d+[^\s]+)$/)[0];
- die "Unsupported Slackware version: $version\n"
+ usage_error "Unsupported Slackware version: $version\n"
unless $version ~~ %supported;
return $supported{$version};
}
@@ -174,10 +200,10 @@ sub check_home() {
opendir(my $home_handle, $sbo_home);
FIRST: while (readdir $home_handle) {
next FIRST if /^\.[\.]{0,1}$/;
- die "$sbo_home exists and is not empty. Exiting.\n";
+ usage_error "$sbo_home exists and is not empty. Exiting.\n";
}
} else {
- make_path($sbo_home) or die "Unable to create $sbo_home.\n";
+ make_path($sbo_home) or usage_error "Unable to create $sbo_home.\n";
}
return 1;
}
@@ -215,8 +241,12 @@ sub slackbuilds_or_fetch() {
unless (chk_slackbuilds_txt) {
say 'It looks like you haven\'t run "sbosnap fetch" yet.';
print 'Would you like me to do this now? [y] ';
- <STDIN> =~ /^[Yy\n]/ ? fetch_tree :
- die "Please run \"sbosnap fetch\"\n";
+ if (<STDIN> =~ /^[Yy\n]/) {
+ fetch_tree;
+ } else {
+ say 'Please run "sbosnap fetch"';
+ exit 0;
+ }
}
return 1;
}
@@ -269,7 +299,11 @@ sub get_sbo_location {
return $$store{$sbos[0]} if exists $$store{$sbos[0]};
}
my %locations;
- my $fh = open_read $slackbuilds_txt;
+ my ($fh, $exit) = open_read $slackbuilds_txt;
+ if ($exit) {
+ warn $fh;
+ exit $exit;
+ }
FIRST: for my $sbo (@sbos) {
$locations{$sbo} = $$store{$sbo}, next FIRST if exists $$store{$sbo};
my $regex = qr#LOCATION:\s+\.(/[^/]+/\Q$sbo\E)$#;
@@ -307,7 +341,8 @@ sub get_from_info {
my $sbo = get_sbo_from_loc $args{LOCATION};
return $$store{$args{GET}} if $$store{PRGNAM}[0] eq $sbo;
# if we're here, we haven't read in the .info file yet.
- my $fh = open_read "$args{LOCATION}/$sbo.info";
+ my ($fh, $exit) = open_read "$args{LOCATION}/$sbo.info";
+ return if $exit;
# suck it all in, clean it all up, stuff it all in $store.
my $contents = do {local $/; <$fh>};
$contents =~ s/("|\\\n)//g;
@@ -362,7 +397,7 @@ sub get_download_info {
@_
);
$args{LOCATION} or script_error 'get_download_info requires LOCATION.';
- my ($get, $downs, $md5s, %return);
+ my ($get, $downs, $exit, $md5s, %return);
$get = ($args{X64} ? 'DOWNLOAD_x86_64' : 'DOWNLOAD');
$downs = get_from_info(LOCATION => $args{LOCATION}, GET => $get);
# did we get nothing back, or UNSUPPORTED/UNTESTED?
@@ -422,7 +457,7 @@ sub get_filename_from_link($) {
# for a given file, compute its md5sum
sub compute_md5sum($) {
-f $_[0] or script_error 'compute_md5sum requires a file argument.';
- my $fh = open_read shift;
+ my ($fh, $exit) = open_read shift;
my $md5 = Digest::MD5->new;
$md5->addfile($fh);
my $md5sum = $md5->hexdigest;
@@ -450,11 +485,12 @@ sub get_distfile {
mkdir $distfiles unless -d $distfiles;
chdir $distfiles;
unlink $filename if -f $filename;
- system("wget --no-check-certificate $link") == 0 or
- die "Unable to wget $link\n";
+ if (system("wget --no-check-certificate $link") != 0) {
+ return "Unable to wget $link.\n", _ERR_DOWNLOAD;
+ }
# can't do anything if the link in the .info doesn't lead to a good d/l
- verify_distfile(@_) ? return 1 : die "md5sum failure for $filename.\n";
- return 1;
+ verify_distfile(@_) ? return 1 : return "md5sum failure for $filename.\n",
+ _ERR_MD5SUM;
}
# for a given distfile, figure out what the full path to its symlink will be
@@ -525,8 +561,10 @@ sub rewrite_slackbuild {
$args{SLACKBUILD} or script_error 'rewrite_slackbuild requires SLACKBUILD.';
my $slackbuild = $args{SLACKBUILD};
my $changes = $args{CHANGES};
- copy($slackbuild, "$slackbuild.orig") or
- die "Unable to backup $slackbuild to $slackbuild.orig\n";
+ unless (copy($slackbuild, "$slackbuild.orig")) {
+ return "Unable to backup $slackbuild to $slackbuild.orig\n",
+ _ERR_OPENFH;
+ }
my $libdir_regex = qr/^\s*LIBDIRSUFFIX="64"\s*$/;
my $arch_regex = qr/\$VERSION-\$ARCH-\$BUILD/;
my $dc_regex = qr/(?<![a-z])(tar|p7zip|unzip|ar|rpm2cpio|sh)\s+/;
@@ -592,10 +630,16 @@ sub check_distfiles {
LOCATION => $location,
32 => $args{COMPAT32}
);
- die "Unable to get download information from $location/$sbo.info.\n" unless
- keys %$downloads > 0;
+ # return an error if we're unable to get download info
+ unless (keys %$downloads > 0) {
+ return "Unable to get download info from $location/$sbo.info\n",
+ _ERR_NOINFO;
+ }
while (my ($link, $md5) = each %$downloads) {
- get_distfile($link, $md5) unless verify_distfile($link, $md5);
+ unless (verify_distfile($link, $md5)) {
+ my ($fail, $exit) = get_distfile($link, $md5);
+ return $fail, $exit if $exit;
+ }
}
my $symlinks = create_symlinks($args{LOCATION}, $downloads);
return $symlinks;
@@ -655,7 +699,9 @@ sub get_src_dir($) {
sub get_tmp_extfn($) {
exists $_[0] or script_error 'get_tmp_extfn requires an argument.';
my $fh = shift;
- fcntl($fh, F_SETFD, 0) or die "Can't unset exec-on-close bit\n";
+ unless (fcntl($fh, F_SETFD, 0)) {
+ return "Can't unset exec-on-close bit.\n", _ERR_F_SETFD;
+ }
return '/dev/fd/'. fileno $fh;
}
@@ -701,22 +747,31 @@ sub perform_sbo {
}
# get a tempfile to store the exit status of the slackbuild
my $exit_temp = tempfile(DIR => $tempdir);
- my $exit_fn = get_tmp_extfn $exit_temp;
+ my ($exit_fn, $exit) = get_tmp_extfn $exit_temp;
+ return $exit_fn, undef, $exit if $exit;
$cmd .= " /bin/sh $location/$sbo.SlackBuild; echo \$? > $exit_fn )";
my $tempfh = tempfile(DIR => $tempdir);
- my $fn = get_tmp_extfn $tempfh;
+ my $fn;
+ ($fn, $exit) = get_tmp_extfn $tempfh;
+ return $fn, undef, $exit if $exit;
$cmd .= " | tee -a $fn";
- rewrite_slackbuild(
+ # attempt to rewrite the slackbuild, or exit if we can't
+ my $fail;
+ ($fail, $exit) = rewrite_slackbuild(
SBO => $sbo,
SLACKBUILD => "$location/$sbo.SlackBuild",
CHANGES => \%changes,
C32 => $args{C32},
);
+ return $fail, undef, $exit if $exit;
+ # run the slackbuild, grab its exit status, revert our changes
chdir $location, system $cmd;
seek $exit_temp, 0, 0;
my $out = do {local $/; <$exit_temp>};
+ close $exit_temp;
revert_slackbuild "$location/$sbo.SlackBuild";
- die "$sbo.SlackBuild returned non-zero exit status\n" unless $out == 0;
+ # return error now if the slackbuild didn't exit 0
+ return "$sbo.SlackBuild return non-zero\n", undef, _ERR_BUILD if $out != 0;
my $pkg = get_pkg_name $tempfh;
my $src = get_src_dir $src_ls_fh;
return $pkg, $src;
@@ -729,8 +784,10 @@ sub do_convertpkg($) {
my $tempfh = tempfile(DIR => $tempdir);
my $fn = get_tmp_extfn $tempfh;
my $cmd = "/usr/sbin/convertpkg-compat32 -i $pkg -d /tmp | tee $fn";
- system($cmd) == 0 or
- die "convertpkg-compt32 returned non-zero exit status\n";
+ if (system($cmd) != 0) {
+ return "convertpkg-compt32 returned non-zero exit status\n",
+ _ERR_CONVERTPKG;
+ }
unlink $pkg;
return get_pkg_name $tempfh;
}
@@ -753,19 +810,26 @@ sub do_slackbuild {
my $x32;
# ensure x32 stuff is set correctly, or that we're setup for it
if ($args{COMPAT32}) {
- die "compat32 requires multilib.\n" unless $multilib;
- die "compat32 requires /usr/sbin/convertpkg-compat32.\n"
- unless -f '/usr/sbin/convertpkg-compat32';
+ unless ($multilib) {
+ return "compat32 requires multilib.\n", (undef) x 2,
+ _ERR_NOMULTILIB;
+ }
+ unless (-f '/usr/sbin/convertpkg-compat32') {
+ return "compat32 requires /usr/sbin/convertpkg-compat32.\n",
+ (undef) x 2, _ERR_NOCONVERTPKG;
+ }
} else {
if ($arch eq 'x86_64') {
$x32 = check_x32 $args{LOCATION};
if ($x32 && ! $multilib) {
- die "$sbo is 32-bit which requires multilib on x86_64.\n";
+ my $warn =
+ "$sbo is 32-bit which requires multilib on x86_64.\n";
+ return $warn, (undef) x 2, _ERR_NOMULTILIB;
}
}
}
# setup and run the .SlackBuild itself
- my ($pkg, $src) = perform_sbo(
+ my ($pkg, $src, $exit) = perform_sbo(
OPTS => $args{OPTS},
JOBS => $args{JOBS},
LOCATION => $location,
@@ -773,7 +837,11 @@ sub do_slackbuild {
C32 => $args{COMPAT32},
X32 => $x32,
);
- $pkg = do_convertpkg $pkg if $args{COMPAT32};
+ return $pkg, (undef) x 2, $exit if $exit;
+ if ($args{COMPAT32}) {
+ ($pkg, $exit) = do_convertpkg $pkg;
+ return $pkg, (undef) x 2, $exit if $exit;
+ }
return $version, $pkg, $src;
}
@@ -814,8 +882,8 @@ sub make_distclean {
make_clean(SBO => $sbo, SRC => $args{SRC}, VERSION => $args{VERSION});
say "Distcleaning for $sbo-$args{VERSION}...";
# remove any distfiles for this particular SBo.
- my %downloads = get_sbo_downloads(LOCATION => $args{LOCATION});
- for my $key (keys %downloads) {
+ my $downloads = get_sbo_downloads(LOCATION => $args{LOCATION});
+ for my $key (keys %$downloads) {
my $filename = get_filename_from_link $key;
unlink $filename if -f $filename;
}
@@ -894,7 +962,8 @@ sub merge_queues {
sub get_readme_contents($) {
exists $_[0] or script_error 'get_readme_contents requires an argument.';
- my $fh = open_read(shift .'/README');
+ my ($fh, $exit) = open_read(shift .'/README');
+ return undef, $exit if $exit;
my $readme = do {local $/; <$fh>};
close $fh;
return $readme;
@@ -908,7 +977,8 @@ sub get_installed_cpans() {
}
my @contents;
for my $file (@locals) {
- my $fh = open_read $file;
+ my ($fh, $exit) = open_read $file;
+ return [] if $exit;
# push @contents, grep {/Module|VERSION/} <$fh>;
push @contents, grep {/Module/} <$fh>;
close $fh;
@@ -983,7 +1053,8 @@ sub ask_opts {
sub user_prompt {
exists $_[1] or script_error 'user_prompt requires two arguments.';
my ($sbo, $location) = @_;
- my $readme = get_readme_contents $location;
+ my ($readme, $exit) = get_readme_contents $location;
+ return $readme, undef, $exit if $exit;
# check for user/group add commands, offer to run any found
my $user_group = get_user_group $readme;
my $cmds;
@@ -1011,6 +1082,7 @@ sub process_sbos {
NOINSTALL => 0,
NOCLEAN => 'FALSE',
DISTCLEAN => 'FALSE',
+ NON_INT => 0,
@_
);
my $todo = $args{TODO};
@@ -1019,23 +1091,32 @@ sub process_sbos {
my $locs = $args{LOCATIONS};
my $jobs = $args{JOBS} =~ /^\d+$/ ? $args{JOBS} : 0;
exists $$todo[0] or script_error 'process_sbos requires TODO.';
- my (%failures, @symlinks, $temp_syms);
- for my $sbo (@$todo) {
+ my (@failures, @symlinks, $temp_syms, $exit);
+ FIRST: for my $sbo (@$todo) {
my $compat32 = $sbo =~ /-compat32$/ ? 1 : 0;
- eval { $temp_syms = check_distfiles(
+ ($temp_syms, $exit) = check_distfiles(
LOCATION => $$locs{$sbo}, COMPAT32 => $compat32
- ); };
- # if $@ is defined, $temp_syms will be empty and the script will error
- # instead of having a proper failure message.
- $@ ? $failures{$sbo} = $@ : push @symlinks, @$temp_syms;
- }
- # return now if we were unable to download/verify everything - might want
- # to not do this. not sure.
- if (keys %failures > 0) {
- unlink for @symlinks;
- return \%failures;
+ );
+ # if $exit is defined, prompt to proceed or return with last $exit
+ if ($exit) {
+ my $fail = $temp_syms;
+ push @failures, {$sbo => $fail};
+ # return now if we're not interactive
+ return \@failures, $exit if $args{NON_INT};
+ say "Unable to download/verify source file(s) for $sbo:";
+ say " $fail";
+ print 'Do you want to proceed? [n] ';
+ if (<STDIN> =~ /^[yY]/) {
+ next FIRST;
+ } else {
+ unlink for @symlinks;
+ return \@failures, $exit;
+ }
+ }
}
- for my $sbo (@$todo) {
+ my $count = 0 unless $args{NON_INT};
+ FIRST: for my $sbo (@$todo) {
+ $count++;
my $options = 0;
$options = $$opts{$sbo} if defined $$opts{$sbo};
my $cmds = $$cmds{$sbo} if defined $$cmds{$sbo};
@@ -1045,54 +1126,69 @@ sub process_sbos {
# switch compat32 on if upgrading/installing a -compat32
# else make sure compat32 is off
my $compat32 = $sbo =~ /-compat32$/ ? 1 : 0;
- my ($version, $pkg, $src);
- eval { ($version, $pkg, $src) = do_slackbuild(
+ my ($version, $pkg, $src, $exit) = do_slackbuild(
OPTS => $options,
JOBS => $jobs,
LOCATION => $$locs{$sbo},
COMPAT32 => $compat32,
- ); };
- if ($@) {
- $failures{$sbo} = $@;
- } else {
- do_upgradepkg $pkg unless $args{NOINSTALL};
-
- unless ($args{DISTCLEAN}) {
- make_clean(SBO => $sbo, SRC => $src, VERSION => $version)
- unless $args{NOCLEAN};
- } else {
- make_distclean(
- SBO => $sbo,
- SRC => $src,
- VERSION => $version,
- LOCATION => $$locs{$sbo},
- );
- }
- # move package to $config{PKG_DIR} if defined
- unless ($config{PKG_DIR} eq 'FALSE') {
- my $dir = $config{PKG_DIR};
- unless (-d $dir) {
- mkdir($dir) or warn "Unable to create $dir\n";
- }
- if (-d $dir) {
- move($pkg, $dir), say "$pkg stored in $dir";
- } else {
- warn "$pkg left in /tmp\n";
- }
- } elsif ($args{DISTCLEAN}) {
- unlink $pkg;
+ );
+ if ($exit) {
+ my $fail = $version;
+ push @failures, {$sbo => $fail};
+ # return now if we're not interactive
+ return \@failures, $exit if $args{NON_INT};
+ # or if this is the last $sbo
+ return \@failures, $exit if $count == @$todo;
+ say "Failure encountered while building $sbo:";
+ say " $fail";
+ print 'Do you want to proceed [n] ';
+ if (<STDIN> =~ /^[yY]/) {
+ next FIRST;
+ } else {
+ unlink for @symlinks;
+ return \@failures, $exit;
+ }
+ }
+
+ do_upgradepkg $pkg unless $args{NOINSTALL};
+
+ unless ($args{DISTCLEAN}) {
+ make_clean(SBO => $sbo, SRC => $src, VERSION => $version)
+ unless $args{NOCLEAN};
+ } else {
+ make_distclean(
+ SBO => $sbo,
+ SRC => $src,
+ VERSION => $version,
+ LOCATION => $$locs{$sbo},
+ );
+ }
+ # move package to $config{PKG_DIR} if defined
+ unless ($config{PKG_DIR} eq 'FALSE') {
+ my $dir = $config{PKG_DIR};
+ unless (-d $dir) {
+ mkdir($dir) or warn "Unable to create $dir\n";
}
+ if (-d $dir) {
+ move($pkg, $dir), say "$pkg stored in $dir";
+ } else {
+ warn "$pkg left in /tmp\n";
+ }
+ } elsif ($args{DISTCLEAN}) {
+ unlink $pkg;
}
}
unlink for @symlinks;
- return \%failures;
+ return \@failures, $exit;
}
# subroutine to print out failures
sub print_failures {
my $failures = shift;
- if (keys %$failures > 0) {
- say 'Failures:';
- say " $_: $$failures{$_}" for keys %$failures;
+ if (@$failures > 0) {
+ warn "Failures:\n";
+ for my $failure (@$failures) {
+ warn " $_: $$failure{$_}" for keys %$failure;
+ }
}
}
diff --git a/man1/sboclean.1 b/man1/sboclean.1
index a16ca92..6e9e38e 100644
--- a/man1/sboclean.1
+++ b/man1/sboclean.1
@@ -33,6 +33,17 @@ Clean working directories, located under /tmp/SBo.
-i|--interactive
.RS
Be interactive; sboclean will ask for confirmation for each item which it thinks should be removed.
+.SH EXIT CODES
+.P
+sboclean can exit with the following codes:
+.RS
+
+0: all operations completed successfully.
+.RE
+.RS
+1: a usage error occurred, such as running sboclean with nothing to clean.
+.RE
+
.SH BUGS
.P
None known, but there may be some. Please report any found to j@dawnrazor.net or xocel@iquidus.org; patches are always welcome.
diff --git a/man1/sboconfig.1 b/man1/sboconfig.1
index 5bca292..3c5792b 100644
--- a/man1/sboconfig.1
+++ b/man1/sboconfig.1
@@ -29,7 +29,6 @@ List out current configuration options, including unmodified default configurati
.RS
NOCLEAN: If TRUE, then DO NOT clean working directories after building the slackbuild. These are the directories where the source is unpacked and compiled, and where the package is put together in, which are under /tmp/SBo. By default, these directories are removed after building an slackbuild. Setting this option to TRUE causes the working directories to not be cleaned by default. This can be overridden when running sboupgrade(1)/sboinstall(1).
.RE
-
.P
-d|--distclean (FALSE|TRUE)
.RS
@@ -50,6 +49,19 @@ PKG_DIR: If set to a path, packages will be stored at the given location after b
.RS
SBO_HOME: If set to a path, this is where the slackbuilds.org tree will live; by default, /usr/sbo will be used. If the tree should live elsewhere, this option can be set to the path where the tree should live. Note that if you set this option after fetching the tree to a different location (such as the default), you will need to fetch the tree again.
.RE
+.SH EXIT CODES
+.P
+sboconfig can exit with the following codes:
+.RS
+
+0: all operations were succesful.
+.RE
+.RS
+1: a usage error occurred, such as trying to specify invalid options.
+.RE
+.RS
+6: sboconfig was unable to obtain a required file handle.
+.RE
.SH BUGS
.P
None known, but there may be some. Please report any found to j@dawnrazor.net or xocel@iquidus.org; patches are always welcome.
diff --git a/man1/sbofind.1 b/man1/sbofind.1
index 60148c8..0ad3e25 100644
--- a/man1/sbofind.1
+++ b/man1/sbofind.1
@@ -29,6 +29,19 @@ Show the contents of the .info file for each slackbuild found.
.RS
Show the contents of the README file for each slackbuild found.
.RE
+.SH EXIT CODES
+.P
+sbofind can exit with the following exit codes:
+.RS
+
+0: all operations were succesful.
+.RE
+.RS
+1: a usage error occured, ie sbofind was ran with nothing to find.
+.RE
+.RS
+6: sbofind was unable to obtain a required file handle.
+.RE
.SH BUGS
.P
None known, but there may be some. Please report any found to j@dawnrazor.net or xocel@iquidus.org; patches are always welcome.
diff --git a/man1/sboinstall.1 b/man1/sboinstall.1
index 819f9bc..e4969d0 100644
--- a/man1/sboinstall.1
+++ b/man1/sboinstall.1
@@ -54,6 +54,43 @@ Skip viewing of the README and the yes or no question which accompanies it. Anyt
.RS
This option causes sboinstall to skip requirement handling, but still show the README and prompt the user to proceed.
.RE
+.SH EXIT CODES
+.P
+sboinstall can exit with the following exit codes:
+.RS
+
+0: all operations were succesful.
+.RE
+.RS
+1: a usage error occured, such as specifying invalid options.
+.RE
+.RS
+3: a .SlackBuild exited non-zero.
+.RE
+.RS
+4: unable to md5sum verify an SBo's source file(s).
+.RE
+.RS
+5: unable to download an SBo's source file(s).
+.RE
+.RS
+6: unable to obtain a required file handle.
+.RE
+.RS
+7: unable to get required info from the SBo's .info file.
+.RE
+.RS
+8: unable to unset the exec-on-close bit on a temporary file.
+.RE
+.RS
+9: multilib hasn't been setup (where required).
+.RE
+.RS
+10: convertpkg-compat32 exited non-zero.
+.RE
+.RS
+11: the convertpkg-compat32 script can't be found (where required).
+.RE
.SH BUGS
.P
None known, but there may be some. Please report any found to j@dawnrazor.net or xocel@iquidus.org; patches are always welcome.
diff --git a/man1/sboremove.1 b/man1/sboremove.1
index 9b5779a..4dc81b9 100644
--- a/man1/sboremove.1
+++ b/man1/sboremove.1
@@ -24,6 +24,16 @@ Show version information.
.RS
Always ask to remove requirements, even those required by other packages currently installed (ignored by default)
.RE
+.SH EXIT CODES
+.P
+sboremove can exit with the following codes:
+.RS
+
+0: all operations completed successfully.
+.RE
+.RS
+1: a usage error occurred, such as running sboremove with nothing to remove.
+.RE
.SH BUGS
.P
None known, but there may be some. Please report any found to xocel@iquidus.org or j@dawnrazor.net; patches are always welcome.
diff --git a/man1/sbosnap.1 b/man1/sbosnap.1
index 0f6fef9..5ddc698 100644
--- a/man1/sbosnap.1
+++ b/man1/sbosnap.1
@@ -30,6 +30,16 @@ update
.RS
Update a previously fetch'd copy of the slackbuilds.org tree.
.RE
+.SH EXIT CODES
+.P
+sbosnap can exit with the following codes:
+.RS
+
+0: all operations completed successfully.
+.RE
+.RS
+1: a usage error occurred, such as running sbosnap with no command.
+.RE
.SH BUGS
.P
None known, but there may be some. Please report any found to j@dawnrazor.net or xocel@iquidus.org; patches are always welcome.
diff --git a/man1/sboupgrade.1 b/man1/sboupgrade.1
index 4dfeeb0..7a6f4cc 100644
--- a/man1/sboupgrade.1
+++ b/man1/sboupgrade.1
@@ -54,6 +54,43 @@ Skip viewing of the README and the yes or no question which accompanies it. Anyt
.RS
When used in combination with the -f option, to force an update even if it would not constitute an update, this will cause sboupgrade to also rebuild all of that slackbuild's requirements. Normally with -f, only the slackbuild(s) specified, and any requirements not already installed, will be rebuilt. This allows for recursive upgrades, among other things.
.RE
+.SH EXIT CODES
+.P
+sboinstall can exit with the following exit codes:
+.RS
+
+0: all operations were succesful.
+.RE
+.RS
+1: a usage error occured, such as specifying invalid options.
+.RE
+.RS
+3: a .SlackBuild exited non-zero.
+.RE
+.RS
+4: unable to md5sum verify an SBo's source file(s).
+.RE
+.RS
+5: unable to download an SBo's source file(s).
+.RE
+.RS
+6: unable to obtain a required file handle.
+.RE
+.RS
+7: unable to get required info from the SBo's .info file.
+.RE
+.RS
+8: unable to unset the exec-on-close bit on a temporary file.
+.RE
+.RS
+9: multilib hasn't been setup (where required).
+.RE
+.RS
+10: convertpkg-compat32 exited non-zero.
+.RE
+.RS
+11: the convertpkg-compat32 script can't be found (where required).
+.RE
.SH BUGS
.P
None known, but there may be some. Please report any found to j@dawnrazor.net or xocel@iquidus.org; patches are always welcome.
diff --git a/sbocheck b/sbocheck
index 5b36f57..2279717 100755
--- a/sbocheck
+++ b/sbocheck
@@ -85,10 +85,15 @@ sub print_output($) {
# save a log of available updates
my $logfile = '/var/log/sbocheck.log';
unlink $logfile if -f $logfile;
- my $log_fh = open_fh($logfile, '>');
- say {$log_fh} $_ for @$listing;
- close $log_fh;
- say "A copy of the above result is kept in $logfile\n";
+ my ($log_fh, $exit) = open_fh($logfile, '>');
+ # non-fatal
+ if ($exit) {
+ warn $log_fh if $exit;
+ } else {
+ say {$log_fh} $_ for @$listing;
+ close $log_fh;
+ say "A copy of the above result is kept in $logfile\n";
+ }
} else {
say "\nNo updates available.";
}
diff --git a/sboclean b/sboclean
index 9ed15f6..3835de7 100755
--- a/sboclean
+++ b/sboclean
@@ -51,7 +51,7 @@ GetOptions(
show_usage and exit 0 if $help;
show_version and exit 0 if $vers;
-show_usage, die "You must specify at least one of -d or -w.\n" unless
+usage_error "You must specify at least one of -d or -w." unless
($clean_dist || $clean_work);
sub remove_stuff($) {
diff --git a/sboconfig b/sboconfig
index 92dab3f..c210a8a 100755
--- a/sboconfig
+++ b/sboconfig
@@ -83,22 +83,22 @@ while (my ($key, $value) = each %valid_confs) {
$changes{$value} = $options{$key} if exists $options{$key};
}
-my $die = 'You have provided an invalid parameter for';
+my $warn = 'You have provided an invalid parameter for';
if (exists $changes{NOCLEAN}) {
- die "$die -c\n" unless $changes{NOCLEAN} =~ /^(TRUE|FALSE)$/;
+ usage_error "$warn -c" unless $changes{NOCLEAN} =~ /^(TRUE|FALSE)$/;
}
if (exists $changes{DISTCLEAN}) {
- die "$die -d\n" unless $changes{DISTCLEAN} =~ /^(TRUE|FALSE)$/;
+ usage_error "$warn -d" unless $changes{DISTCLEAN} =~ /^(TRUE|FALSE)$/;
}
if (exists $changes{JOBS}) {
- die "$die -j\n" unless $changes{JOBS} =~ /^(\d+|FALSE)$/;
+ usage_error "$warn -j" unless $changes{JOBS} =~ /^(\d+|FALSE)$/;
}
if (exists $changes{PKG_DIR}) {
- die "$die -p\n" unless $changes{PKG_DIR} =~ qr#^(/|FALSE$)#;
+ usage_error "$warn -p" unless $changes{PKG_DIR} =~ qr#^(/|FALSE$)#;
}
if (exists $changes{SBO_HOME}) {
- die "$die -s\n" unless $changes{SBO_HOME} =~ qr#^/#;
+ usage_error "$warn -s" unless $changes{SBO_HOME} =~ qr#^/#;
}
# safely modify our conf file; write its contents to a temp file, modify the
@@ -110,11 +110,15 @@ sub config_write {
exists $_[1] or script_error 'config_write requires two arguments.';
my ($key, $val) = @_;
if (! -d $conf_dir) {
- mkdir $conf_dir or die "Unable to create $conf_dir. Exiting.\n";
+ mkdir $conf_dir or usage_error "Unable to create $conf_dir. Exiting.";
}
if (-f $conf_file) {
my $tempfh = tempfile(DIR => $tempdir);
- my $conffh = open_read $conf_file;
+ my ($conffh, $exit) = open_read $conf_file;
+ if ($exit) {
+ warn $conffh;
+ exit $exit;
+ }
my $conftents = do {local $/; <$conffh>};
print {$tempfh} $conftents;
# tie the temp file so that if $key is already there, we just change
@@ -132,13 +136,20 @@ sub config_write {
seek $tempfh, 0, 0;
my $contents = do {local $/; <$tempfh>};
close $conffh;
- eval { $conffh = open_fh($conf_file, '>') };
- warn "Cannot write configuration: $@\n" and return if $@;
+ ($conffh, $exit) = open_fh($conf_file, '>');
+ if ($exit) {
+ warn $conffh;
+ exit $exit;
+ }
print {$conffh} $contents or return;
close $conffh, close $tempfh;
} else {
# no config file, easiest case of all.
- my $fh = open_fh($conf_file, '>') or return;
+ my ($fh, $exit) = open_fh($conf_file, '>') or return;
+ if ($exit) {
+ warn $fh;
+ exit $exit;
+ }
print {$fh} "$key=$val\n";
close $fh;
}
@@ -147,7 +158,7 @@ sub config_write {
while (my ($key, $value) = each %changes) {
say "Setting $key to $value...";
- config_write($key, $value) or warn "Unable to write to $conf_file\n";
+ config_write($key, $value);
}
exit 0;
diff --git a/sbofind b/sbofind
index 93e7e36..807f733 100755
--- a/sbofind
+++ b/sbofind
@@ -66,7 +66,11 @@ sub perform_search($) {
my (@findings, $name, $found);
my $name_regex = qr/NAME:\s+(.*\Q$search\E.*)$/i;
my $loc_regex = qr/LOCATION:\s+(.*)$/;
- my $fh = open_read "$config{SBO_HOME}/SLACKBUILDS.TXT";
+ my ($fh, $exit) = open_read "$config{SBO_HOME}/SLACKBUILDS.TXT";
+ if ($exit) {
+ warn $fh;
+ exit $exit;
+ }
FIRST: while (my $line = <$fh>) {
unless ($found) {
$found++, next FIRST if $name = ($line =~ $name_regex)[0];
@@ -85,7 +89,11 @@ sub perform_search($) {
sub get_file_contents($) {
exists $_[0] or script_error 'get_file_contents requires an argument';
-f $_[0] or return "$_[0] doesn't exist.\n";
- my $fh = open_read shift;
+ my ($fh, $exit) = open_read shift;
+ if ($exit) {
+ warn $fh;
+ return;
+ }
my $contents = do {local $/; <$fh>};
for ($contents) {
s/\n/\n /g;
diff --git a/sboinstall b/sboinstall
index 56e682e..6bff012 100755
--- a/sboinstall
+++ b/sboinstall
@@ -64,7 +64,7 @@ GetOptions(
show_usage and exit 0 if $help;
show_version and exit 0 if $vers;
-show_usage and exit 0 unless exists $ARGV[0];
+show_usage and exit 1 unless exists $ARGV[0];
$noclean = $noclean eq 'TRUE' ? 1 : 0;
$distclean = $distclean eq 'TRUE' ? 1 : 0;
@@ -130,7 +130,11 @@ FIRST: for my $sbo (@$build_queue) {
if ($compat32) {
unless ($sbo ~~ @$inst_names) {
say "$name requires $sbo.";
- my ($cmds, $opts) = user_prompt($sbo, $locations{$sbo});
+ my ($cmds, $opts, $exit) = user_prompt($sbo, $locations{$sbo});
+ if ($exit) {
+ warn "Unable to open README for $sbo.\n";
+ exit $exit;
+ }
if ($cmds) {
next FIRST if $cmds eq 'N';
}
@@ -140,7 +144,11 @@ FIRST: for my $sbo (@$build_queue) {
say "$sbo$added";
}
}
- my ($cmds, $opts) = user_prompt($name, $locations{$name});
+ my ($cmds, $opts, $exit) = user_prompt($name, $locations{$name});
+ if ($exit) {
+ warn "Unable to open README for $name.\n";
+ exit $exit;
+ }
if ($cmds) {
next FIRST if $cmds eq 'N';
}
@@ -162,7 +170,7 @@ unless ($non_int) {
exit 0 unless <STDIN> =~ /^[Yy\n]/;
}
-my $failures = process_sbos(
+my ($failures, $exit) = process_sbos(
TODO => $build_queue,
CMDS => \%commands,
OPTS => \%options,
@@ -171,7 +179,12 @@ my $failures = process_sbos(
NOINSTALL => $no_install,
NOCLEAN => $noclean,
DISTCLEAN => $distclean,
+ NON_INT => $non_int,
);
print_failures($failures);
-exit keys %$failures > 0 ? 1 : 0;
+if ($exit) {
+ exit $exit;
+} else {
+ exit 0;
+}
diff --git a/sboremove b/sboremove
index 7479f29..0aa0fb8 100755
--- a/sboremove
+++ b/sboremove
@@ -46,7 +46,7 @@ GetOptions(
show_usage and exit 0 if $help;
show_version and exit 0 if $vers;
-show_usage and exit 0 unless exists $ARGV[0];
+show_usage and exit 1 unless exists $ARGV[0];
# ensure that all provided arguments are valid sbos
my @sbos;
@@ -59,15 +59,7 @@ for my $sbo (@ARGV) {
say "Unable to locate $sbo in the SlackBuilds.org tree."
}
}
-exit 0 unless exists $sbos[0];
-
-# # wrapper to pull the list of requirements for a given sbo
-# sub get_requires ($) {
-# my $location = get_sbo_location(shift);
-# return unless $location;
-# my $info = get_from_info(LOCATION => $location, GET => 'REQUIRES');
-# return $$info[0] ne '' ? $info : undef;
-# }
+exit 1 unless exists $sbos[0];
# Create full queue.
my ($remove_queue, %warnings);
@@ -156,8 +148,14 @@ FIRST: for my $remove (@$remove_queue) {
if ( "%README%" ~~ @reqz ) {
say "It is recommended that you view the README before continuing.";
print "Display README now? [y]: ";
- my $readme = get_readme_contents get_sbo_location($remove);
- print "\n" . $readme if <STDIN> =~ /^[Yy\n]/;
+ if (<STDIN> =~ /^[Yy\n]/) {
+ my ($readme, $exit) = get_readme_contents get_sbo_location($remove);
+ if ($exit) {
+ warn "Unable to open README for $remove.\n";
+ } else {
+ print "\n" . $readme;
+ }
+ }
}
# Determine default behavior for prompt
diff --git a/sboupgrade b/sboupgrade
index b38b456..8c5b283 100755
--- a/sboupgrade
+++ b/sboupgrade
@@ -192,7 +192,11 @@ unless ($force) {
my (@temp_queue, %commands, %options);
FIRST: for my $sbo (@$upgrade_queue) {
unless ($non_int) {
- my ($cmds, $opts) = user_prompt($sbo, $locations{$sbo});
+ my ($cmds, $opts, $exit) = user_prompt($sbo, $locations{$sbo});
+ if ($exit) {
+ warn "Unable to open README for $sbo.\n";
+ exit $exit;
+ }
if ($cmds) {
next FIRST if $cmds eq 'N';
}
@@ -213,7 +217,7 @@ unless ($non_int) {
exit 0 unless <STDIN> =~ /^[Yy\n]/;
}
-my $failures = process_sbos(
+my ($failures, $exit) = process_sbos(
TODO => $upgrade_queue,
CMDS => \%commands,
OPTS => \%options,
@@ -222,7 +226,12 @@ my $failures = process_sbos(
NOINSTALL => $no_install,
NOCLEAN => $noclean,
DISTCLEAN => $distclean,
+ NON_INT => $non_int,
);
print_failures($failures);
-exit keys %$failures > 0 ? 1 : 0;
+if ($exit) {
+ exit $exit;
+} else {
+ exit 0;
+}
diff --git a/t/prep.pl b/t/prep.pl
index c8d38bd..b7dc111 100755
--- a/t/prep.pl
+++ b/t/prep.pl
@@ -69,15 +69,15 @@ while (my $line = <$file_h>) {
}
seek $file_h, 0, 0;
-my @not_exported;
-FIRST: for my $sub (@subs) {
- my $found = 'FALSE';
- my $has = 'FALSE';
+my @not_exported;
+FIRST: for my $sub (@subs) {
+ my $found = 'FALSE';
+ my $has = 'FALSE';
SECOND: while (my $line = <$file_h>) {
- if ($found eq 'FALSE') {
+ if ($found eq 'FALSE') {
$found = 'TRUE', next SECOND if $line =~ /\@EXPORT/;
- } else {
- last SECOND if $line =~ /^\);$/;
+ } else {
+ last SECOND if $line =~ /^\);$/;
$has = 'TRUE', last SECOND if $line =~ /$sub/;
}
}
@@ -91,7 +91,20 @@ FIRST: for my $line (@file) {
if ($line =~ /\@EXPORT/) {
$line = "our \@EXPORT = qw(". join ' ', @not_exported;
}
- $line = "#$line" if $line =~ /root privileges/;
+ $line =~ s/^/#/ if $line =~ /^read_config;$/;
}
-
+my $found = 0;
+FIRST: for my $line (@file) {
+ unless ($found) {
+ if ($line =~ /^unless\s+\(\$<\s+==/) {
+ $found++;
+ $line =~ s/^/#/;
+ }
+ } else {
+ $line =~ s/^/#/;
+ if ($line =~ /^#}$/) {
+ last FIRST;
+ }
+ }
+}
diff --git a/t/test.t b/t/test.t
index b8bb7fc..3b0b799 100755
--- a/t/test.t
+++ b/t/test.t
@@ -14,6 +14,7 @@ chomp(my $pwd = `pwd`);
my $sbo_home = "$pwd/sbo";
$conf_file = "$pwd/sbotools.conf";
+$SBO::Lib::conf_file = $conf_file;
read_config;
$config{SBO_HOME} = $sbo_home;
$SBO::Lib::distfiles = "$sbo_home/distfiles";
@@ -47,9 +48,6 @@ is(chk_slackbuilds_txt, undef,
'chk_slackbuilds_txt returns false with no SLACKBUILDS.TXT');
move("$sbo_home/SLACKBUILDS.TXT.moved", "$sbo_home/SLACKBUILDS.TXT");
-#ok (rsync_sbo_tree == 1, 'rsync_sbo_tree is good');
-#ok (update_tree == 1, 'update_tree is good');
-
# slackbuilds_or_fetch test
is(slackbuilds_or_fetch, 1, 'slackbuilds_or_fetch is good');
@@ -246,9 +244,9 @@ ok(! get_sbo_from_loc('omg_wtf_bbq'),
# get_distfile tests
my $distfile = "$sbo_home/distfiles/Sort-Versions-1.5.tar.gz";
unlink $distfile if -f $distfile;
-is(get_distfile
- ('http://search.cpan.org/CPAN/authors/id/E/ED/EDAVIS/Sort-Versions-1.5.tar.gz',
- '5434f948fdea6406851c77bebbd0ed19'), 1, 'get_distfile is good');
+is(get_distfile(
+ 'http://search.cpan.org/CPAN/authors/id/E/ED/EDAVIS/Sort-Versions-1.5.tar.gz',
+ '5434f948fdea6406851c77bebbd0ed19'), 1, 'get_distfile test 01');
unlink $distfile;
# rewrite_slackbuild/revert_slackbuild tests
@@ -312,13 +310,6 @@ for my $item (@$listing) {
# remove_stuff test - can only really test for invalid input
is(remove_stuff('/omg/wtf/bbq'), 1, 'remove_stuff good for invalid input');
-# config_write test
-chmod 0444, $conf_file;
-is(config_write ('OMG', 'WTF'), undef,
- 'config_write returned undef correctly');
-chmod
-chmod 0644, $conf_file;
-
# perform_search tests
my $findings = perform_search('desktop');
for my $found (@$findings) {
@@ -385,17 +376,6 @@ $readme = do {local $/; <$fh>};
close $fh;
ok(! (get_opts $readme), 'get_opts good where README does not define opts');
-# clean_reqs tests
-
-# $SBO::Lib::compat32 = 0;
-# $reqs = get_requires "zdoom", "$sbo_home/games/zdoom";
-# $reqs = clean_reqs $reqs;
-# ok (! $$reqs[0], 'clean_reqs good for already installed reqs');
-# $reqs = get_requires 'gmpc', "$sbo_home/audio/gmpc";
-# $reqs = clean_reqs $reqs;
-# is ($$reqs[0], 'gob2', 'clean_reqs good for un/installed reqs.');
-# is ($$reqs[1], 'libmpd', 'clean_reqs good for un/installed reqs.');
-
# queue tests
# test multiple sbo's
diff --git a/tools/masstest_sbo.sh b/tools/masstest_sbo.sh
index 478a848..06d6609 100755
--- a/tools/masstest_sbo.sh
+++ b/tools/masstest_sbo.sh
@@ -2,16 +2,16 @@
# set DISTCLEAN TRUE to preserve space
sboconfig -d TRUE
+# clear out work directories and distfiles
+sboclean -dw
SBOS=$(find /usr/sbo -type f -iname \*.info | sed -r 's|.*/([^/]+)\.info$|\1|g');
TLOG=~/tmp.log
-FLOG=~/fail.log
ILOG=~/install.log
RLOG=~/remove.log
# zero out logs in case they have content from previous run
-:> $FLOG
:> $ILOG
:> $RLOG
@@ -24,11 +24,21 @@ function build_things() {
fi
done
echo "=============" > $TLOG
- echo "sboupgrade -oNr $1" >> $TLOG
- sboupgrade -oNr $i >> $TLOG 2>&1
- if [[ $? != "0" ]]; then
- echo "" >> $FLOG
- cat $TLOG >> $FLOG
+ echo "sboinstall -r $1" >> $TLOG
+ sboinstall -r $1 >> $TLOG 2>&1
+ case "$?" in
+ "0") OLOG="" ;;
+ "3") OLOG=~/build.fail.log ;;
+ "4") OLOG=~/md5sum.fail.log ;;
+ "5") OLOG=~/wget.fail.log ;;
+ "7") OLOG=~/noinfo.fail.log ;;
+ "9") OLOG=~/nomulti.fail.log ;;
+ esac
+ if [[ "$OLOG" != "" ]]; then
+ if ! grep -q "^$1 added to build queue.$" $OLOG; then
+ echo "" >> $OLOG
+ cat $TLOG >> $OLOG
+ fi
fi
echo "" >> $ILOG
cat $TLOG >> $ILOG
@@ -44,10 +54,6 @@ function remove_things() {
echo "=============" > $TLOG
echo "sboremove --nointeractive $1" >> $TLOG
sboremove --nointeractive $1 >> $TLOG 2>&1
- if [[ $? != 0 ]]; then
- echo "" >> $FLOG
- cat $TLOG >> $FLOG
- fi
echo "" >> $RLOG
cat $TLOG >> $RLOG
:> $TLOG