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