Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: automate the macOS installation #122

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Catalina/clover-image-ng.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# https://github.com/kraxel/imagefish

Expand Down
2 changes: 1 addition & 1 deletion HighSierra/clover-image.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# https://github.com/kraxel/imagefish

Expand Down
2 changes: 1 addition & 1 deletion Mojave/clover-image-ng.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# https://github.com/kraxel/imagefish

Expand Down
2 changes: 1 addition & 1 deletion Mojave/clover-image.sh
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# https://github.com/kraxel/imagefish

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -190,7 +190,7 @@ Phenom II X3 720 does not. Ryzen processors work just fine.
I have the following commands present in `/etc/rc.local`.

```
#!/bin/bash
#!/usr/bin/env bash

sudo ip tuntap add dev tap0 mode tap
sudo ip link set tap0 up promisc on
Expand Down
1 change: 1 addition & 0 deletions automation/.gitignore
@@ -0,0 +1 @@
*.qcow2
280 changes: 280 additions & 0 deletions automation/automation.sh
@@ -0,0 +1,280 @@
#!/usr/bin/env bash
if [[ $0 = "${BASH_SOURCE[0]}" ]]; then
set -euo pipefail
fi

function === { echo "=== $*" >&2; }

vncsend() { vncdo -s localhost:1 "$@"; }

# proxy all those commands
commands=(
capture
click
expect
key
move
)
for cmd in "${commands[@]}"; do
eval "$cmd() { vncsend $cmd \"\$@\"; }"
done

# rename type to text to avoid overriding the `type` builtin
text() {
vncsend type "$@"
}

expect() {
local img=$1 imgtmp imgdiff
imgtmp=$(mktemp XXXXXXXX.png)
imgdiff=$(mktemp XXXXXXXXX-diff.png)
capture "$imgtmp"
compare \
-metric AE -fuzz 5% \
"$img" "$imgtmp" \
-compose Src \
"$imgdiff"

# TODO: calculate the number of red pixels
}

expect() {
echo "wait for the screen to look like $1"
img2txt -W 79 "$1"
read -r
}

if [[ $0 != "${BASH_SOURCE[0]}" ]]; then
return
fi

### Main ###
# TODO: start qemu as well

# TODO: allow to jump forward to resume the installation from a certain point

=== Starting VNC viewer for debugging

vncviewer -noraiseonbeep localhost:1 &
pid=$!
trap 'kill $pid' EXIT
# rm mac_hdd_ng.img
# qemu-img create -f qcow2 mac_hdd_ng.img 32G

# TODO: also start qemu
#exec {myfd}< <(./boot-macOS-NG.sh)

=== Boot installer
expect cap1.png 0
key enter

=== Language selection
# NOTE: this is remembered
expect cap1.1.png 0

# spam enter, doesn't seem reliable
key enter
key enter
key enter

=== Select the disk utility
expect cap2.png 0
# selected safari instead one time
key down
key down
key down
key down
key tab
key space

=== Select qemu HDD
expect cap3.png 0
key up

=== Select erase button
# FIXME: partition buttons got selected instead
key tab
key tab
key tab
key space

=== Enter disk info
# FIXME: for some reason it typed "mACINTOSH hd"
# text "Macintosh HD"
# Theory: only use lower cases to avoid that issue
text "macos"
key tab
key tab
key tab
key tab
key tab
key space

=== Back to menu
expect cap4.png 0
move 80 10 click 1
key q
# FIXME: this is not reliable. spam
key space
key space
key space

=== Start the installer
expect cap2.png 10
key up
key up
key tab
key space

=== macOS Mojave
# FIXME: It can output the following error:
# "The request to the recovery server timed out."
# => cap5-error.png
expect cap5.png 10
key tab
key space

=== macOS license
expect cap6.png 10
key tab
key tab
key space

=== macOS license popup
expect cap6.1.png 10
key tab
key space

=== disk selector
expect cap7.png 10
# disk not selectable through keyboard presses
move 450 500 click 1
# aand now the button is not navigable either
move 560 620 click 1

# wait 17 minutes
=== select country
# FIXME: sometimes the installed fails
# cap8-error.png
expect cap8.png 10
move 500 500 click 1
key v
key up
key up
key up
key tab
key space

=== select keyboard
expect cap9.png 10
key tab
key tab
key tab
key space

=== data and privacy
expect cap10.png 10
key tab
key tab
key tab
key space

=== transfer information to this mac
expect cap11.png 10
key tab
key tab
key tab
key space

=== sign in with your Apple ID
expect cap12.png 10
key tab
key tab
key tab
key tab
key tab
key tab
key space
key tab
key space

=== terms and conditions
expect cap13.png 10
key tab
key tab
key space
# popup
key tab
key space

=== create a computer account
expect cap14.png 10
text user
key tab
key tab
text password
key tab
text password
key tab
key tab
key tab
key space

=== express setup
expect cap15.png 10
key tab
key tab
key space

=== enable location services
expect cap16.png 10
key tab
key tab
key tab
key tab
key space
# popup
key tab
key space

=== select your timezone
expect cap17.png 10
key tab
key tab
key tab
key tab
key space

=== analytics
expect cap18.png 10
key tab
key space
key tab
key tab
key tab
key space

=== choose your look
expect cap19.png 10
key tab
key tab
key tab
key space

=== started!
expect cap20.png 10

# TODO: make meta-space work
key meta-space
text "terminal"
key enter

text "sudo systemsetup -setremotelogin on"
key enter
text "password"
key enter

# (qemu) savevm prepare
# Error: State blocked by non-migratable CPU device (invtsc flag)

# Error: Device 'pflash1' is writable but does not support snapshots
14 changes: 14 additions & 0 deletions automation/boot-macOS-NG.sh
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -euo pipefail

args=()

# shellcheck disable=SC1091
source ./common-macOS-NG.sh

# shellcheck disable=SC2054,SC2191,SC2034
args+=(
-netdev user,id=net0 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27
)

qemu-system-x86_64 "${args[@]}"
Binary file added automation/cap1.1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap10.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap11.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap12.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap13.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap14.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap15.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap17.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap18.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap19.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap20.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap5-error.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap5.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap6.1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap6.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap7.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap8-error.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added automation/cap9.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions automation/common-macOS-NG.sh
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

if [[ $(< /sys/module/kvm/parameters/ignore_msrs) != Y ]]; then
echo 1 | sudo tee /sys/module/kvm/parameters/ignore_msrs
fi

############################################################################
# NOTE: Tweak the "MY_OPTIONS" line in case you are having booting problems!
############################################################################

# This works for High Sierra as well as Mojave. Tested with macOS 10.13.6 and macOS 10.14.4.

#MY_OPTIONS="+pcid,+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"
# pcid is not supported on my machine
MY_OPTIONS="+ssse3,+sse4.2,+popcnt,+avx,+aes,+xsave,+xsaveopt,check"

# shellcheck disable=SC2054,SC2191,SC2034
args=(
-enable-kvm
-m 3072
# Error: State blocked by non-migratable CPU device (invtsc flag)
#-cpu "Penryn,kvm=on,vendor=GenuineIntel,+invtsc,vmware-cpuid-freq=on,$MY_OPTIONS"
-cpu "Penryn,kvm=on,vendor=GenuineIntel,vmware-cpuid-freq=on,$MY_OPTIONS"
-machine q35
-smp "4,cores=2"
-usb -device usb-kbd -device usb-tablet
-device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
# Error: Device 'pflash1' is writable but does not support snapshots
#-drive "if=pflash,format=raw,readonly,file=$OVMF/OVMF_CODE.fd"
#-drive "if=pflash,format=raw,file=$OVMF/OVMF_VARS-1024x768.fd"
# qemu-img convert -p -f raw OVMF_CODE.fd -O qcow2 OVMF_CODE.qcow2
# qemu-img convert -p -f raw OVMF_VARS-1024x768.fd -O qcow2 OVMF_VARS-1024x768.qcow2
-drive if=pflash,format=qcow2,readonly,file=OVMF_CODE.qcow2
-drive if=pflash,format=qcow2,file=OVMF_VARS-1024x768.qcow2
-smbios type=2
-device ich9-intel-hda -device hda-duplex
-device ich9-ahci,id=sata
# (qemu) qemu-system-x86_64: Device 'Clover' does not have the requested snapshot 'prepare'
-drive id=Clover,if=none,format=qcow2,file=CloverNG.qcow2
-device ide-hd,bus=sata.2,drive=Clover
-drive id=MacHDD,if=none,format=qcow2,file=mac_hdd_ng.img
-device ide-hd,bus=sata.4,drive=MacHDD
#-netdev tap,id=net0,ifname=tap0,script=no,downscript=no -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:27
# during the installation, a "recovery server" is being contacted
-netdev user,id=net0 -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:28
-monitor stdio
-vga vmware
-vnc 0.0.0.0:1 -k en-us
#-loadvm prepare
)