diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | SBO-Lib/Changes | 8 | ||||
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Info.pm | 45 | ||||
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Readme.pm | 27 | ||||
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Repo.pm | 2 | ||||
-rw-r--r-- | SBO-Lib/lib/SBO/Lib/Util.pm | 18 | ||||
-rwxr-xr-x | t/01-unit.t | 5 | ||||
-rwxr-xr-x | t/05-upgrade.t | 10 | ||||
-rwxr-xr-x | t/11-git.t | 33 | ||||
-rwxr-xr-x | t/12-readme.t | 9 | ||||
-rw-r--r-- | t/32-info.t | 34 | ||||
-rw-r--r-- | t/LO-readme/otherreadmes/README | 1 | ||||
-rw-r--r-- | t/LO-readme/otherreadmes/README.SBo | 1 | ||||
-rw-r--r-- | t/LO-readme/otherreadmes/README.SLACKWARE | 1 | ||||
-rw-r--r-- | t/LO-readme/otherreadmes/otherreadmes.SlackBuild | 15 | ||||
-rw-r--r-- | t/LO-readme/otherreadmes/otherreadmes.info | 10 | ||||
-rw-r--r-- | t/LO/locale-versionsbo/README | 1 | ||||
-rw-r--r-- | t/LO/locale-versionsbo/locale-versionsbo.SlackBuild | 16 | ||||
-rw-r--r-- | t/LO/locale-versionsbo/locale-versionsbo.info | 10 |
19 files changed, 226 insertions, 24 deletions
@@ -9,8 +9,12 @@ - Extract code to submodules for easier separation of concerns * New features: - Support for templates for installing things with specified options #38 + - Display other README files if the slackbuild comes with them #49 * Bugfixes - sboinstall/sboremove disagreeing about a package being installed #44 + - sbocheck and sboupgrade misinterpreting version strings #45 + - parsing .info files without leading space on second line #46 + - local git repo gets partially chowned to root #47 * 2.0 - 2016-07-02 * Major new features diff --git a/SBO-Lib/Changes b/SBO-Lib/Changes index 588b0ec..1189995 100644 --- a/SBO-Lib/Changes +++ b/SBO-Lib/Changes @@ -5,9 +5,17 @@ * New features: - Support for templates for installing things with specified options (https://github.com/pink-mist/sbotools/issues/38) + - Display other README files if the slackbuild comes with them + (https://github.com/pink-mist/sbotools/issues/49) * Bugfixes - sboinstall/sboremove disagreeing about a package being installed (https://github.com/pink-mist/sbotools/issues/44) + - sbocheck and sboupgrade misinterpreting version strings + (https://github.com/pink-mist/sbotools/issues/45) + - parsing .info files without leading space on second line + (https://github.com/pink-mist/sbotools/issues/46) + - local git repo gets partially chowned to root + (https://github.com/pink-mist/sbotools/issues/47) 2.0 - 2016-07-02 * Major new features diff --git a/SBO-Lib/lib/SBO/Lib/Info.pm b/SBO-Lib/lib/SBO/Lib/Info.pm index 3f20497..91a96e0 100644 --- a/SBO-Lib/lib/SBO/Lib/Info.pm +++ b/SBO-Lib/lib/SBO/Lib/Info.pm @@ -18,6 +18,7 @@ our @EXPORT_OK = qw{ get_orig_version get_requires get_sbo_version + parse_info }; our %EXPORT_TAGS = ( @@ -132,18 +133,13 @@ sub get_from_info { usage_error("get_from_info: could not read $args{LOCATION}/$sbo.info.") unless defined $contents; - $contents =~ s/("|\\\n)//g; - my $last_key = ''; + my %parse = parse_info($contents); + script_error("error when parsing $sbo.info file.") unless %parse; + $store = {}; $store->{LOCATION} = [$args{LOCATION}]; - foreach my $line (split /\n/, $contents) { - my ($key, $val) = $last_key; - if ($line =~ /^([^=\s]+)=(.*)$/) { $key = $1; $val = $2; } - elsif ($line =~ /^\s+([^\s].+)$/) { $val = $1; } - else { script_error("error when parsing $sbo.info file. Line: $line") } - push @{ $store->{$key} }, ($val ? split(' ', $val) : $val); - $last_key = $key; - } + foreach my $k (keys %parse) { $store->{$k} = $parse{$k}; } + # allow local overrides to get away with not having quite all the fields if (is_local($sbo)) { for my $key (qw/DOWNLOAD_x86_64 MD5SUM_x86_64 REQUIRES/) { @@ -205,6 +201,35 @@ sub get_sbo_version { return $version->[0]; } +=head2 parse_info + + my %parse = parse_info($str); + +C<parse_info()> parses the contents of an .info file from C<$str> and returns +a key-value list of it. + +=cut + +sub parse_info { + script_error('parse_info requires an argument.') unless @_ == 1; + my $info_str = shift; + my $pos = 0; + my %ret; + + while ($info_str =~ /\G([A-Za-z0-9_]+)="([^"]*)"\n/g) { + my $key = $1; + my @val = split " ", $2; + @val = '' unless @val; + $ret{$key} = \@val; + $pos = pos($info_str); + } + + return if $pos != length($info_str); + + return %ret; + +} + =head1 AUTHORS SBO::Lib was originally written by Jacob Pipkin <j@dawnrazor.net> with diff --git a/SBO-Lib/lib/SBO/Lib/Readme.pm b/SBO-Lib/lib/SBO/Lib/Readme.pm index b29558b..d365a8a 100644 --- a/SBO-Lib/lib/SBO/Lib/Readme.pm +++ b/SBO-Lib/lib/SBO/Lib/Readme.pm @@ -13,6 +13,7 @@ use Exporter 'import'; our @EXPORT_OK = qw{ ask_opts + ask_other_readmes ask_user_group get_opts get_readme_contents @@ -77,6 +78,31 @@ sub ask_opts { return(); } +=head2 ask_other_readmes + + ask_other_readmes($sbo, $location); + +C<ask_other_readmes()> checks if there are other readmes for the C<$sbo> in +C<$location>, and if so, asks the user if they should be displayed, and then +displays them if the user didn't decline. + +=cut + +sub ask_other_readmes { + my ($sbo, $location) = @_; + my @readmes = sort grep { ! m!/README$! } glob "$location/README*"; + + return unless @readmes; + + return unless prompt("\nIt looks like $sbo has additional README files. Would you like to see those too?", default => 'yes'); + + for my $fn (@readmes) { + my ($display_fn) = $fn =~ m!/(README.*)$!; + say "\n$display_fn:"; + say slurp $fn; + } +} + =head2 ask_user_group my $bool = ask_user_group($cmds, $readme); @@ -183,6 +209,7 @@ sub user_prompt { my $opts = 0; $opts = ask_opts($sbo, $readme) if get_opts($readme); print "\n". $readme unless $opts; + ask_other_readmes($sbo, $location); # we have to return something substantial if the user says no so that we # can check the value of $cmds on the calling side. we should be able to # assume that 'N' will never be a valid command to run. diff --git a/SBO-Lib/lib/SBO/Lib/Repo.pm b/SBO-Lib/lib/SBO/Lib/Repo.pm index e920b6b..1330073 100644 --- a/SBO-Lib/lib/SBO/Lib/Repo.pm +++ b/SBO-Lib/lib/SBO/Lib/Repo.pm @@ -242,7 +242,7 @@ sub git_sbo_tree { } else { chdir $config{SBO_HOME} or return 0; remove_tree($repo_path) if -d $repo_path; - $res = system(qw/ git clone /, $url, $repo_path) == 0; + $res = system(qw/ git clone --no-local /, $url, $repo_path) == 0; } _race::cond '$cwd could be deleted here'; return 1 if chdir $cwd and $res; diff --git a/SBO-Lib/lib/SBO/Lib/Util.pm b/SBO-Lib/lib/SBO/Lib/Util.pm index c4128af..6c38382 100644 --- a/SBO-Lib/lib/SBO/Lib/Util.pm +++ b/SBO-Lib/lib/SBO/Lib/Util.pm @@ -506,20 +506,32 @@ sub usage_error { C<version_cmp()> will compare C<$ver1> with C<$ver2> to try to determine which is bigger than the other, and returns 1 if C<$ver1> is bigger, -1 if C<$ver2> is bigger, and 0 if they are just as big. Before making the comparison, it will -strip off the version of your running kernel if it happens to be appended to -the version string being compared. +strip off the version of your running kernel as well as any locale information +if it happens to be appended to the version string being compared. =cut # wrapper around versioncmp for checking if versions have kernel version -# appended to them +# or locale info appended to them sub version_cmp { my ($v1, $v2) = @_; my $kv = get_kernel_version(); + # strip off kernel version if ($v1 =~ /(.+)_\Q$kv\E$/) { $v1 = $1 } if ($v2 =~ /(.+)_\Q$kv\E$/) { $v2 = $1 } + # if $v2 doesn't end in the same thing, strip off locale info from $v1 + if ($v1 =~ /(.*)_([a-z]{2})_([A-Z]{2})$/) { + my $v = $1; + if ($v2 !~ /_$2_$3$/) { $v1 = $v; } + } + # and vice versa... + if ($v2 =~ /(.*)_([a-z]{2})_([A-Z]{2})$/) { + my $v = $1; + if ($v1 !~ /_$2_$3$/) { $v2 = $v; } + } + versioncmp($v1, $v2); } diff --git a/t/01-unit.t b/t/01-unit.t index 13d6e8e..6fec4fd 100755 --- a/t/01-unit.t +++ b/t/01-unit.t @@ -11,7 +11,7 @@ use Capture::Tiny qw/ capture_merged /; use File::Temp 'tempdir'; use Cwd; -plan tests => 60; +plan tests => 62; # 1-2: test script_error(); { @@ -319,6 +319,9 @@ SKIP: { local *SBO::Lib::Util::get_kernel_version = sub { "foo_bar" }; is (SBO::Lib::version_cmp('1.0', '1.0_foo_bar'), 0, "version_cmp(1.0, 1.0_foo_bar) returned 0"); + + is (SBO::Lib::version_cmp('1.0_en_US', '1.0'), 0, "version_cmp(1.0_en_US, 1.0) returned 0"); + is (SBO::Lib::version_cmp('1.0', '1.0_en_US'), 0, "version_cmp(1.0, 1.0_en_US) returned 0"); } # 60: test check_multilib(); diff --git a/t/05-upgrade.t b/t/05-upgrade.t index b7e1e29..e35bc5c 100755 --- a/t/05-upgrade.t +++ b/t/05-upgrade.t @@ -25,12 +25,14 @@ sub cleanup { system(qw!/sbin/removepkg nonexistentslackbuild5!); system(qw!/sbin/removepkg nonexistentslackbuild6!); system(qw!/sbin/removepkg weird-versionsbo!); + system(qw!/sbin/removepkg locale-versionsbo!); unlink "$RealBin/LO/nonexistentslackbuild/perf.dummy"; unlink "$RealBin/LO/nonexistentslackbuild2/perf.dummy"; unlink "$RealBin/LO/nonexistentslackbuild4/perf.dummy"; unlink "$RealBin/LO/nonexistentslackbuild5/perf.dummy"; unlink "$RealBin/LO/nonexistentslackbuild6/perf.dummy"; unlink "$RealBin/LO/weird-versionsbo/perf.dummy"; + unlink "$RealBin/LO/locale-versionsbo/perf.dummy"; unlink "$RealBin/LO2/nonexistentslackbuild/perf.dummy"; unlink "$RealBin/LO2/nonexistentslackbuild2/perf.dummy"; unlink "$RealBin/LO2/nonexistentslackbuild4/perf.dummy"; @@ -50,6 +52,7 @@ sub cleanup { system(qw!rm -rf /tmp/SBo/nonexistentslackbuild5-1.0!); system(qw!rm -rf /tmp/SBo/nonexistentslackbuild6-1.0!); system(qw!rm -rf /tmp/SBo/weird-versionsbo-1.0!); + system(qw!rm -rf /tmp/SBo/locale-versionsbo-1.0!); system(qw!rm -rf /tmp/SBo/nonexistentslackbuild-1.1!); system(qw!rm -rf /tmp/SBo/nonexistentslackbuild2-1.1!); system(qw!rm -rf /tmp/SBo/nonexistentslackbuild4-1.1!); @@ -61,6 +64,7 @@ sub cleanup { system(qw!rm -rf /tmp/package-nonexistentslackbuild5!); system(qw!rm -rf /tmp/package-nonexistentslackbuild6!); system(qw!rm -rf /tmp/package-weird-versionsbo!); + system(qw!rm -rf /tmp/package-locale-versionsbo!); }; } @@ -129,9 +133,9 @@ sboupgrade '--all', { expected => "Checking for updated SlackBuilds...\nNothing cleanup(); -# 16: sboupgrade --all shouldn't pick up weird-versionsbo -install('LO', 'weird-versionsbo'); -sboupgrade '--all', { input => ("n\n" x (@sbos+1)), expected => sub { not /weird-versionsbo/ } }; +# 16: sboupgrade --all shouldn't pick up weird-versionsbo or locale-versionsbo +install('LO', 'weird-versionsbo', 'locale-versionsbo'); +sboupgrade '--all', { input => ("n\n" x (@sbos+1)), expected => sub { not /weird-versionsbo/ and not /locale-versionsbo/ } }; # 17-18: sboupgrade -r -f both something installed and something not installed install('LO', 'nonexistentslackbuild'); @@ -10,14 +10,18 @@ use lib $RealBin; use Test::Sbotools qw/ set_repo sbosnap /; if ($ENV{TEST_INSTALL}) { - plan tests => 3; + plan tests => 5; } else { plan skip_all => 'Only run these tests if TEST_INSTALL=1'; } sub cleanup { capture_merged { - system(qw!rm -rf !, "$RealBin/gitrepo"); + system(qw!rm -rf !, "$RealBin/gitrepo"); + if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { + system(qw!userdel test!); + system(qw!groupdel test!); + } }; } @@ -40,20 +44,39 @@ git checkout -b b1; echo 'echo "Hello World."' > test; git commit -am 'branch co git checkout master; echo 'echo "Hello World"' > test; git commit -am 'master commit'; END -set_repo("file://$RealBin/gitrepo/"); +if (defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true') { +capture_merged { system(<<"END"); }; +groupadd -g 200 test +useradd -u 200 -g 200 -d /tmp test +chown -R 200:200 $RealBin/gitrepo +END +} + +set_repo("$RealBin/gitrepo/"); # 1: sbosnap get initial repo sbosnap 'fetch', { expected => qr!Pulling SlackBuilds tree.*Cloning into '/usr/sbo/repo'!s }; +# 2-3: check ownership of repodir if under TRAVIS +SKIP: { + skip "Only run under Travis CI", 2 unless defined $ENV{TRAVIS} and $ENV{TRAVIS} eq 'true'; + + my @fnames = glob "$RealBin/gitrepo/.git/objects/*/*"; + + my @stat = stat shift @fnames; + is ($stat[4], 200, "Correct owner uid for $RealBin/gitrepo"); + is ($stat[5], 200, "Correct owner gid for $RealBin/gitrepo"); +} + # make a conflict capture_merged { system(<<"END"); }; cd "$RealBin"; cd gitrepo; git reset --hard b1 END -# 2: sbosnap update through merge conflict +# 4: sbosnap update through merge conflict sbosnap 'update', { expected => qr!Updating SlackBuilds tree.*master.*->.*origin/master.*forced update.*HEAD is now at!s }; -# 3: make sure test repo is merged correctly +# 5: make sure test repo is merged correctly is (slurp('/usr/sbo/repo/test'), <<"END", 'repo test file updated correctly'); echo "Hello World." END diff --git a/t/12-readme.t b/t/12-readme.t index ff69ac2..eb472d2 100755 --- a/t/12-readme.t +++ b/t/12-readme.t @@ -10,7 +10,7 @@ use lib $RealBin; use Test::Sbotools qw/ make_slackbuilds_txt set_lo sboinstall sboremove restore_perf_dummy /; if ($ENV{TEST_INSTALL}) { - plan tests => 10; + plan tests => 11; } else { plan skip_all => 'Only run these tests if TEST_INSTALL=1'; } @@ -19,12 +19,16 @@ sub cleanup { capture_merged { system(qw!/sbin/removepkg envsettingtest!); system(qw!/sbin/removepkg envsettingtest2!); + system(qw!/sbin/removepkg otherreadmes!); unlink "$RealBin/LO-readme/envsettingtest/perf.dummy"; unlink "$RealBin/LO-readme/envsettingtest2/perf.dummy"; + unlink "$RealBin/LO-readme/otherreadmes/perf.dummy"; system(qw!rm -rf /tmp/SBo/envsettingtest-1.0!); system(qw!rm -rf /tmp/SBo/envsettingtest2-1.0!); + system(qw!rm -rf /tmp/SBo/otherreadmes-1.0!); system(qw!rm -rf /tmp/package-envsettingtest!); system(qw!rm -rf /tmp/package-envsettingtest2!); + system(qw!rm -rf /tmp/package-otherreadmes!); }; } @@ -70,6 +74,9 @@ SKIP: { capture_merged { system(qw/ userdel test /); system(qw/ groupdel test /); }; } +# 11: sboinstall otherreadmes +sboinstall 'otherreadmes', { input => "y\ny\ny", expected => qr/It looks like.*Would you like to see.*README.*SlackBuilds[.]org.*SLACKWARE/s }; + # Cleanup END { cleanup(); diff --git a/t/32-info.t b/t/32-info.t new file mode 100644 index 0000000..91cec79 --- /dev/null +++ b/t/32-info.t @@ -0,0 +1,34 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use Test::More; + +use SBO::Lib 'parse_info'; + +plan tests => 13; + +my %parse = parse_info(<<"END"); +FOO="bar" +BAR="foo bar +baz" +BAZ="barf foof + bazf" +QUUX="finf" +END + +is ($parse{FOO}[0], 'bar', 'bar value gotten from FOO key'); +is ($parse{FOO}[1], undef, 'FOO key has correct length'); +is ($parse{BAR}[0], 'foo', 'foo value gotten from BAR key'); +is ($parse{BAR}[1], 'bar', 'bar value gotten from BAR key'); +is ($parse{BAR}[2], 'baz', 'baz value gotten from BAR key'); +is ($parse{BAR}[3], undef, 'BAR key has correct length'); +is ($parse{BAZ}[0], 'barf', 'barf value gotten from BAZ key'); +is ($parse{BAZ}[1], 'foof', 'foof value gotten from BAZ key'); +is ($parse{BAZ}[2], 'bazf', 'bazf value gotten from BAZ key'); +is ($parse{BAZ}[3], undef, 'BAZ key has correct length'); +is ($parse{QUUX}[0], 'finf', 'finf value gotten from QUUX key'); +is ($parse{QUUX}[1], undef, 'QUUX key has correct length'); +delete @parse{qw/ FOO BAR BAZ QUUX /}; +is (scalar %parse, 0, 'no additional keys were parsed'); diff --git a/t/LO-readme/otherreadmes/README b/t/LO-readme/otherreadmes/README new file mode 100644 index 0000000..6d388bb --- /dev/null +++ b/t/LO-readme/otherreadmes/README @@ -0,0 +1 @@ +This doesn't exist! diff --git a/t/LO-readme/otherreadmes/README.SBo b/t/LO-readme/otherreadmes/README.SBo new file mode 100644 index 0000000..7ff669b --- /dev/null +++ b/t/LO-readme/otherreadmes/README.SBo @@ -0,0 +1 @@ +this is the README for SlackBuilds.org diff --git a/t/LO-readme/otherreadmes/README.SLACKWARE b/t/LO-readme/otherreadmes/README.SLACKWARE new file mode 100644 index 0000000..9539839 --- /dev/null +++ b/t/LO-readme/otherreadmes/README.SLACKWARE @@ -0,0 +1 @@ +this is the README for SLACKWARE! diff --git a/t/LO-readme/otherreadmes/otherreadmes.SlackBuild b/t/LO-readme/otherreadmes/otherreadmes.SlackBuild new file mode 100644 index 0000000..4466ded --- /dev/null +++ b/t/LO-readme/otherreadmes/otherreadmes.SlackBuild @@ -0,0 +1,15 @@ +#!/bin/bash +PRGNAM="otherreadmes" +VERSION=${VERSION:-1.0} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +TMP=${TMP:-/tmp/SBo} +OUTPUT=${OUTPUT:-/tmp} + +mkdir -p $TMP/$PRGNAM-$VERSION +cp README $TMP/$PRGNAM-$VERSION +mkdir -p $OUTPUT/package-$PRGNAM/usr/doc/$PRGNAM-$VERSION +cp README $OUTPUT/package-$PRGNAM/usr/doc/$PRGNAM-$VERSION +cd $OUTPUT/package-$PRGNAM + +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-noarch-$BUILD$TAG.tgz diff --git a/t/LO-readme/otherreadmes/otherreadmes.info b/t/LO-readme/otherreadmes/otherreadmes.info new file mode 100644 index 0000000..3dcaf67 --- /dev/null +++ b/t/LO-readme/otherreadmes/otherreadmes.info @@ -0,0 +1,10 @@ +PRGNAM="otherreadmes" +VERSION="1.0" +HOMEPAGE="http://www.example.com" +DOWNLOAD="http://pink-mist.github.io/sbotools/testing/perf.dummy" +MD5SUM="9cba6c70fb57a22a155073d54748b614" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Andreas Guldstrand" +EMAIL="doesnt@matter.org" diff --git a/t/LO/locale-versionsbo/README b/t/LO/locale-versionsbo/README new file mode 100644 index 0000000..6d388bb --- /dev/null +++ b/t/LO/locale-versionsbo/README @@ -0,0 +1 @@ +This doesn't exist! diff --git a/t/LO/locale-versionsbo/locale-versionsbo.SlackBuild b/t/LO/locale-versionsbo/locale-versionsbo.SlackBuild new file mode 100644 index 0000000..f146a92 --- /dev/null +++ b/t/LO/locale-versionsbo/locale-versionsbo.SlackBuild @@ -0,0 +1,16 @@ +#!/bin/bash +PRGNAM="locale-versionsbo" +VERSION=${VERSION:-1.0} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +TMP=${TMP:-/tmp/SBo} +OUTPUT=${OUTPUT:-/tmp} +KERNEL=$(uname -r) + +mkdir -p $TMP/$PRGNAM-$VERSION +cp README $TMP/$PRGNAM-$VERSION +mkdir -p $OUTPUT/package-$PRGNAM/usr/doc/$PRGNAM-$VERSION +cp README $OUTPUT/package-$PRGNAM/usr/doc/$PRGNAM-$VERSION +cd $OUTPUT/package-$PRGNAM + +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION\_en_US-noarch-$BUILD$TAG.tgz diff --git a/t/LO/locale-versionsbo/locale-versionsbo.info b/t/LO/locale-versionsbo/locale-versionsbo.info new file mode 100644 index 0000000..787a2ef --- /dev/null +++ b/t/LO/locale-versionsbo/locale-versionsbo.info @@ -0,0 +1,10 @@ +PRGNAM="locale-versionsbo" +VERSION="1.0" +HOMEPAGE="http://www.example.com" +DOWNLOAD="http://pink-mist.github.io/sbotools/testing/perf.dummy" +MD5SUM="9cba6c70fb57a22a155073d54748b614" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Andreas Guldstrand" +EMAIL="doesnt@matter.org" |