]> cvs.zerfleddert.de Git - m1-debian/blob - pmdi.pl
12884d4981f7eb949c9b2a605a9ee8199644a4ba
[m1-debian] / pmdi.pl
1 #!/usr/bin/perl
2
3 # SPDX-License-Identifier: MIT
4
5 use strict;
6
7 my ($identifier, $size);
8
9 sub
10 find_identifier_before_free_space
11 {
12 my $identifier = undef;
13 my $size = undef;
14
15 for my $line (`diskutil list /dev/disk0`) {
16
17 if ($line =~ /^\s+\(free space\)\s+(\d+.\d GB)/) {
18 $size = $1;
19 $size =~ s/\s+//g;
20 last;
21 }
22
23 if ($line =~ /(disk0s\d)$/) {
24 $identifier = $1;
25 }
26 }
27
28 die if not defined $identifier;
29 die if not defined $size;
30
31 return ($identifier, $size);
32 }
33
34 ($identifier, $size) = find_identifier_before_free_space();
35 system("diskutil addPartition $identifier %EFI% LB 512MB");
36
37 $identifier = undef;
38
39 for my $line (`diskutil list /dev/disk0`) {
40 if ($line =~ /EFI.*(disk0s\d)/) {
41 $identifier = $1;
42 }
43 }
44
45 die if not defined $identifier;
46
47 system("newfs_msdos /dev/$identifier");
48 system("mkdir -p /Volumes/efi");
49 system("mount -t msdos /dev/$identifier /Volumes/efi");
50 chdir('/Volumes/efi');
51 system('mkdir -p /Volumes/efi/efi/boot');
52 system('curl -Lo /Volumes/efi/efi/boot/bootaa64.efi https://tg.st/u/grubaa64.efi');
53 system('curl -sL tg.st/u/fwx.sh | bash');
54 system('cp /tmp/linux-firmware.tar /Volumes/efi/');
55 chdir('/var/root');
56 system('umount /Volumes/efi');
57
58 ($identifier, $size) = find_identifier_before_free_space();
59 system("diskutil addPartition $identifier %Linux% %noformat% $size");
60
61 $identifier = undef;
62
63 for my $line (`diskutil list /dev/disk0`) {
64 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
65 $identifier = $1;
66 }
67 }
68
69 die if not defined $identifier;
70
71 system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");
Impressum, Datenschutz