#!/usr/bin/perl ########################################################################## # Artistic license (same as Perl) # Author: Alexander Kuehn # Purpose: This script will scan through all installed ports and run # ldd against all ELF files (executeables, shared objects, etc.) # it will report the port and the file of that port which has # unresolved libs. # PORTSDIR is assumed to be /usr/local but can be overwritten # by setting it as environment variable. # The output of the script can be parsed like this to # reinstall all broken ports automatically: # checkports2.pl|grep fail|sed -e s:/var/db/pkg/::g |\ # awk '{print $1}'|xargs portupgrade -fO # Usage: perl checkports.pl # Notes: The script will ignore all files in the include/ and share/locale/ # subdirectories to save some time. use strict; use Data::Dumper; my $portsdir=(defined $ENV{"PORTSDIR"}) ? $ENV{"PORTSDIR"} : '/usr/local'; for my $port (`find /var/db/pkg -type d -name \\\*-\\\*`) { chomp($port); print "$port : "; my $res="ok"; my @content=`grep -v "^@" $port/+CONTENTS`; my @content2=grep(!/^include\//, @content); @content=grep(!/^share\/locale\//, @content2); @content2=(); for (@content) { my $curfile="$portsdir/$_"; chomp($curfile); next unless -f $curfile; open FILE, "<$curfile" || die ("error opening $curfile : $!"); my $header; read FILE,$header,4; close FILE; if($header =~ /.ELF/) { @content2=grep(/=>\ not\ found\ \(0x0\)$/, `ldd $curfile 2>/dev/null`); if($#content2 >= 0) { $res="fail ($curfile)"; last; } } } print "$res\n"; }