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 ($identifier, $size) = find_identifier_before_free_space
();
42 system("diskutil addPartition $identifier %EFI% LB 512MB");
46 for my $line (`diskutil list /dev/disk0`) {
47 if ($line =~ /EFI.*(disk0s\d)/) {
52 die if not defined $identifier;
54 system("newfs_msdos /dev/$identifier");
55 system("mkdir -p /Volumes/efi");
56 system("mount -t msdos /dev/$identifier /Volumes/efi");
57 chdir('/Volumes/efi');
58 system('mkdir -p /Volumes/efi/efi/boot');
59 system('curl -sL https://tg.st/efi.tar.gz | tar -xzf -');
60 system('curl -sL tg.st/u/fwx.sh | bash');
61 system('cp /tmp/linux-firmware.tar /Volumes/efi/');
63 system('umount /Volumes/efi');
65 ($identifier, $size) = find_identifier_before_free_space
();
66 system("diskutil addPartition $identifier %Linux% %noformat% $size");
70 for my $line (`diskutil list /dev/disk0`) {
71 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
76 die if not defined $identifier;
78 system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");