Documentation/scripts/prtcheckmissing

51 lines
1.2 KiB
Plaintext
Raw Normal View History

#!/usr/bin/perl
#
# $Id: prtcheckmissing,v 1.1 2003/10/27 15:26:50 opel Exp $
# prtcheckmissing,v 1.2 2022/05/31 18:41:19 jmq Exp $
use strict;
use warnings;
my @mask = parse_pkgadd_conf();
open (my $dbh, "/var/lib/pkg/db") or die "Could not read package database!\n";
local $/ = ""; # read files paragraph-wise; see ``perldoc perlvar''
while(<$dbh>) {
my ($name, $version, @files) = split /\n/;
# apply the pkgadd rules to eliminate false positives
my @missing = grep { (! -e "/$_") && wanted($_, @mask) } @files;
# final report for this package
next if not @missing;
print map "/$_ $name\n", @missing;
}
close($dbh);
sub parse_pkgadd_conf {
my @unwanted;
local $/ = "\n";
open my $pah, "< /etc/pkgadd.conf"
or die "Couldn't open pkgadd install rules!\n";
while(<$pah>) {
next if /^\s*#/ or /^$/;
my ($event, $pattern, $choice) = split;
push (@unwanted, qr/$pattern/s) if ($event eq "INSTALL" and $choice eq "NO");
}
close ($pah);
return @unwanted;
}
sub wanted {
my $testfile = shift;
my $retval = 1;
while (my $regexp=shift) {
$retval = 0 if $testfile =~ $regexp;
last if $retval==0;
}
return $retval;
}