#!/usr/local/bin/perl -w

# This program checks the list of required packages 
# and sees if any libraries are missing from the provides.
#
# On plinius, the packages created by vpkg-provides2.sh are only
# missing two "packages" required by SUNWadmap -- sysidlib and 
# sysiduilib -- both of which are in /usr/sbin/. 

use strict;
use Bootstrap;

my $missing_ver = '$Id: missing.pl,v 1.5 2001/08/17 20:16:43 sbi Exp $';

if ($#ARGV == -1 || $ARGV[0] eq "-h") {
    print <<EOF;
Usage: ./missing.pl rpms ...

$missing_ver
$bootstrap_pm_ver
EOF
    exit 0;
}

my (%provides, %mia);

my $files = join " ", @ARGV;
my $line;

open RPM, "/usr/local/bin/rpm -q -p $files --provides |"
    or die "Pipe error: $!";
while (($line = <RPM>)) {
    chomp $line;
    next if ($line =~ /rpmlib/);
    $provides{$line} = 1;
}
close RPM or die "Pipe error: $!";

open RPM, "/usr/local/bin/rpm -q -p $files --requires |"
    or die "Pipe error: $!";
while (($line = <RPM>)) {
    chomp $line;
    next if ($line =~ /rpmlib/);
    $mia{$line} = 1 unless ($provides{$line});
}  
close RPM or die "Pipe error: $!";

# This really should check to see if the shared libraries required
# by the programs in %mia are on the system.  They must be -- otherwise
# the program wouldn't run -- but RPM should know about them.

print_spec { NAME => "missing", 
	     VERSION => 1, 
	     RELEASE => 1,
	     PROVIDES => [ keys %mia ], 
	     REQUIRES => [] };
