aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SBO-Lib/lib/SBO/Lib.pm65
-rwxr-xr-xsboremove6
-rwxr-xr-xsboupgrade6
-rwxr-xr-xt/test.t60
4 files changed, 119 insertions, 18 deletions
diff --git a/SBO-Lib/lib/SBO/Lib.pm b/SBO-Lib/lib/SBO/Lib.pm
index 811243b..e06f124 100644
--- a/SBO-Lib/lib/SBO/Lib.pm
+++ b/SBO-Lib/lib/SBO/Lib.pm
@@ -31,6 +31,7 @@ our @EXPORT = qw(
get_inst_names
get_available_updates
get_requires
+ get_readme_contents
do_slackbuild
make_clean
make_distclean
@@ -447,11 +448,45 @@ sub check_multilib() {
return;
}
+# given a list of downloads, return just the filenames
+sub get_dl_fns($) {
+ my $fns = shift;
+ my $return;
+ push @$return, ($_ =~ qr|/([^/]+)$|)[0] for @$fns;
+ return $return;
+}
+
+# given a line that looks like it's decompressing something, try to return a
+# valid filename regex
+sub get_dc_regex {
+ my $line = shift;
+ # get rid of initial 'tar x'whatever stuff
+ $line =~ s/^.*(?<![a-z])(tar|p7zip|unzip|ar|rpm2cpio|sh)\s+[^\s]+\s+//;
+ # need to know preceeding character - should be safe to assume it's either
+ # a slash or a space
+ my $initial = $line =~ qr|/| ? '/' : ' ';
+ # get rid of initial path info
+ $line =~ s|^\$[^/]+/||;
+ # convert any instances of command substitution to [^-]+
+ $line =~ s/\$\([^)]+\)/[^-]+/g;
+ # convert any bash variables to [^-]+
+ $line =~ s/\$({|)[A-Za-z0-9_]+(}|)/[^-]+/g;
+ # get rid of anything excess at the end
+ $line =~ s/\s+.*$//;
+ # fix .?z* at the end
+ $line =~ s/\.\?z\*/\.[a-z]z.*/;
+ # return what's left as a regex
+ my $regex = qr/$initial$line/;
+ return $regex, $initial;
+}
+
# make a backup of the existent SlackBuild, and rewrite the original as needed
sub rewrite_slackbuild {
my %args = (
+ SBO => '',
SLACKBUILD => '',
CHANGES => {},
+ C32 => 0,
@_
);
$args{SLACKBUILD} or script_error 'rewrite_slackbuild requires SLACKBUILD.';
@@ -461,8 +496,28 @@ sub rewrite_slackbuild {
die "Unable to backup $slackbuild to $slackbuild.orig\n";
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+/;
# tie the slackbuild, because this is the easiest way to handle this.
tie my @sb_file, 'Tie::File', $slackbuild;
+ # if we're dealing with a compat32, we need to change the tar line(s) so
+ # that the 32-bit source is untarred
+ if ($args{C32}) {
+ my $location = get_sbo_location($args{SBO});
+ my %downloads = get_sbo_downloads(
+ LOCATION => $location,
+ 32 => 1,
+ );
+ my $fns = get_dl_fns [keys %downloads];
+ for my $line (@sb_file) {
+ if ($line =~ $dc_regex) {
+ my ($regex, $initial) = get_dc_regex $line;
+ for my $fn (@$fns) {
+ $fn = "$initial$fn";
+ $line =~ s/$regex/$fn/ if $fn =~ $regex;
+ }
+ }
+ }
+ }
for my $line (@sb_file) {
# then check for and apply any other %$changes
if (exists $$changes{libdirsuffix}) {
@@ -598,8 +653,10 @@ sub perform_sbo {
my $fn = get_tmp_extfn $tempfh;
$cmd .= " | tee -a $fn";
rewrite_slackbuild(
+ SBO => $sbo,
SLACKBUILD => "$location/$sbo.SlackBuild",
CHANGES => \%changes,
+ C32 => $args{C32},
);
chdir $location, system $cmd;
seek $exit_temp, 0, 0;
@@ -785,3 +842,11 @@ sub merge_queues {
}
return $queue_a;
}
+
+sub get_readme_contents($) {
+ exists $_[0] or script_error 'get_readme_contents requires an argument.';
+ my $fh = open_read(shift .'/README');
+ my $readme = do {local $/; <$fh>};
+ close $fh;
+ return $readme;
+}
diff --git a/sboremove b/sboremove
index 3b92099..7e4ddfc 100755
--- a/sboremove
+++ b/sboremove
@@ -156,11 +156,7 @@ 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 $location = get_sbo_location($remove);
- my $fh = open_read($location .'/README');
- my $readme = do {local $/; <$fh>};
- close $fh;
-
+ my $readme = get_readme_contents get_sbo_location($remove);
print "\n" . $readme if <STDIN> =~ /^[Yy\n]/;
}
diff --git a/sboupgrade b/sboupgrade
index 3f9dcfe..daa6799 100755
--- a/sboupgrade
+++ b/sboupgrade
@@ -171,10 +171,8 @@ sub ask_opts {
sub user_prompt {
exists $_[1] or script_error 'user_prompt requires two arguments.';
my ($sbo, $location) = @_;
- my $fh = open_read($location .'/README');
- my $readme = do {local $/; <$fh>};
- close $fh;
-
+ my $readme = get_readme_contents $location;
+
# check for user/group add commands, offer to run any found
my $user_group = get_user_group $readme;
my $cmds;
diff --git a/t/test.t b/t/test.t
index 8c2979a..daa9d1c 100755
--- a/t/test.t
+++ b/t/test.t
@@ -204,7 +204,7 @@ is(get_distfile
'5434f948fdea6406851c77bebbd0ed19'), 1, 'get_distfile is good');
unlink $distfile;
-# rewrite_slackbuilds/revert_slackbuild tests
+# rewrite_slackbuild/revert_slackbuild tests
my $rewrite_dir = tempdir(CLEANUP => 1);
copy("$sbo_home/system/ifuse/ifuse.SlackBuild", $rewrite_dir);
my $slackbuild = "$rewrite_dir/ifuse.SlackBuild";
@@ -218,18 +218,22 @@ is(revert_slackbuild $slackbuild, 1, 'revert_slackbuild is good');
$changes{libdirsuffix} = '';
$changes{make} = '-j 5';
$changes{arch_out} = 'i486';
-is(rewrite_slackbuild (SLACKBUILD => $slackbuild, TEMPFN => $tempfn,
- CHANGES => \%changes), 1, 'rewrite_slackbuild with all %changes good');
+is(rewrite_slackbuild (SLACKBUILD => $slackbuild, CHANGES => \%changes,
+ C32 => 1, SBO => 'ifuse'), 1, 'rewrite_slackbuild test w/ all %changes');
ok(-f "$slackbuild.orig", 'rewrite_slackbuild backing up original is good.');
-my $expected_out = "55c55
-< LIBDIRSUFFIX=\"64\"
+my $expected_out = '55c55
+< LIBDIRSUFFIX="64"
+---
+> LIBDIRSUFFIX=""
+67c67
+< tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2
---
-> LIBDIRSUFFIX=\"\"
+> tar xvf $CWD/ifuse-1.1.1.tar.bz2
103c103
-< /sbin/makepkg -l y -c n \$OUTPUT/\$PRGNAM-\$VERSION-\$ARCH-\$BUILD\$TAG.\${PKGTYPE:-tgz}
+< /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
---
-> /sbin/makepkg -l y -c n \$OUTPUT/\$PRGNAM-\$VERSION-i486-\$BUILD\$TAG.\${PKGTYPE:-tgz}
-";
+> /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-i486-$BUILD$TAG.${PKGTYPE:-tgz}
+';
is(diff("$slackbuild.orig", $slackbuild, {STYLE => 'OldStyle'}),
$expected_out, 'all changed lines rewritten correctly');
is(revert_slackbuild $slackbuild, 1, 'revert_slackbuild is good again');
@@ -392,5 +396,43 @@ confirm_remove('zdoom');
$count = @SBO::Lib::confirmed;
is($count, 4, 'confirm_remove good for duplicate sbo');
+# test get_readme_contents
+ok((get_readme_contents "$sbo_home/network/nagios"), 'get_readme_contents is good');
+
+# test get_dl_fns
+my $downloads = [
+ 'http://developer.download.nvidia.com/cg/Cg_3.1/Cg-3.1_April2012_x86.tgz'
+];
+my $fns = get_dl_fns $downloads;
+is($$fns[0], 'Cg-3.1_April2012_x86.tgz', 'get_dl_fns test, one input');
+$downloads = [
+ 'http://download.virtualbox.org/virtualbox/4.2.0/VirtualBox-4.2.0.tar.bz2',
+ 'http://download.virtualbox.org/virtualbox/4.2.0/VBoxGuestAdditions_4.2.0.iso',
+ 'http://download.virtualbox.org/virtualbox/4.2.0/UserManual.pdf',
+ 'http://download.virtualbox.org/virtualbox/4.2.0/SDKRef.pdf',
+];
+$fns = get_dl_fns $downloads;
+is($$fns[0], 'VirtualBox-4.2.0.tar.bz2', 'get_dl_fns test, multiple inputs 01');
+is($$fns[2], 'UserManual.pdf', 'get_dl_fns test, multiple inputs 02');
+
+# test get_dc_regex - multiple tests for various types of input
+my $line = 'tar xvf $CWD/$PRGNAM-$VERSION.tar.?z*';
+my ($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u:/[^-]+-[^-]+.tar.[a-z]z.*)', 'get_dc_regex test 01.1');
+is($initial, '/', 'get_dc_regex test 01.2');
+$line = 'tar xvf $CWD/Oracle_VM_VirtualBox_Extension_Pack-$VERSION.vbox-extpack';
+($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u:/Oracle_VM_VirtualBox_Extension_Pack-[^-]+.vbox-extpack)',
+ 'get_dc_regex test 02.1');
+is($initial, '/', 'get_dc_regex test 02.2');
+$line = 'tar xvf $CWD/${PRGNAM}-source-$(echo $VERSION).tar.gz';
+($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u:/[^-]+-source-[^-]+.tar.gz)', 'get_dc_regex test 03.1');
+is($initial, '/', 'get_dc_regex test 03.2');
+$line = '( tar xvf xapian-bindings-$VERSION.tar.gz';
+($regex, $initial) = get_dc_regex $line;
+is($regex, '(?^u: xapian-bindings-[^-]+.tar.gz)', 'get_dc_regex test 04.1');
+is($initial, ' ', 'get_dc_regex test 04.2');
+
# end of tests.
done_testing();