display and/or create md5sum in user.md5 xattr master
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 21 May 2012 16:02:12 +0000 (18:02 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 21 May 2012 16:15:07 +0000 (18:15 +0200)
md5-attr.pl [new file with mode: 0755]

diff --git a/md5-attr.pl b/md5-attr.pl
new file mode 100755 (executable)
index 0000000..d60b58c
--- /dev/null
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use autodie;
+use File::Find;
+use IPC::System::Simple qw(system capture);
+
+my @dirs = @ARGV;
+@dirs = ( '.' ) unless @dirs;
+my @created;
+
+sub md5sum {
+       my $path = shift;
+       my $md5;
+       eval { $md5 = capture( qw{attr -q -g md5}, $path ) };
+       if ( $md5 =~ /^[0-9a-fA-F]{32}$/ ) {
+               print "$md5  $path\n";
+       } else {
+               warn "# md5sum $path\n";
+               my $line = capture( 'md5sum', $path );
+               ($md5) = split(/\s+/, $line, 2);
+               system( qw{attr -q -s md5 -V}, $md5, $path );
+               warn "# $md5 $path\n";
+               push @created, $path;
+               print "$md5  $path\n";
+       }
+}
+
+find({
+       wanted => sub { md5sum $_ if -f $_ },
+       no_chdir => 1,
+}, @dirs );
+
+warn "# created md5sum for:\n", join("\n", @created), "\n";