Add domd5sums.pl
[ambdownload.git] / domd5sums.pl
diff --git a/domd5sums.pl b/domd5sums.pl
new file mode 100755 (executable)
index 0000000..3ad6175
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+use File::stat;
+use strict;
+use warnings;
+
+use File::Basename;
+use File::stat;
+use MIME::Base64;
+use File::Spec;
+use File::Spec::Functions qw(rel2abs);
+
+my $datadir = dirname(rel2abs($0))."/";
+
+sub getfile
+{
+    my $fn = $datadir.(shift @_);
+    $fn = File::Spec->rel2abs( readlink($fn) ) if (-l $fn);
+    return undef unless ( -f $fn);
+    return $fn;
+}
+
+my $dir;
+opendir($dir, $datadir);
+my @links = grep { /^[^.]/ && -l $datadir.$_ } readdir($dir);
+closedir($dir);
+foreach my $link (@links) {
+    my $target = getfile($link);
+    next unless ( defined ($target) && -f $target);
+    next unless ( $datadir eq dirname($target)."/" );
+    system ("md5sum '$target' | tee '$target.md5sum'");
+}