diff --git a/scripts/prtcheckmissing b/scripts/prtcheckmissing index cea9351..34d12e5 100755 --- a/scripts/prtcheckmissing +++ b/scripts/prtcheckmissing @@ -1,27 +1,47 @@ #!/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 $ +# prtcheckmissing,v 1.3 2023/03/25 15:55:20 jmq Exp $ use strict; use warnings; -my @missing; +my @installed; my @regfiles; my @symlinks; my @missingReg; my @missingSym; my @mask = parse_pkgadd_conf(); -local $/ = ""; # read files paragraph-wise; see ``perldoc perlvar'' - -open my $dbh, "< /var/lib/pkg/db" - or die "Couldn't open package database!\n"; - -while(<$dbh>) { - my ($pkg_name, $pkg_version, @pkg_file) = split /\n/; - @missing = grep { (! -e "/$_") && wanted($_, @mask) } @pkg_file; - next if not @missing; - - print map "/$_ $pkg_name\n", @missing; +open(PORTLIST,"-|","prt-get printf '%i:%p/%n\n'"); +while () { + push(@installed,$1) if m/^yes:(.+)/; +} + +foreach (@installed) { + local $/ = ""; # read files paragraph-wise; see ``perldoc perlvar'' + my $pf = "$_/.footprint"; + my $pkg_name = (split /\//)[-1]; + open (my $dbh, $pf) + or die "Could not read $pf !\n"; + while(<$dbh>) { + my @pkg_file = split /\n/; + + # erase the annotations that appear in the footprint + foreach (@pkg_file) { s/ \(EMPTY\)//; s/ \([0-9]+, [0-9]+\)//; } + + # extract the paths, ignoring fields for mode and uid/gid + @symlinks = map {(split /[\t ]/, $_)[2]} grep {m/ -> /} @pkg_file; + @regfiles = map {(split /\t/, $_)[2]} grep { !m/ -> / } @pkg_file; + + # apply the pkgadd rules to eliminate false positives + @missingSym = grep { (! -e "/$_") && wanted($_, @mask) } @symlinks; + @missingReg = grep { (! -e "/$_") && wanted($_, @mask) } @regfiles; + + # final report for this package + next if ((not @missingSym) and (not @missingReg)); + print map "/$_ $pkg_name\n", @missingReg if (@missingReg); + print map "/$_ $pkg_name\n", @missingSym if (@missingSym); + } + close($dbh); } - -close($dbh); sub parse_pkgadd_conf { my @unwanted;