aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Pipkin <j@dawnrazor.net>2012-08-31 15:53:21 -0500
committerJacob Pipkin <j@dawnrazor.net>2012-08-31 15:53:21 -0500
commitd55dbdf17977ed9b1dfd91c98a4a569960b851cd (patch)
tree8e6a860de9fe0e8f5e52bc71716f6b4d69241c6d
parent12a1c8c4530ddb9ab83fec1f9b5bf61a25764e6b (diff)
downloadsbotools2-d55dbdf17977ed9b1dfd91c98a4a569960b851cd.tar.xz
epic changes and fixes and much further testing
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm11
-rwxr-xr-xsbocheck43
-rwxr-xr-xsboclean2
-rwxr-xr-xsboconfig9
-rwxr-xr-xsbofind33
-rwxr-xr-xsboupgrade87
-rw-r--r--t/SBO/Lib.pm~643
-rwxr-xr-xt/prep.pl44
-rwxr-xr-xt/test.t73
9 files changed, 227 insertions, 718 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index 886c19c..94ce3be 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -464,9 +464,7 @@ sub check_distfiles (%) {
my %dists = @_;
for my $link (keys %dists) {
my $md5sum = $dists{$link};
- unless (verify_distfile $link, $md5sum) {
- die unless get_distfile $link, $md5sum;
- }
+ get_distfile $link, $md5sum unless verify_distfile $link, $md5sum;
}
return 1;
}
@@ -561,7 +559,7 @@ sub perform_sbo (%) {
my $location = $args{LOCATION};
my $sbo = get_sbo_from_loc $location;
my ($cmd, %changes);
- # figure out any changes we need to make to the .SlackBuild
+ # set any changes we need to make to the .SlackBuild, setup the command
$changes{make} = "-j $args{JOBS}" if $args{JOBS};
if ($args{ARCH} eq 'x86_64' and ($args{C32} || $args{X32})) {
if ($args{C32}) {
@@ -578,7 +576,7 @@ sub perform_sbo (%) {
rewrite_slackbuild "$location/$sbo.SlackBuild", $fn, %changes;
chdir $location, my $out = system $cmd;
revert_slackbuild "$location/$sbo.SlackBuild";
- die unless $out == 0;
+ die "$sbo.SlackBuild returned non-zero ext status\n" unless $out == 0;
my $pkg = get_pkg_name $tempfh;
my $src = get_src_dir $tempfh;
return $pkg, $src;
@@ -591,7 +589,8 @@ 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;
+ system ($cmd) == 0 or
+ die "convertpkg-compt32 returned non-zero exit status\n";
unlink $pkg;
return get_pkg_name $tempfh;
}
diff --git a/sbocheck b/sbocheck
index 9d228a6..d2e6f91 100755
--- a/sbocheck
+++ b/sbocheck
@@ -27,24 +27,35 @@ show_version && exit 0 if (exists $options{v});
update_tree;
-print "Checking for updated SlackBuilds...\n";
-my $updates = get_available_updates;
-
-# pretty formatting.
-my @listing;
-for my $key (keys @$updates) {
- my $string = "$$updates[$key]{name}-$$updates[$key]{installed}";
- $string .= " < needs updating (SBo has $$updates[$key]{update})\n";
- push @listing, $string;
+# retrieve and format list of available updates
+sub get_update_list () {
+ print "Checking for updated SlackBuilds...\n";
+ my $updates = get_available_updates;
+ # pretty formatting.
+ my @listing;
+ for my $update (@$updates) {
+ my $string = "$$update{name}-$$update{installed}";
+ $string .= " < needs updating (SBo has $$update{update})\n";
+ push @listing, $string;
+ }
+ return \@listing;
}
-if (exists $listing[0]) {
- my $tab = new Text::Tabulate ();
- $tab->configure (tab => '\s');
- my $output = $tab->format (@listing);
- say "\n". $output;
-} else {
- say "\nNo updates available.";
+# Text::Tabulate and print list of updates
+sub print_output ($) {
+ exists $_[0] or script_error 'print_output requires an argument';
+ my $listing = shift;
+ if (exists $$listing[0]) {
+ my $tab = new Text::Tabulate ();
+ $tab->configure (tab => '\s');
+ my $output = $tab->format (@$listing);
+ say "\n". $output;
+ } else {
+ say "\nNo updates available.";
+ }
}
+my $output = get_update_list;
+print_output $output;
+
exit 0;
diff --git a/sboclean b/sboclean
index fd6f5c8..558272b 100755
--- a/sboclean
+++ b/sboclean
@@ -49,7 +49,7 @@ unless ($clean_dist || $clean_work) {
sub remove_stuff ($) {
exists $_[0] or script_error 'remove_stuff requires an argument';
- -d $[0] or say "Nothing to do." and return 1;
+ -d $_[0] or say "Nothing to do." and return 1;
my $dir = shift;
opendir (my $dh, $dir);
FIRST: while (my $ls = readdir $dh) {
diff --git a/sboconfig b/sboconfig
index 9c2682f..2065a27 100755
--- a/sboconfig
+++ b/sboconfig
@@ -98,7 +98,7 @@ sub config_write ($$) {
# tie the file so that if $key is already there, we just change that
# line and untie it
tie my @temp, 'Tie::File', $tempfn;
- my $has = 0;
+ my $has;
my $regex = qr/\A\Q$key\E=/;
FIRST: for my $tmpline (@temp) {
$has++, $tmpline = "$key=$val", last FIRST if $tmpline =~ $regex;
@@ -110,18 +110,19 @@ sub config_write ($$) {
print {$fh} "$key=$val\n";
close $fh;
}
- move ($tempfn, $conf_file);
+ move ($tempfn, $conf_file) || return;
} else {
# no config file, easiest case of all.
- my $fh = open_fh $conf_file, '>';
+ my $fh = open_fh $conf_file, '>' || return;
say {$fh} "$key=$val";
close $fh;
}
+ return 1;
}
while (my ($key, $value) = each %changes) {
print "Setting $key to $value...\n";
- config_write $key, $value;
+ config_write $key, $value or warn "Unable to write to $conf_file\n";
}
exit 0;
diff --git a/sbofind b/sbofind
index e00f8de..16ad1b1 100755
--- a/sbofind
+++ b/sbofind
@@ -51,23 +51,28 @@ my $search = $ARGV[0];
slackbuilds_or_fetch;
# find anything with $search in its name
-my ($findings, $name);
-my $found = 0;
-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";
-FIRST: while (my $line = <$fh>) {
- unless ($found) {
- $found++, next FIRST if $name = ($line =~ $name_regex)[0];
- } else {
- if (my ($location) = ($line =~ $loc_regex)[0]) {
- $found = 0;
- $location =~ s#^\.##;
- push @$findings, {$name => $config{SBO_HOME} . $location};
+sub perform_search ($) {
+ exists $_[0] or script_error 'perform_search requires an argument.';
+ my $search = shift;
+ 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";
+ FIRST: while (my $line = <$fh>) {
+ unless ($found) {
+ $found++, next FIRST if $name = ($line =~ $name_regex)[0];
+ } else {
+ if (my ($location) = ($line =~ $loc_regex)[0]) {
+ $found = 0;
+ $location =~ s#^\.##;
+ push @findings, {$name => $config{SBO_HOME} . $location};
+ }
}
}
+ return \@findings;
}
+# pull the contents of a file into a variable and format it for output
sub get_file_contents ($) {
exists $_[0] or script_error 'get_file_contents requires an argument';
-f $_[0] or return "$_[0] doesn't exist.\n";
@@ -78,6 +83,8 @@ sub get_file_contents ($) {
return $contents;
}
+perform_search $search;
+
# pretty formatting
if (exists $$findings[0]) {
my @listing = ("\n");
diff --git a/sboupgrade b/sboupgrade
index cdc2ca2..6633834 100755
--- a/sboupgrade
+++ b/sboupgrade
@@ -95,10 +95,10 @@ sub get_inst_names ($) {
return \@installed;
}
-# pull list of requirements, offer to install them
-sub grok_requirements ($$$) {
- exists $_[1] or script_error 'grok_requirements requires an argument.';
- my ($sbo, $location, $readme) = @_;
+# pull list of requirements
+sub get_requires ($$) {
+ exists $_[1] or script_error 'get_requires requires an argument.';
+ my ($sbo, $location) = @_;
my $requires = get_from_info (LOCATION => $location, GET => 'REQUIRES');
return unless $$requires[0];
# do nothing if a req list contains %README%
@@ -109,7 +109,13 @@ sub grok_requirements ($$$) {
GET => 'REQUIRES');
return if $sbo ~~ @$req_req;
}
- # else proceed
+ return $requires;
+}
+
+# ask to install any requirements found
+sub ask_requires ($$$) {
+ exists $_[2] or script_error 'ask_requires requires three arguments.';
+ my ($requires, $readme, $sbo) = shift;
for my $req (@$requires) {
my $inst = get_installed_sbos;
my $inst_names= get_inst_names $inst;
@@ -123,36 +129,43 @@ sub grok_requirements ($$$) {
}
}
}
- return;
}
# look for any (user|group)add commands in the README
-sub grok_user_group ($) {
+sub get_user_group ($) {
exists $_[0] or script_error 'grok_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 ($) {
+sub get_opts ($) {
exists $_[0] or script_error 'grok_options requires an argument';
my $readme = shift;
- return unless $readme =~ /[A-Z]+=[^\s]/;
+ 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;
say "\n". $readme;
print "\nIt looks this slackbuilds has options; would you like to set any";
print " when the slackbuild is run? [n] ";
@@ -181,10 +194,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, $location, $readme;
- grok_user_group $readme;
- my $opts = grok_options $readme;
+ # check for requirements, offer to install any found
+ my $requires = get_requires $sbo, $location;
+ 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;
@@ -197,7 +215,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, $locations{$sbo} unless $no_readme;
@@ -211,7 +229,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';
@@ -240,13 +258,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;
}
}
@@ -274,8 +295,8 @@ 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;
@@ -302,7 +323,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;
diff --git a/t/SBO/Lib.pm~ b/t/SBO/Lib.pm~
deleted file mode 100644
index be29986..0000000
--- a/t/SBO/Lib.pm~
+++ /dev/null
@@ -1,643 +0,0 @@
-#!/usr/bin/env perl
-#
-# vim: set ts=4:noet
-#
-# Lib.pm
-# shared functions for the sbo_ scripts.
-#
-# author: Jacob Pipkin <j@dawnrazor.net>
-# date: Setting Orange, the 37th day of Discord in the YOLD 3178
-# license: WTFPL <http://sam.zoy.org/wtfpl/COPYING>
-
-use 5.16.0;
-use warnings FATAL => 'all';
-use strict;
-
-package SBO::Lib 1.0;
-my $version = "1.0";
-
-require Exporter;
-our @ISA = qw(Exporter);
-our @EXPORT = qw(get_slack_version chk_slackbuilds_txt check_home rsync_sbo_tree get_sbo_from_loc get_sbo_version get_download_info get_arch get_sbo_downloads get_filename_from_link compute_md5sum compare_md5s check_distfile get_distfile get_symlink_from_filename check_x32 check_multilib rewrite_slackbuild revert_slackbuild create_symlinks grok_temp_file get_src_dir get_pkg_name perform_sbo
- script_error
- open_fh
- open_read
- show_version
- slackbuilds_or_fetch
- fetch_tree
- update_tree
- get_installed_sbos
- get_available_updates
- do_slackbuild
- make_clean
- make_distclean
- do_upgradepkg
- get_sbo_location
- get_from_info
-);
-
-#$< == 0 or die "This script requires root privileges.\n";
-
-use Tie::File;
-use Sort::Versions;
-use Digest::MD5;
-use File::Copy;
-use File::Path qw(make_path remove_tree);
-use Fcntl;
-use File::Find;
-use File::Temp qw(tempdir tempfile);
-use Data::Dumper;
-
-our $tempdir = tempdir (CLEANUP => 1);
-
-# subroutine for throwing internal script errors
-sub script_error (;$) {
- exists $_[0] ? die "A fatal script error has occured:\n$_[0]\nExiting.\n"
- : die "A fatal script error has occured. Exiting.\n";
-}
-
-# sub for opening files, second arg is like '<','>', etc
-sub open_fh ($$) {
- exists $_[1] or script_error 'open_fh requires two arguments';
- -f $_[0] or script_error 'open_fh first argument not a file';
- my ($file, $op) = @_;
- open my $fh, $op, $file or die "Unable to open $file.\n";
- return $fh;
-}
-
-sub open_read ($) {
- return open_fh shift, '<';
-}
-
-# pull in configuration, set sane defaults, etc.
-our $conf_dir = '/etc/sbotools';
-our $conf_file = "$conf_dir/sbotools.conf";
-our %config = (
- NOCLEAN => 'FALSE',
- DISTCLEAN => 'FALSE',
- JOBS => 'FALSE',
- PKG_DIR => 'FALSE',
- SBO_HOME => 'FALSE',
-);
-
-# if the conf file exists, pull all the $key=$value pairs into a hash
-my %conf_values;
-if (-f $conf_file) {
- my $fh = open_read $conf_file;
- my $text = do {local $/; <$fh>};
- %conf_values = $text =~ /^(\w+)=(.*)$/mg;
- close $fh;
-}
-
-for my $key (keys %config) {
- $config{$key} = $conf_values{$key} if exists $conf_values{$key};
-}
-$config{JOBS} = 'FALSE' unless $config{JOBS} =~ /^\d+$/;
-$config{SBO_HOME} = '/usr/sbo' if $config{SBO_HOME} eq 'FALSE';
-
-# some stuff we'll need later.
-my $distfiles = "$config{SBO_HOME}/distfiles";
-my $slackbuilds_txt = "$config{SBO_HOME}/SLACKBUILDS.TXT";
-my $name_regex = '\ASLACKBUILD\s+NAME:\s+';
-
-sub show_version () {
- print "sbotools version $version\n";
- print "licensed under the WTFPL\n";
- print "<http://sam.zoy.org/wtfpl/COPYING>\n";
-}
-
-# %supported maps what's in /etc/slackware-version to what's at SBo
-# which is now not needed since this version drops support < 14.0
-# 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';
- chomp (my $line = <$fh>);
- close $fh;
- my $version = ($line =~ /\s+(\d+[^\s]+)$/)[0];
- die "Unsupported Slackware version: $version\n"
- unless $version ~~ %supported;
- return $supported{$version};
-}
-
-# does the SLACKBUILDS.TXT file exist in the sbo tree?
-sub chk_slackbuilds_txt () {
- return -f $slackbuilds_txt ? 1 : 0;
-}
-
-# check for the validity of new $config{SBO_HOME}
-sub check_home () {
- my $sbo_home = $config{SBO_HOME};
- if (-d $sbo_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";
- }
- } else {
- make_path ($sbo_home) or die "Unable to create $sbo_home.\n";
- }
-}
-
-# rsync the sbo tree from slackbuilds.org to $config{SBO_HOME}
-sub rsync_sbo_tree () {
- my $slk_version = get_slack_version;
- my @arg = ('rsync', '-a', '--exclude=*.tar.gz', '--exclude=*.tar.gz.asc');
- push @arg, "rsync://slackbuilds.org/slackbuilds/$slk_version/*";
- my $out = system @arg, $config{SBO_HOME};
- print "Finished.\n" and return $out;
-}
-
-# wrappers for differing checks and output
-sub fetch_tree () {
- check_home;
- print "Pulling SlackBuilds tree...\n";
- rsync_sbo_tree, return $?;
-}
-
-sub update_tree () {
- fetch_tree, return unless chk_slackbuilds_txt;
- print "Updating SlackBuilds tree...\n";
- rsync_sbo_tree, return $?;
-}
-
-# if the SLACKBUILDS.TXT is not in $config{SBO_HOME}, we assume the tree has
-# not been populated there; prompt the user to automagickally pull the tree.
-sub slackbuilds_or_fetch () {
- unless (chk_slackbuilds_txt) {
- print "It looks like you haven't run \"sbosnap fetch\" yet.\n";
- print "Would you like me to do this now? [y] ";
- <STDIN> =~ /^[Yy\n]/ ? fetch_tree :
- die "Please run \"sbosnap fetch\"\n";
- }
- return 1;
-}
-
-# pull an array of hashes, each hash containing the name and version of an sbo
-# currently installed.
-sub get_installed_sbos () {
- my @installed;
- # $1 == name, $2 == version
- my $regex = qr#/([^/]+)-([^-]+)-[^-]+-[^-]+$#;
- for my $path (</var/log/packages/*_SBo>) {
- my ($name, $version) = ($path =~ $regex)[0,1];
- push @installed, {name => $name, version => $version};
- }
- return \@installed;
-}
-
-# search the SLACKBUILDS.TXT for a given sbo's directory
-sub get_sbo_location ($) {
- exists $_[0] or script_error 'get_sbo_location requires an argument.';
- my $sbo = shift;
- my $regex = qr#LOCATION:\s+\.(/[^/]+/$sbo)$#;
- my $fh = open_read $slackbuilds_txt;
- while (my $line = <$fh>) {
- if (my $loc = ($line =~ $regex)[0]) {
- return "$config{SBO_HOME}$loc";
- }
- }
- return;
-}
-
-# pull the sbo name from a $location: $config{SBO_HOME}/system/wine, etc.
-sub get_sbo_from_loc ($) {
- exists $_[0] or script_error 'get_sbo_from_loc requires an argument.';
- return (shift =~ qr#/([^/]+)$#)[0];
-}
-
-# pull piece(s) of data, GET, from the $sbo.info file under LOCATION.
-sub get_from_info {
- warn " * * * * * * * * * * in get_from_info sub * * * * * * * * * *\n";
- my %args = (
- LOCATION => '',
- GET => '',
- @_
- );
- unless ($args{LOCATION} && $args{GET}) {
- script_error 'get_from_info requires LOCATION and GET.';
- }
- state $vars = {PKGNAM => ['']};
- my $sbo = get_sbo_from_loc $args{LOCATION};
- print Dumper ($vars);
- return $$vars{$args{GET}} if $$vars{PKGNAM}[0] eq $sbo;
- # if we haven't read in the .info file yet, do so now.
- warn " * * * * * * * * * * parsing $sbo.info file * * * * * * * * * *\n";
- my $fh = open_read "$args{LOCATION}/$sbo.info";
- # suck it all in and join up the \ lines...
- my $contents = do {local $/; <$fh>};
- $contents =~ s/("|\\\n)//g;
- my %tmp = $contents =~ /^(\w+)=(.*)$/mg;
- $vars = \%tmp;
- # fill the hash with array refs - even for single values,
- # since consistency here is a lot easier than sorting it out later
- for my $key (keys %$vars) {
- if ($$vars{$key} =~ /\s/) {
- my @array = split ' ', $$vars{$key};
- $$vars{$key} = \@array;
- } else {
- $$vars{$key} = [$$vars{$key}];
- }
- }
- return $$vars{$args{GET}};
-}
-
-# find the version in the tree for a given sbo (provided a location)
-sub get_sbo_version ($) {
- exists $_[0] or script_error 'get_sbo_version requires an argument.';
- my $version = get_from_info (LOCATION => shift, GET => 'VERSION');
- return $$version[0] ? $$version[0] : 0;
-}
-
-# for each installed sbo, find out whether or not the version in the tree is
-# newer, and compile an array of hashes containing those which are
-sub get_available_updates () {
- my @updates;
- my $pkg_list = get_installed_sbos;
- FIRST: for my $key (keys @$pkg_list) {
- my $location = get_sbo_location $$pkg_list[$key]{name};
- # if we can't find a location, assume invalid and skip
- next FIRST unless defined $location;
- my $version = get_sbo_version $location;
- if (versioncmp ($version, $$pkg_list[$key]{version}) == 1) {
- push @updates, {
- name => $$pkg_list[$key]{name},
- installed => $$pkg_list[$key]{version},
- update => $version
- };
- }
- }
- return \@updates;
-}
-
-# get downloads and md5sums from an sbo's .info file, first
-# checking for x86_64-specific info if we are told to
-sub get_download_info {
- my %args = (
- LOCATION => 0,
- X64 => 1,
- @_
- );
- $args{LOCATION} or script_error 'get_download_info requires LOCATION.';
- my ($get, $downs, $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?
- if ($args{X64}) {
- my $nothing;
- if (! $$downs[0]) {
- $nothing = 1;
- } elsif ($$downs[0] =~ qr/^UN(SUPPOR|TES)TED$/) {
- $nothing = 1;
- }
- if ($nothing) {
- $args{X64} = 0;
- $downs = get_from_info (LOCATION => $args{LOCATION},
- GET => 'DOWNLOAD');
- }
- }
- # if we still don't have any links, something is really wrong.
- return unless $$downs[0];
- # grab the md5s and build a hash
- $get = $args{X64} ? 'MD5SUM_x86_64' : 'MD5SUM';
- $md5s = get_from_info (LOCATION => $args{LOCATION}, GET => $get);
- return unless $$md5s[0];
- $return{$$downs[$_]} = $$md5s[$_] for (keys @$downs);
- return %return;
-}
-
-sub get_arch () {
- chomp (my $arch = `uname -m`);
- return $arch;
-}
-
-# TODO: should probably combine this with get_download_info
-sub get_sbo_downloads {
- my %args = (
- LOCATION => '',
- 32 => 0,
- @_
- );
- $args{LOCATION} or script_error 'get_sbo_downloads requires LOCATION.';
- my $location = $args{LOCATION};
- -d $location or script_error 'get_sbo_downloads given a non-directory.';
- my $arch = get_arch;
- my %dl_info;
- if ($arch eq 'x86_64') {
- %dl_info = get_download_info (LOCATION => $location) unless $args{32};
- }
- unless (keys %dl_info > 0) {
- %dl_info = get_download_info (LOCATION => $location, X64 => 0);
- }
- return %dl_info;
-}
-
-# given a link, grab the filename from the end of it
-sub get_filename_from_link ($) {
- exists $_[0] or script_error 'get_filename_from_link requires an argument';
- return "$distfiles/". (shift =~ qr#/([^/]+)$#)[0];
-}
-
-# for a given file, computer its md5sum
-sub compute_md5sum ($) {
- -f $_[0] or script_error 'compute_md5sum requires a file argument.';
- my $fh = open_read shift;
- my $md5 = Digest::MD5->new;
- $md5->addfile ($fh);
- my $md5sum = $md5->hexdigest;
- close $fh;
- return $md5sum;
-}
-
-sub compare_md5s ($$) {
- exists $_[1] or script_error 'compare_md5s requires two arguments.';
- my ($first, $second) = @_;
- return $first eq $second ? 1 : 0;
-}
-
-# for a given distfile, see whether or not it exists, and if so, if its md5sum
-# matches the sbo's .info file
-sub check_distfile ($$) {
- exists $_[1] or script_error 'check_distfile requires two arguments.';
- my ($link, $info_md5sum) = @_;
- my $filename = get_filename_from_link $link;
- return unless -d $distfiles;
- return unless -f $filename;
- my $md5sum = compute_md5sum $filename;
- return compare_md5s $info_md5sum, $md5sum;
-}
-
-# for a given distfile, attempt to retrieve it and, if successful, check its
-# md5sum against that in the sbo's .info file
-sub get_distfile ($$) {
- exists $_[1] or script_error 'get_distfile requires an argument';
- my ($link, $exp_md5) = @_;
- my $filename = get_filename_from_link $link;
- mkdir $distfiles unless -d $distfiles;
- chdir $distfiles;
- system ("wget --no-check-certificate $link") == 0 or
- die "Unable to wget $link\n";
- my $md5sum = compute_md5sum $filename;
- # can't do anything if the link in the .info doesn't lead to a good d/l
- compare_md5s $md5sum, $exp_md5 or die "md5sum failure for $filename.\n";
- return 1;
-}
-
-# for a given distfile, figure out what the full path to its symlink will be
-sub get_symlink_from_filename ($$) {
- exists $_[1] or script_error
- 'get_symlink_from_filename requires two arguments';
- -f $_[0] or script_error
- 'get_symlink_from_filename first argument is not a file';
- my ($filename, $location) = @_;
- return "$location/". ($filename =~ qr#/([^/]+)$#)[0];
-}
-
-# determine whether or not a given sbo is 32-bit only
-sub check_x32 ($) {
- exists $_[0] or script_error 'check_x32 requires an argument.';
- my $dl = get_from_info (LOCATION => shift, GET => 'DOWNLOAD_x86_64');
- return $$dl[0] =~ /UN(SUPPOR|TES)TED/ ? 1 : 0;
-}
-
-# can't do 32-bit on x86_64 without this file, so we'll use it as the test to
-# to determine whether or not an x86_64 system is setup for multilib
-sub check_multilib () {
- return 1 if -f '/etc/profile.d/32dev.sh';
- return;
-}
-
-# make a backup of the existent SlackBuild, and rewrite the original as needed
-sub rewrite_slackbuild ($$%) {
- exists $_[1] or script_error 'rewrite_slackbuild requires two arguments.';
- my ($slackbuild, $tempfn, %changes) = @_;
- copy ($slackbuild, "$slackbuild.orig") or
- die "Unable to backup $slackbuild to $slackbuild.orig\n";
- my $tar_regex = qr/(un|)tar .*$/;
- my $makepkg_regex = qr/makepkg/;
- my $libdir_regex = qr/^\s*LIBDIRSUFFIX="64"\s*$/;
- my $make_regex = qr/^\s*make(| \Q||\E exit 1)$/;
- my $arch_regex = qr/\$VERSION-\$ARCH-\$BUILD/;
- # tie the slackbuild, because this is the easiest way to handle this.
- tie my @sb_file, 'Tie::File', $slackbuild;
- for my $line (@sb_file) {
- # get the output of the tar and makepkg commands. hope like hell that v
- # is specified among tar's arguments
- if ($line =~ $tar_regex || $line =~ $makepkg_regex) {
- $line = "$line | tee -a $tempfn";
- }
- # then check for and apply any other %changes
- if (exists $changes{libdirsuffix}) {
- $line =~ s/64/$changes{libdirsuffix}/ if $line =~ $libdir_regex;
- }
- if (exists $changes{make}) {
- $line =~ s/make/make $changes{make}/ if $line =~ $make_regex;
- }
- if (exists $changes{arch_out}) {
- $line =~ s/\$ARCH/$changes{arch_out}/ if $line =~ $arch_regex;
- }
- }
- untie @sb_file;
- return 1;
-}
-
-# move a backed-up .SlackBuild file back into place
-sub revert_slackbuild ($) {
- exists $_[0] or script_error 'revert_slackbuild requires an argument';
- my $slackbuild = shift;
- if (-f "$slackbuild.orig") {
- unlink $slackbuild if -f $slackbuild;
- rename ("$slackbuild.orig", $slackbuild);
- }
- return 1;
-}
-
-# given a location and a list of download links, assemble a list of symlinks,
-# and create them.
-sub create_symlinks ($%) {
- exists $_[1] or script_error 'create_symlinks requires two arguments.';
- my ($location, %downloads) = @_;
- my @symlinks;
- for my $link (keys %downloads) {
- my $md5sum = $downloads{$link};
- unless (check_distfile $link, $md5sum) {
- die unless get_distfile $link, $md5sum;
- }
- my $filename = get_filename_from_link $link;
- my $symlink = get_symlink_from_filename $filename, $location;
- push @symlinks, $symlink;
- symlink $filename, $symlink;
- }
- return @symlinks;
-}
-
-# pull the untarred source directory or created package name from the temp
-# file (the one we tee'd to)
-sub grok_temp_file {
- my %args = (
- TEMPFN => '',
- REGEX => '',
- CAPTURE => 0,
- @_
- );
- unless ($args{TEMPFN} && $args{REGEX}) {
- script_error 'grok_temp_file requires two arguments';
- }
- my $out;
- my $fh = open_read $args{TEMPFN};
- FIRST: while (my $line = <$fh>) {
- if ($line =~ $args{REGEX}) {
- $out = ($line =~ $args{REGEX})[$args{CAPTURE}];
- last FIRST;
- }
- }
- close $fh;
- return $out;
-}
-
-# wrappers around grok_temp_file
-sub get_src_dir ($) {
- exists $_[0] or script_error 'get_src_dir requires an argument';
- return grok_temp_file (TEMPFN => shift, REGEX => qr#^([^/]+)/#);
-}
-
-sub get_pkg_name ($) {
- exists $_[0] or script_error 'get_pkg_name requires an argument';
- return grok_temp_file (TEMPFN => shift,
- REGEX => qr/^Slackware\s+package\s+([^\s]+)\s+created\.$/);
-}
-
-# prep and run .SlackBuild
-sub perform_sbo {
- my %args = (
- OPTS => 0,
- JOBS => 0,
- LOCATION => '',
- ARCH => '',
- C32 => 0,
- X32 => 0,
- @_
- );
- unless ($args{LOCATION} && $args{ARCH}) {
- script_error 'perform_sbo requires LOCATION and ARCH.';
- }
- my $location = $args{LOCATION};
- my $sbo = get_sbo_from_loc $location;
- my ($cmd, %changes);
- $changes{make} = "-j $args{JOBS}" if $args{JOBS};
- if ($args{ARCH} eq 'x86_64' and ($args{C32} || $args{X32}) ) {
- if ($args{C32}) {
- $changes{libdirsuffix} = '';
- } elsif ($args{X32}) {
- $changes{arch_out} = 'i486';
- }
- $cmd = ". /etc/profile.d/32dev.sh &&";
- }
- $cmd .= "/bin/sh $location/$sbo.SlackBuild";
- $cmd = "$args{OPTS} $cmd" if $args{OPTS};
- my ($tempfh, $tempfn) = tempfile (DIR => $tempdir);
- close $tempfh;
- rewrite_slackbuild "$location/$sbo.SlackBuild", $tempfn, %changes;
- chdir $location, my $out = system $cmd;
- revert_slackbuild "$location/$sbo.SlackBuild";
- die unless $out == 0;
- my $src = get_src_dir $tempfn;
- my $pkg = get_pkg_name $tempfn;
- unlink $tempfn;
- return $pkg, $src;
-}
-
-# "public interface", sort of thing.
-sub do_slackbuild {
- my %args = (
- OPTS => 0,
- JOBS => 0,
- LOCATION => '',
- COMPAT32 => 0,
- @_
- );
- $args{LOCATION} or script_error 'do_slackbuild requires LOCATION.';
- my $location = $args{LOCATION};
- my $sbo = get_sbo_from_loc $location;
- my $arch = get_arch;
- my $multi = check_multilib;
- my $version = get_sbo_version $location;
- my $x32;
- if ($args{COMPAT32}) {
- die "compat32 only works on x86_64.\n" unless $arch eq 'x86_64';
- die "compat32 requires multilib.\n" unless $multi;
- die "compat32 requires /usr/sbin/convertpkg-compat32.\n"
- unless -f '/usr/sbin/convertpkg-compat32';
- } else {
- if ($arch eq 'x86_64') {
- $x32 = check_x32 $args{LOCATION};
- if ($x32 && ! $multi) {
- die "$sbo is 32-bit which requires multilib on x86_64.\n";
- }
- }
- }
- my %downloads = get_sbo_downloads (
- LOCATION => $location,
- 32 => $args{COMPAT32}
- );
- my @symlinks = create_symlinks $args{LOCATION}, %downloads;
- my ($pkg, $src) = perform_sbo (
- OPTS => $args{OPTS},
- JOBS => $args{JOBS},
- LOCATION => $location,
- ARCH => $arch,
- C32 => $args{COMPAT32},
- X32 => $x32,
- );
- if ($args{COMPAT32}) {
- my ($tempfh, $tempfn) = tempfile (DIR => $tempdir);
- close $tempfh;
- my $cmd = "/usr/sbin/convertpkg-compat32 -i $pkg -d /tmp | tee $tempfn";
- system ($cmd) == 0 or die;
- unlink $pkg;
- $pkg = get_pkg_name $tempfn;
- }
- unlink $_ for @symlinks;
- return $version, $pkg, $src;
-}
-
-# remove work directories (source and packaging dirs under /tmp/SBo)
-sub make_clean ($$$) {
- exists $_[2] or script_error 'make_clean requires three arguments.';
- my ($sbo, $src, $version) = @_;
- print "Cleaning for $sbo-$version...\n";
- my $tmpsbo = "/tmp/SBo";
- remove_tree ("$tmpsbo/$src") if -d "$tmpsbo/$src";
- remove_tree ("$tmpsbo/package-$sbo") if -d "$tmpsbo/package-$sbo";
- return 1;
-}
-
-# remove distfiles
-sub make_distclean {
- my %args = (
- SRC => '',
- VERSION => '',
- LOCATION => '',
- @_
- );
- unless ($args{SRC} && $args{VERSION} && $args{LOCATION}) {
- script_error 'make_distclean requires four arguments.';
- }
- my $sbo = get_sbo_from_loc $args{LOCATION};
- make_clean $sbo, $args{SRC}, $args{VERSION};
- print "Distcleaning for $sbo-$args{VERSION}...\n";
- # remove any distfiles for this particular SBo.
- 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;
- }
- return 1;
-}
-
-# run upgradepkg for a created package
-sub do_upgradepkg ($) {
- exists $_[0] or script_error 'do_upgradepkg requires an argument.';
- system ('/sbin/upgradepkg', '--reinstall', '--install-new', shift);
- return 1;
-}
diff --git a/t/prep.pl b/t/prep.pl
index 08efc61..c5591dc 100755
--- a/t/prep.pl
+++ b/t/prep.pl
@@ -1,5 +1,6 @@
#!/usr/bin/perl
+use 5.16.0;
use strict;
use warnings FATAL => 'all';
use File::Copy;
@@ -8,6 +9,49 @@ use Tie::File;
chomp (my $pwd = `pwd`);
mkdir "$pwd/SBO" unless -d "$pwd/SBO";
copy ('/home/d4wnr4z0r/projects/slack14/sbotools/SBO-Lib/lib/SBO/Lib.pm', "$pwd/SBO");
+
+open my $write, '>>', "$pwd/SBO/Lib.pm";
+
+print {$write} "my \$interactive = 1;\n";
+print {$write} "my \%locations;";
+print {$write} "my \$compat32 = 1;\n";
+print {$write} "my \$no_readme = 1;\n";
+print {$write} "my \$jobs = 1;\n";
+print {$write} "my \$distclean = 1;\n";
+print {$write} "my \$noclean = 1;\n";
+print {$write} "my \$no_install = 1;\n";
+
+sub get_subs ($) {
+ my $read = shift;
+ my $begin_regex = qr/^sub\s+[a-z0-9_]+/;
+ my $usage_regex = qr/^sub\s+show_usage/;
+ my $end_regex = qr/^}$/;
+ my $begin = 0;
+ my $end = 0;
+ while (my $line = <$read>) {
+ if (! $begin) {
+ if ($line =~ $begin_regex) {
+ if ($line !~ $usage_regex) {
+ $end = 0, $begin++, print {$write} $line;
+ }
+ }
+ } elsif (! $end) {
+ if ($line =~ $end_regex) {
+ $begin = 0, $end++, print {$write} $line;
+ } else {
+ print {$write} $line;
+ }
+ }
+ }
+}
+
+for my $file (qw(sbocheck sboclean sboconfig sbofind sboupgrade)) {
+ open my $read, '<', "../$file";
+ get_subs $read;
+ close $read;
+}
+close $write;
+
my @subs;
open my $file_h, '<', "$pwd/SBO/Lib.pm";
my $regex = qr/^sub\s+([^\s]+)\s+/;
diff --git a/t/test.t b/t/test.t
index aabb5fa..36306c4 100755
--- a/t/test.t
+++ b/t/test.t
@@ -4,7 +4,7 @@ use 5.16.0;
use strict;
use warnings FATAL => 'all';
use File::Temp qw(tempdir tempfile);
-use Test::More tests => 61;
+use Test::More tests => 87;
use File::Copy;
use Text::Diff;
use SBO::Lib;
@@ -210,5 +210,74 @@ is ($$info[0], 'http://www.libimobiledevice.org', 'get_from_info GET => HOMEPAGE
$info = get_from_info (%params, GET => 'DOWNLOAD_x86_64');
is ($$info[0], "", 'get_from_info GET => DOWNLOAD_x86_64 is good');
+# 62-64, get_update_list tests
+my $listing = get_update_list;
+s/\s//g for @$listing;
+for my $item (@$listing) {
+ is ($item, 'zdoom-2.5.0<needsupdating(SBohas2.6.0)', 'get_update_list output good for zdoom') if $item =~ /^zdoom/;
+ is ($item, 'ffmpeg-0.8.7<needsupdating(SBohas0.11.1)', 'get_update_list output good for ffmpeg') if $item =~ /^ffmpeg/;
+ is ($item, 'atkmm-2.22.4<needsupdating(SBohas2.22.6)', 'get_update_list output good for atkmm') if $item =~ /^atkmm/;
+}
+
+# 65, remove_stuff test - can only really test for invalid input
+is (remove_stuff '/omg/wtf/bbq', 1, 'remove_stuff good for invalid input');
+
+# 66, config_write test
+is (config_write ('OMG', 'WTF'), undef, 'config_write returned undef correctly');
+
+# 67-74, perform_search tests
+my $findings = perform_search 'desktop';
+for my $found (@$findings) {
+ for my $key (keys %$found) {
+ my $section = 'desktop';;
+ if ($key eq 'libdesktop-agnostic') {
+ $section = 'libraries';
+ } elsif ($key eq 'mendeleydesktop') {
+ $section = 'academic';
+ } elsif ($key eq 'gtk-recordmydesktop' || $key eq 'huludesktop') {
+ $section = 'multimedia';
+ } elsif ($key eq 'gnome-python-desktop') {
+ $section = 'python';
+ }
+ is ($$found{$key}, "$sbo_home/$section/$key", 'perform_search good for $search eq desktop');
+ }
+}
+
+# 75, get_inst_names test
+$installed = get_installed_sbos;
+my $inst_names = get_inst_names $installed;
+ok ('zdoom' ~~ @$inst_names, 'get_inst_names is good');
+
+# 76-81, get_reqs tests
+ok (! (get_requires 'stops', "$sbo_home/audio/stops"), 'get_requires good for circular requirements');
+ok (! (get_requires 'smc', "$sbo_home/games/smc"), 'get_requires good for REQUIRES="%README%"');
+ok (! (get_requires 'krb5', "$sbo_home/network/krb5"), 'get_requires good for REQUIRES=""');
+my $reqs = get_requires 'matchbox-desktop', "$sbo_home/desktop/matchbox-desktop";
+my $say = 'get_requires good for normal req list';
+is ($$reqs[0], 'libmatchbox', $say);
+is ($$reqs[1], 'matchbox-window-manager', $say);
+is ($$reqs[2], 'matchbox-common', $say);
+
+# 82-85, get_user_group tests
+$fh = open_read "$sbo_home/network/nagios/README";
+my $readme = do {local $/; <$fh>};
+close $fh;
+my @cmds = get_user_group $readme;
+is ($cmds[0], 'groupadd -g 213 nagios', 'get_user_group good for # groupadd');
+is ($cmds[1], 'useradd -u 213 -d /dev/null -s /bin/false -g nagios nagios', 'get_user_group for # useradd');
+$fh = open_read "$sbo_home/network/havp/README";
+$readme = do {local $/; <$fh>};
+close $fh;
+@cmds = get_user_group $readme;
+is ($cmds[0], 'groupadd -g 210 clamav', 'get_user_group good for groupadd');
+is ($cmds[1], 'useradd -u 256 -d /dev/null -s /bin/false -g clamav havp', 'get_user_group good for useradd');
-#is (do_convertpkg ($package), "$package-compat32", 'do_convertpkg good');
+# 86-87, get_opts test
+$fh = open_read "$sbo_home/games/vbam/README";
+$readme = do {local $/; <$fh>};
+close $fh;
+ok (get_opts $readme, 'get_opts good where README defines opts');
+$fh = open_read "$sbo_home/libraries/libmatchbox/README";
+$readme = do {local $/; <$fh>};
+close $fh;
+ok (! (get_opts $readme), 'get_opts good where README does not define opts');