]> git.zerfleddert.de Git - m1-debian/blob - m1di.pl
add todos
[m1-debian] / m1di.pl
1 #!/usr/bin/perl
2
3 # Todo:
4 # Create an exclude identifier list of all Apple volumes and build a safetey check
5 # Detect if the paritions already exist and offer to reinstall system
6 # Let the use pick between u-boot and untethered m1n1
7 # Check that there is at least 1.5 GB space
8 # Make sure that there is only one free region
9
10 use strict;
11
12 my ($identifier, $size);
13
14 sub
15 find_identifier_before_free_space
16 {
17 my $identifier = undef;
18 my $size = undef;
19
20 for my $line (`diskutil list /dev/disk0`) {
21
22 if ($line =~ /^\s+\(free space\)\s+(\d+.\d GB)/) {
23 $size = $1;
24 $size =~ s/\s+//g;
25 last;
26 }
27
28 if ($line =~ /(disk0s\d)$/) {
29 $identifier = $1;
30 }
31 }
32
33 die if not defined $identifier;
34 die if not defined $size;
35
36 return ($identifier, $size);
37 }
38
39 ($identifier, $size) = find_identifier_before_free_space();
40 system("diskutil addPartition $identifier %EFI% LB 512MB");
41
42 $identifier = undef;
43
44 for my $line (`diskutil list /dev/disk0`) {
45 if ($line =~ /EFI.*(disk0s\d)/) {
46 $identifier = $1;
47 }
48 }
49
50 die if not defined $identifier;
51
52 system("newfs_msdos /dev/$identifier");
53 system("mkdir -p /Volumes/efi");
54 system("mount -t msdos /dev/$identifier /Volumes/efi");
55 chdir('/Volumes/efi');
56 system('mkdir -p /Volumes/efi/efi/boot');
57 system('curl -Lo /Volumes/efi/efi/boot/bootaa64.efi https://tg.st/u/grubaa64.efi');
58 system('curl -sL tg.st/u/fwx.sh | bash');
59 system('cp /tmp/linux-firmware.tar /Volumes/efi/');
60 chdir('/var/root');
61 system('umount /Volumes/efi');
62
63 ($identifier, $size) = find_identifier_before_free_space();
64 system("diskutil addPartition $identifier %Linux% %noformat% $size");
65
66 $identifier = undef;
67
68 for my $line (`diskutil list /dev/disk0`) {
69 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
70 $identifier = $1;
71 }
72 }
73
74 die if not defined $identifier;
75
76 system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");
Impressum, Datenschutz