]> git.zerfleddert.de Git - m1-debian/blame - m1di.pl
hookup backlight
[m1-debian] / m1di.pl
CommitLineData
1524918e
TG
1#!/usr/bin/perl
2
1cee07b4
TG
3# SPDX-License-Identifier: MIT
4
4506cdc9
TG
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
1524918e
TG
12use strict;
13
14my ($identifier, $size);
15
16sub
17find_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($identifier, $size) = find_identifier_before_free_space();
42system("diskutil addPartition $identifier %EFI% LB 512MB");
43
44$identifier = undef;
45
46for my $line (`diskutil list /dev/disk0`) {
47 if ($line =~ /EFI.*(disk0s\d)/) {
48 $identifier = $1;
49 }
50}
51
52die if not defined $identifier;
53
54system("newfs_msdos /dev/$identifier");
55system("mkdir -p /Volumes/efi");
56system("mount -t msdos /dev/$identifier /Volumes/efi");
57chdir('/Volumes/efi');
58system('mkdir -p /Volumes/efi/efi/boot');
59system('curl -Lo /Volumes/efi/efi/boot/bootaa64.efi https://tg.st/u/grubaa64.efi');
60system('curl -sL tg.st/u/fwx.sh | bash');
61system('cp /tmp/linux-firmware.tar /Volumes/efi/');
62chdir('/var/root');
63system('umount /Volumes/efi');
64
65($identifier, $size) = find_identifier_before_free_space();
66system("diskutil addPartition $identifier %Linux% %noformat% $size");
67
68$identifier = undef;
69
70for my $line (`diskutil list /dev/disk0`) {
71 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
72 $identifier = $1;
73 }
74}
75
76die if not defined $identifier;
77
78system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");
Impressum, Datenschutz