-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdl.pl
executable file
·99 lines (85 loc) · 2.54 KB
/
dl.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/perl -w
# Copyright (c) 2024 Dry Ark LLC
use strict;
use lib 'mod';
use Ujsonin;
use Util qw/print_progress bytesToHR read_file/;
use Data::Dumper;
use File::Path qw/make_path/;
my $bottleDir = glob( "~/.minibrew/cache" );
if( ! -d $bottleDir ) {
make_path( $bottleDir );
}
my $arch = `uname -m`;
$arch =~ s/\n//;
my $macosVersion = `sw_vers -productVersion`;
my $major = $macosVersion;
$major =~ s/\..+//;
my $plat = "";#"ventura";
if( $arch eq 'arm64' ) {
$plat = "arm64_";
}
if( $major == 12 ) { $plat .= "monterey"; }
elsif( $major == 13 ) { $plat .= "ventura"; }
elsif( $major == 14 ) { $plat .= "sonoma"; }
else {
print "MacOS older than monterey(12) or newer than sonoma(14)\n";
exit;
}
my $doneSize = 0;
my $totSize = 0;
my $dlTot = 0;
if( ! -e "/usr/bin/install_name_tool" ) {
if( ! -e "./install_name_tool.tar.xz" ) {
`curl --progress-bar --location https://github.com/dryark/cctools-port/releases/download/986/install_name_tool.tar.xz -o install_name_tool.tar.xz`;
}
if( ! -e "./install_name_tool" ) {
`tar -xf install_name_tool.tar.xz`;
}
}
download_plat( $plat );
sub download_plat {
my $plat = shift;
my $root = Ujsonin::parse_file( "dlinfo.json" );
my $root2 = Ujsonin::parse_file( "dlsize.json" );
my $pkgs = $root->{pkgs};
my $shas = $root2->{sha256};
for my $pkg ( @$pkgs ) {
my $plats = $pkg->{platforms};
my $sha = $plats->{ $plat } || $plats->{all};
#print "$name - $sha\n";
my $size = $shas->{ $sha };
if( !$size ) {
print "Could not find size for $sha\n";
}
$totSize += $size;
}
print "Total size of packages to download: ".bytesToHR( $totSize )."\n";
print "Downloading raw brew packages...\n";
print_progress( 0 );
for my $pkg ( @$pkgs ) {
my $name = $pkg->{name};
my $plats = $pkg->{platforms};
my $sha = $plats->{ $plat } || $plats->{all};
my $size = $shas->{ $sha };
#print "$name - $sha\n";
$dlTot += $size;
ghcr_dl( $pkg->{url}.$sha, "$bottleDir/$name-$sha.tar.gz", $size );
}
print "\n";
}
sub ghcr_dl {
my ( $url, $out, $size ) = @_;
if( ! -e "$out" ) {
my $cmd = "./curlprog \"$url\" \"$out\"";
open my $cmdfh, '-|', $cmd;
while( my $line = <$cmdfh> ) {
if( $line =~ m/^[0-9]+$/ ) {
$doneSize += $line;
print_progress( int( ($doneSize/$totSize)*100 ) );
next;
}
print "Line: $line\n";
}
}
}