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
12 my ($identifier, $size);
15 find_identifier_before_free_space
17 my $identifier = undef;
20 for my $line (`diskutil list /dev/disk0`) {
22 if ($line =~ /^\s+\(free space\)\s+(\d+.\d GB)/) {
28 if ($line =~ /(disk0s\d)$/) {
33 die if not defined $identifier;
34 die if not defined $size;
36 return ($identifier, $size);
39 ($identifier, $size) = find_identifier_before_free_space
();
40 system("diskutil addPartition $identifier %EFI% LB 512MB");
44 for my $line (`diskutil list /dev/disk0`) {
45 if ($line =~ /EFI.*(disk0s\d)/) {
50 die if not defined $identifier;
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/');
61 system('umount /Volumes/efi');
63 ($identifier, $size) = find_identifier_before_free_space
();
64 system("diskutil addPartition $identifier %Linux% %noformat% $size");
68 for my $line (`diskutil list /dev/disk0`) {
69 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
74 die if not defined $identifier;
76 system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");