yhdev/dllink.pl
Yorhel de0227cdbd Add file download information window + SHA-256 + more checksums
I'm not the biggest fan of how the info window works, but it works
anyway, and it's easy to apply to *all* the download links.

Also decided to sign & checksum static binaries. Those are just as
important (if not more so) than the source tarballs.

Yes, I did verify that my copies of all the files were still in line
with the other checksums before creating the SHA256 checksums. :)

And I think I'm done fiddling with the site now; This is the last of my
planned changes. ...except that the site kinda sucks in text-mode
browsers now. Hmm. But how do I improve that?
2019-03-26 19:05:20 +01:00

36 lines
1.5 KiB
Perl
Executable file

#!/usr/bin/perl -p
# This script adds an information icon to any link into /download/* - if there
# is more information to display than just the file name and size.
use autodie;
sub slurp { local $/=undef; open F, '<', shift; <F> }
sub fullsize { scalar reverse join ".", unpack "(A3)*", reverse shift }
sub size { $s=shift; $s > 1<<20 ? sprintf '%.1f MiB', $s/(1<<20) : sprintf '%.1f KiB', $s/1024 }
sub file {
($code, $lbl, $fn) = @_;
my @info;
push @info, sprintf '<em>PGP:</em> <a href="/download/%s.asc">%1$s.asc</a>', $fn if -e "$fn.asc";
push @info, sprintf '<em>MD5:</em> <code>%s</code>', (slurp "$fn.md5") =~ /^([^ ]+)/ if -e "$fn.md5";
push @info, sprintf '<em>SHA1:</em> <code>%s</code>', (slurp "$fn.sha1") =~ /^([^ ]+)/ if -e "$fn.sha1";
push @info, sprintf '<em>SHA-256:</em> <code>%s</code>', (slurp "$fn.sha256") =~ /^([^ ]+)/ if -e "$fn.sha256";
return $code if !@info;
unshift @info, sprintf '<em>Size:</em> %s (%s bytes)', size(-s $fn), fullsize(-s $fn);
unshift @info, sprintf '<em>File:</em> <a href="/download/%s">%1$s</a>', $fn;
$id = sprintf 'fileinfo_%d', rand 1<<32;
qq{<span class="fileinfo">}
. qq{<input id="$id" type="checkbox">}
. qq{<span>}
. qq{<label for="$id">close</label>}
. join('<br>', @info)
. qq{</span>}
. $code
. qq{ <label for="$id"><img src="/img/info.svg"></label>}
.qq{</span>}
}
BEGIN { chdir 'pub/download' }
s{\[([^\]]+)\]\(/download/([^\) ]+)\)}{file $&,$1,$2}eg;