Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 106 lines (81 sloc) 2.186 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#!/usr/bin/perl

use strict;
use warnings;

use Parse::RPM::Spec;

my $spec = shift || die "No spec given\n";

my $s = Parse::RPM::Spec->new({ file => $spec });

my $rpm_cmd = 'rpm -q --whatprovides';
my $repo_cmd = 'repoquery -C --whatprovides';
my $format = q(--queryformat='%{name}~%{version}~%{vendor}');

my (@ok, @errs);

my %req = map { $_ => 1 } (@{$s->requires}, @{$s->buildrequires});

foreach (sort keys %req) {
  my ($cap, $op, $ver) = split;

  my $err;
  $err->{cap} = $cap;

  next if $cap =~ /COMPAT/;

  my $rpm_out = run_cmd("$rpm_cmd $format '$cap'");

  if ($rpm_out =~ /no package provides/i) {
    $err->{not_installed} = 1;
    $err->{ver_req} = $ver;
  } else {
    my ($rpm_name, $rpm_ver, $rpm_vend) = split /~/, $rpm_out;

    if (defined $ver) {
      if ($rpm_ver < $ver) {
$err->{rpm} = $rpm_name;
$err->{vnd_cur} = $rpm_vend;
$err->{ver_cur} = $rpm_ver;
$err->{ver_req} = $ver;
      } else {
push @ok, $cap;
next;
      }
    } else {
      push @ok, $cap;
      next;
    }
  }

  my $repo_out = run_cmd("$repo_cmd $format '$cap'");
  $repo_out =~ s/\|\|//;

  if ($repo_out) {

    my ($repo_name, $repo_ver, $repo_vend) = split /~/, $repo_out;

    $err->{ava_rpm} = $repo_name;
    $err->{ava_ver} = $repo_ver;
    $err->{ava_vnd} = $repo_vend;

    if (defined $ver and $ver > $repo_ver) {
      $err->{diy} = 1;
    }
  } else {
    $err->{diy} = 1;
  }

  push @errs, $err;
}

unless (@errs) {
  print "All dependencies satisfied\n";
} else {
  print "The following dependencies are missing:\n";
  foreach (@errs) {
    print $_->{cap}, "\n";
    print 'You need ';
    print "$_->{ver_req} of " if $_->{ver_req};
    print "$_->{cap}.\n";
    print "You have $_->{ver_cur}\n" if $_->{ver_cur};
    if ($_->{diy}) {
      print "You'll have to build it yourself\n";
      if ($_->{ava_name}) {
print "The most recent version available is $_->{ava_ver}\n";
print "from $_->{ava_vnd}.\n";
      }
    } else {
      print "You can get $_->{ava_rpm} version $_->{ava_ver} ",
"from $_->{ava_vnd}\n";
    }
    print "\n";
  }
}

sub run_cmd {
  my $cmd = shift;

  # print "[$cmd]\n";

  chomp (my $output = `$cmd`);

  return $output;
}
Something went wrong with that request. Please try again.