#!/sw/bin/perl -w
use strict;
# By: Ventz Petkov
# Date: 7-08-05
##################################################

use Cwd; #dirname = cwd()
my ($dirname, $file, $temp, $temp2, $size1, $size2, $thediff, $loc1, $loc2);
my ($line, $line2, $line3, $line4, $line5, $line6, $line7);
my (@results, @results2, @results3, @thediff);
my (@lsresults, @lsresults2, @lsresults3, @lsresults4);
my (@t, $t, @t2, $t2);

my $LIVE_SERVER = "/webvols/webs/dev-htdocs";
my $DEV_SERVER = "/webvols/webs/live-htdocs";
my $DIFF = "/usr/bin/diff";
my $LS = "/bin/ls";

##################################################

open(OUTPUT, "$DIFF --suppress-common-lines -r $LIVE_SERVER $DEV_SERVER |");
while ($line = <OUTPUT>) { push(@results, $line); @results3 = @results2 = @results; }
close(OUTPUT);

print "Stuff ONLY in live-htdocs:\n--------------------------\n";
foreach $line (@results) {
    if ($line =~ s/Only in // && $line =~ s/: /\// && $line =~ /live-htdocs/) {
        chomp($line); $line = "\"".$line."\"";
        $temp = $line; chomp($temp);
        @t = split("\"", $temp, 3);
        if ( -d ($t[1]) ) { print "$t[1]\n"; }
        else {
            open(LS, "$LS -alh $line |"); $line2 = <LS>; close(LS);
            @lsresults = split(" ", $line2, 9);
            chomp($lsresults[8]);
            print "$lsresults[8] || ";
            print "User: $lsresults[2] || ";
            print "Size:  $lsresults[4] || ";
            print "Date: $lsresults[5] $lsresults[6] $lsresults[7]\n";
        }
    }
} 

print "\n\nStuff ONLY in dev-htdocs:\n--------------------------\n";
foreach $line3 (@results2) {
    if ($line3 =~ s/Only in // && $line3 =~ s/: /\// && $line3 =~ /dev-htdocs/) {
        chomp($line3); $line3 = "\"".$line3."\"";
        $temp2 = $line3; chomp($temp2);
        @t = split("\"", $temp2, 3);
        if ( -d ($t[1]) ) { print "$t[1]\n"; }
        else {
            open(LS2, "$LS -alh $line3 |"); $line4 = <LS2>; close(LS2);
            @lsresults2 = split(" ", $line4, 9);
            chomp($lsresults2[8]);
            print "$lsresults2[8] || ";
            print "User: $lsresults2[2] || ";
            print "Size:  $lsresults2[4] || ";
            print "Date: $lsresults2[5] $lsresults2[6] $lsresults2[7]\n";
        }   
    }
} 


print "\n\nStuff that differs in Size:\n---------------------------\n";
foreach $line5 (@results3) {
    if ($line5 =~ /^diff/) {
        @thediff = split("/", $line5);
        $loc2 = "/".$thediff[5]."/".$thediff[6]."/".$thediff[7]."/".$thediff[8];
        $loc1 = "/".$thediff[1]."/".$thediff[2]."/".$thediff[3]."/".$thediff[4];
        chomp($loc2); $loc2 = "\"".$loc2."\"";
        chop($loc1); $loc1 = "\"".$loc1."\""; # must be chop and NOT chomp
        
        @t2 = split("\"", $loc2, 3);
        @t = split("\"", $loc1, 3);
        print $t2[1]; print " and "; print $t[1]; print "\n";
       
        open(LS3, "$LS -alh $loc1 |"); $line6 = <LS3>; close(LS3);
        open(LS4, "$LS -alh $loc2 |"); $line7 = <LS4>; close(LS4);
        
        @lsresults3 = split(" ", $line6, 9); $size1 = $lsresults3[4];
        @lsresults4 = split(" ", $line7, 9); $size2 = $lsresults4[4];

        print "\tFile in Live is: $size2 || File in Dev is: $size1\n";
    }
}

        
##################################################

#open(FP, ">$ARGV[0]") or die "Can't open file $ARGV[0]: $!\n";
#print FP "blah\n";
#close(FP);

#$dirname = cwd();
#opendir(DIR, $dirname) or die "Can't Open $dirname: $!";
#while( defined($file = readdir DIR) ) {
#    print "$file\n";
#}
#closedir(DIR);
