-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmpdir
executable file
·111 lines (95 loc) · 2.14 KB
/
cmpdir
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
#!/usr/bin/perl -s
use File::Basename;
my $usage = "Usage: cmpdir [-v] [-h] dir1 dir2\n";
my $verbose=0;
if ($ARGS[0] eq "-v") {
$verbose = 0;
shift @ARGV;
}
if ($ARGV[0] eq "-h") {
print "Help: ", $usage;
exit(0);
}
if (scalar @ARGV != 2) {
die $usage;
}
my $src = $ARGV[0];
my $dest = $ARGV[1];
my %md5 = ();
my $esc = chr(27);
my $red = "${esc}[41m";
my $yellow = "${esc}[43m";
my $off = "${esc}[m";
-d $src || die "Source not a directory: $src\n";
-d $dest || die "Dest not a directory: $dest\n";
my $dir;
chomp($dir = `pwd`);
chdir($src) || die "Can't cd to $src: $!\n";
my @files = `find . -type f \! -name '.*'`;
chomp(@files);
chdir($dir);
chdir($dest) || die "${red}Can't cd top $dest: $!{$off}\n";
my $width = 100;
my @missing=();
print "# scanning ${yellow}${dest}${off}\n";
my $count=0;
my $lines=1;
print " 1 ";
foreach $file (sort @files) {
print ".";
$count++;
if($count % $width == 0) {
$lines++;
print "\n";
printf("%2d ", $lines);
}
next if $file =~ /\.DS_Store/;
$file =~ s#^\./##;
my $dir = dirname($file);
my $base = basename($file);
$base =~ s#^\.(.*).icloud$#\1#;
if($f) {
if(-r "$file") {
print "found - $file\n" if $v;
} elsif(-r "$dir/.$base.icloud") {
print "iCloud - $file\n";
} else {
push @missing, $file;
next;
}
} else {
$md5{$file} = `md5 -q "$file"`;
chomp($md5{$file});
}
}
exit(0) if $f;
chdir($dir);
chdir($src) || die "Can't cd to $src: $!\n";
print "\n";
print "\n# scanning ${yellow}${src}${off}\n" if $verbose;
my @keys = sort keys %md5;
my @matches=();
my @mismatches=();
foreach $file (@keys) {
next if /\.DS_Store/;
$file =~ s#\./##;
next if $file =~ /^\./;
my $check = `md5 -q "$file" 2>/dev/null`;
chomp($check);
if($check eq $md5{$file}) {
print "✅";
push @matches, $file;
# print "### ✅ matches $md5{$file}: $file\n";
}
else {
print "❌";
push @mismatches, $file;
# print "### ❌ no match $file\n");
}
print "\n" if (scalar(@matches) + scalar(@mismatches)) % $width == 0;
}
print "\n";
print "Missing:\n";
print join("\n", @missing), "\n\n";
print "Mismatches:\n";
print join("\n", @mismatches), "\n\n";