#! /usr/bin/perl -w
#------------------------------------------------------------------------------
# check-files.pl - show differences between files.txt and CVS tree
#
# usage: check-files.pl
#
# Please add package directory names to this file!
#
# Creation:    11.09.2003 jw5
# Last Update: $Id$
#------------------------------------------------------------------------------

# --- MODULES ---
use File::Find;

# --- CONFIG ---

# Subdirectories to use
@dirs = (
	"advanced_networking", "ath_pci", "avm-fcclassic", "avm-fcdsl", "avm-fcdsl2", "avm-fcdslsl",
	"avm-fcdslusb", "avm-fcpci", "avm-fcpnp", "avm-fcusb", "avm-fcusb2",
	"avm-fxusb", "base", "chrony", "cpmvrmlog", "dhcp", "djbdns",
	"doc", "dsl", "dvb", "dyneisfair", "easycron", "faxrcv", "hd", "httpd", "isdn",
	"lcd", "lpdsrv", "modem", "oidentd", "pcmcia", "ppp", "proxy", "qos", "src",
	"register", "rootfs", "samba_lpd", "serial", "shfs", "squid", "sshd", "dyndns",
	"template", "tools", "usb", "usercmd", "vpn", "wlan", "src-non-free", "avm-fcdslslusb",
);
# These are pre-compiled pattern, add new ones the same way
@ignore = (
        qr{\.svn},
        qr{src/src/buildroot/dl},
        qr{src/src/buildroot/build},
        qr{src/src/buildroot/target},
        qr{src/src/fbr/build_i386},
        qr{src/src/fbr/dl},
        qr{src/src/fbr/toolchain_build_i386},
        qr{.+~},
);
# These are the fileslists where all files should be listed...
@filelists = (
	"files.txt"
);

# --- SUBS ---
sub process_file {
	return unless -f;

	foreach $pat (@ignore) {
		return if $File::Find::name =~ /$pat/;
	}
	$real_files{$File::Find::name} = 1;
}

# --- MAIN ---

# read files.txt
print "reading file list\n";
foreach $list (@filelists) {
	open (FILES, "<", $list) or die "can't open '$list': $!";

	while (<FILES>) {
	    if (/^[bB] (.*)$/o) {
		if ( -f $1 ) { 
		    $binfiles{$1} = 1;
		}
	    }
	    /^. (.*)$/o;
	    $files{$1} = 1;
	}

	close FILES;
}

# read files in directories
print "searching for files ...\n";
find(\&process_file, @dirs);

# compare both hashes
print "Missing files:\n\n";
foreach $key (sort keys %files) {
	if (! defined ($real_files{$key})) {
		print " $key\n";
	}
}

print "\n\nNot in files.txt:\n\n";
foreach $key (sort keys %real_files) {
	if (! defined ($files{$key})) {
		print " $key\n";
	}
}

print "\n";
print "checking svn properties...\n";
foreach $key (sort keys %binfiles) {
    open (SVN, "svn pl $key |") || die "unable to fork svn";
    while (<SVN>) {
	next if /^Properties/;
	next if /svn:mime-type/;
	next if /svn:executable/;
	print "$key: Wrong Property: $_";
    }
    open (SVN, "svn pg mime-type $key |") || die "unable to fork svn";
    while (<SVN>) {
	next if /^Properties/;
	if (/svn:mime-type/) {
	    if (! /application\/octet-stream/) {
		print "$key: Wrong mime type: $_";
	    }
	}
    }
}
print "checking libc version\n";
foreach $key (sort keys %binfiles) {
    open (STRINGS, "strings $key |") || die "unable to fork strings";
    while (<STRINGS>) {
	if (/i386-linux-uclibc/) {
	    print "$key: Wrong libc versions: $_";
	}
    }
}
# vi: set ts=4 sw=4:
