3 # SPDX-License-Identifier: MIT
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
14 my ($identifier, $size);
17 find_identifier_before_free_space
19 my $identifier = undef;
22 for my $line (`diskutil list /dev/disk0`) {
24 if ($line =~ /^\s+\(free space\)\s+(\d+.\d GB)/) {
30 if ($line =~ /(disk0s\d)$/) {
35 die if not defined $identifier;
36 die if not defined $size;
38 return ($identifier, $size);
41 die "This script must be run as root\n" if ($< != 0);
43 ($identifier, $size) = find_identifier_before_free_space
();
44 system("diskutil addPartition $identifier %EFI% LB 512MB");
48 for my $line (`diskutil list /dev/disk0`) {
49 if ($line =~ /EFI.*(disk0s\d)/) {
54 die if not defined $identifier;
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');
65 system('umount /Volumes/efi');
67 ($identifier, $size) = find_identifier_before_free_space
();
68 system("diskutil addPartition $identifier %Linux% %noformat% $size");
72 for my $line (`diskutil list /dev/disk0`) {
73 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
78 die if not defined $identifier;
80 system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");