File: CheckSum.pl

package info (click to toggle)
otrs2 2.2.7-2lenny3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 13,444 kB
  • ctags: 5,808
  • sloc: perl: 129,825; xml: 16,139; sql: 11,400; sh: 1,198; makefile: 31; php: 16
file content (131 lines) | stat: -rwxr-xr-x 3,794 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl -w
# --
# bin/CheckSum.pl - a tool to compare changes in a installation
# Copyright (C) 2001-2007 OTRS GmbH, http://otrs.org/
# --
# $Id: CheckSum.pl,v 1.6 2007/03/04 23:59:50 martin Exp $
# --
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# --

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin)."/Kernel/cpan-lib";

use strict;

use vars qw($VERSION $RealBin);
$VERSION = '$Revision: 1.6 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;

use Getopt::Std;
use Digest::MD5 qw(md5_hex);

my $Start = $RealBin.'/../';
my $Archive = '';
my $Action = 'compare';
my %Compare = ();

# get options
my %Opts = ();
getopt('habd', \%Opts);
if ($Opts{'h'}) {
    print "CheckSum.pl <Revision $VERSION> - OTRS check sum\n";
    print "Copyright (c) 2001-2006 OTRS GmbH, http://otrs.org/\n";
    print "usage: CheckSum.pl -a create|compare [-b /path/to/ARCHIVE] [-d /path/to/framework]\n";
    exit 1;
}

if ($Opts{'a'} && $Opts{'a'} eq 'create') {
    $Action = $Opts{'a'};
}
if ($Opts{'d'}) {
    $Start = $Opts{'d'};
}
if ($Opts{'b'}) {
    $Archive = $Opts{'b'};
}
else {
    $Archive = $Start.'ARCHIVE';
}

if ($Action eq 'create') {
    print "Writing $Archive ...";
    open(OUT, "> $Archive") || die "ERROR: Can't open: $Archive";
}
else {
    open(IN, "< $Archive") || die "ERROR: Can't open: $Archive";
    while (<IN>) {
        my @Row = split(/::/, $_);
        chomp($Row[1]);
        $Compare{$Row[1]} = $Row[0];
    }
    close(IN);
}

my @Dirs = ();
R($Start);
foreach my $File (sort keys %Compare) {
#    print "Notice: Removed $Compare{$File}\n";
    print "Notice: Removed $File\n";
}
if ($Action eq 'create') {
    print " done.\n";
    close(OUT);
}

sub R {
    my $In = shift;
    my @List = glob("$In/*");
    foreach my $File (@List) {
        $File =~ s/\/\//\//g;
        if (-d $File && $File !~ /CVS/ && $File !~ /^doc\// && $File !~ /^var\/tmp/) {
            R($File);
            $File =~ s/$Start//;
#            print "Directory: $File\n";
        }
        else {
            my $OrigFile = $File;
            $File =~ s/$Start//;
            $File =~ s/^\/(.*)$/$1/;
#            print "File: $File\n";
            if ($File !~ /Entries|Repository|Root|CVS|ARCHIVE/ && $File !~ /^doc\// && $File !~ /^var\/tmp/) {
                my $Content = '';
                open (IN, "< $OrigFile") || die "ERROR: $!";
                while (<IN>) {
                    $Content .= $_;
                }
                close (IN);
                my $Digest = md5_hex($Content);
                if ($Action eq 'create') {
                    print OUT $Digest.'::'.$File."\n";
                }
                else {
                    if (! $Compare{$File}) {
                        print "Notice: New $File\n";
                    }
                    elsif ($Compare{$File} ne $Digest) {
                        print "Notice: Dif $File\n";
                    }
                    if (defined($Compare{$File})) {
                        delete $Compare{$File};
                    }
                }
            }
        }
    }
}