| 1 |
#!/opt/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Digest::SHA (); |
| 6 |
use File::Copy (); |
| 7 |
use File::Path (); |
| 8 |
use File::Temp (); |
| 9 |
|
| 10 |
my $version = shift || "9.0.4"; |
| 11 |
$version =~ /^9\.\d+\.\d+$/ && !@ARGV |
| 12 |
or die "Usage: perl fetch-binaries [9.x.y]\n"; |
| 13 |
|
| 14 |
my %platforms = ( |
| 15 |
"linux-x86_64" => "Linux64-intel-dyn", |
| 16 |
"linux-aarch64" => "Linux64-arm-dyn", |
| 17 |
"linux-riscv64" => "Linux64-riscv-dyn", |
| 18 |
"darwin-universal" => "Darwin64-universal-dyn", |
| 19 |
"mswin32-x86_64" => "win64-intel-dyn.exe", |
| 20 |
"mswin32-x86" => "win32-intel-dyn.exe", |
| 21 |
); |
| 22 |
|
| 23 |
my %bundled = map { $_ => 1 } qw(linux-x86_64 darwin-universal mswin32-x86_64); |
| 24 |
my $tmp = File::Temp::tempdir (CLEANUP => 1); |
| 25 |
my $url = "https://www.bawt.tcl3d.org/download/Tclkits/tclkits-$version.7z"; |
| 26 |
|
| 27 |
system "curl", "-fL", "-o", "$tmp/kits.7z", $url |
| 28 |
and die "Download failed: $url\n"; |
| 29 |
|
| 30 |
system "7z", "e", "-y", "-o$tmp", "$tmp/kits.7z", |
| 31 |
map "tclkits-$version/tclkit-$version-$_", values %platforms |
| 32 |
and die "Extraction failed\n"; |
| 33 |
|
| 34 |
mkdir "$tmp/prebuilt" or die $!; |
| 35 |
mkdir "$tmp/wwwdist" or die $!; |
| 36 |
|
| 37 |
my %digests; |
| 38 |
|
| 39 |
for my $platform (sort keys %platforms) { |
| 40 |
my $file = "$tmp/tclkit-$version-$platforms{$platform}"; |
| 41 |
|
| 42 |
open my $fh, "<:raw", $file or die "$file: $!\n"; |
| 43 |
my $digest = $digests{$platform} = Digest::SHA->new (384)->addfile ($fh)->hexdigest; |
| 44 |
close $fh; |
| 45 |
|
| 46 |
my $dir = $bundled{$platform} ? "prebuilt" : "wwwdist"; |
| 47 |
my $name = "alien-tclsh9-$platform-$digest"; |
| 48 |
|
| 49 |
File::Copy::copy ($file, "$tmp/$dir/$name") or die "copy $file: $!\n"; |
| 50 |
print "$dir/$name\n"; |
| 51 |
} |
| 52 |
|
| 53 |
# replace only our generated binaries, not unrelated files in these directories |
| 54 |
for my $dir (qw(prebuilt wwwdist)) { |
| 55 |
File::Path::make_path ($dir); |
| 56 |
|
| 57 |
for my $file (glob "$dir/alien-tclsh9-*") { |
| 58 |
unlink $file or die "unlink $file: $!\n"; |
| 59 |
} |
| 60 |
|
| 61 |
for my $file (glob "$tmp/$dir/*") { |
| 62 |
File::Copy::copy ($file, $dir) or die "copy $file: $!\n"; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
open my $fh, ">", "binaries.pl" or die "binaries.pl: $!\n"; |
| 67 |
print $fh "# generated by fetch-binaries\n+{\n version => \"$version\",\n binaries => {\n"; |
| 68 |
printf $fh " %-20s => \"%s\",\n", "\"$_\"", $digests{$_} for sort keys %digests; |
| 69 |
print $fh " },\n}\n"; |
| 70 |
close $fh or die "binaries.pl: $!\n"; |
| 71 |
|
| 72 |
open $fh, "<", "MANIFEST" or die "MANIFEST: $!\n"; |
| 73 |
my @manifest = grep !m{^prebuilt/alien-tclsh9-}, <$fh>; |
| 74 |
close $fh; |
| 75 |
|
| 76 |
open $fh, ">", "MANIFEST" or die "MANIFEST: $!\n"; |
| 77 |
print $fh @manifest, map "$_\n", sort glob "prebuilt/alien-tclsh9-*"; |
| 78 |
close $fh or die "MANIFEST: $!\n"; |