#!/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";
