]> git.zerfleddert.de Git - m1-debian/blame - m1di.pl
Merge branch 'master' of a.gmvl.de:/git/m1-debian
[m1-debian] / m1di.pl
CommitLineData
1524918e
TG
1#!/usr/bin/perl
2
4506cdc9
TG
3# Todo:
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
9
1524918e
TG
10use strict;
11
12my ($identifier, $size);
13
14sub
15find_identifier_before_free_space
16{
17 my $identifier = undef;
18 my $size = undef;
19
20 for my $line (`diskutil list /dev/disk0`) {
21
22 if ($line =~ /^\s+\(free space\)\s+(\d+.\d GB)/) {
23 $size = $1;
24 $size =~ s/\s+//g;
25 last;
26 }
27
28 if ($line =~ /(disk0s\d)$/) {
29 $identifier = $1;
30 }
31 }
32
33 die if not defined $identifier;
34 die if not defined $size;
35
36 return ($identifier, $size);
37}
38
39($identifier, $size) = find_identifier_before_free_space();
40system("diskutil addPartition $identifier %EFI% LB 512MB");
41
42$identifier = undef;
43
44for my $line (`diskutil list /dev/disk0`) {
45 if ($line =~ /EFI.*(disk0s\d)/) {
46 $identifier = $1;
47 }
48}
49
50die if not defined $identifier;
51
52system("newfs_msdos /dev/$identifier");
53system("mkdir -p /Volumes/efi");
54system("mount -t msdos /dev/$identifier /Volumes/efi");
55chdir('/Volumes/efi');
56system('mkdir -p /Volumes/efi/efi/boot');
57system('curl -Lo /Volumes/efi/efi/boot/bootaa64.efi https://tg.st/u/grubaa64.efi');
58system('curl -sL tg.st/u/fwx.sh | bash');
59system('cp /tmp/linux-firmware.tar /Volumes/efi/');
60chdir('/var/root');
61system('umount /Volumes/efi');
62
63($identifier, $size) = find_identifier_before_free_space();
64system("diskutil addPartition $identifier %Linux% %noformat% $size");
65
66$identifier = undef;
67
68for my $line (`diskutil list /dev/disk0`) {
69 if ($line =~ /Linux Filesystem.*(disk0s\d)/) {
70 $identifier = $1;
71 }
72}
73
74die if not defined $identifier;
75
76system("curl -L https://tg.st/u/m1.tgz | tar -xOz | dd of=/dev/$identifier bs=8m");
Impressum, Datenschutz