#! /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", "wrap", "kernel-modules-extra",
	"doc", "dsl", "dvb", "dyneisfair", "easycron", "faxrcv", "hd", "httpd", "isdn",
	"lcd", "lirc", "lpdsrv", "modem", "oidentd", "pcmcia", "ppp", "proxy", "qos", "src",
	"register", "rootfs", "samba_lpd", "serial", "shfs", "squid", "sshd", "dyndns",
	"template", "tools", "usb", "usercmd", "openvpn", "wlan", "src-non-free", "avm-fcdslslusb",
	"xen-kernel", "rrdtool", "rsync", "smbfs", "surfstation", "cipe"
);
# 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/kernel-2.4/out/},
        qr{src/src/kernel-2.4/linux-.+.bz2},
        qr{src/src/kernel-2.4/linux-.+/},
        qr{src/src/kernel-2.4/build-.+/},
        qr{src/src/kernel-2.4/drivers/build-.+/},
        qr{src/src/kernel-2.4/drivers/avm-.+},
        qr{src/src/kernel-2.4/drivers/avm/},
        qr{src/src/kernel-2.4/drivers/avm.sh},
        qr{src/src/kernel-2.4/drivers/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";
	}
}

if (@ARGV == 0) {

    print "\n\nGetting svn state of files ...\n";
    open (SVN, "svn status -v |") || die "unable to fork svn";
    while (<SVN>) {
	chomp;
	if (/^[^?].*/) {
	    /.*\s+(\S+)$/;
	    $file=$1;
	    if ($file ne ".") {
		$svn_files{$file} = 1 ;
	    }
	}
    }
    
# compare both hashes
    print "Files not in repository:\n\n";
    foreach $key (sort keys %files) {
	if (! defined ($svn_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: $_";
	}
	if (/libc.so.[56]/) {
	    print "$key: Wrong libc versions: $_";
	}
    }
}
# vi: set ts=4 sw=4:
