Installing Rosetta 2 on Apple Silicon Macs

Our bootstap tool is written in Go, and as of the time I’m writing this, Go doesn’t support building for Apple Silicon Macs.

As such, we need to ensure Rosetta 2 is installed for our enrollment process to work. The only problem I had was that we only wanted to run this on Apple Silicon devices - obviously Intel Macs don’t need this. I learned about /usr/bin/arch this morning, which led to the script below:

#!/bin/bash

arch=$(/usr/bin/arch)

if [ "$arch" == "arm64" ]; then
    /usr/sbin/softwareupdate --install-rosetta --agree-to-license
fi

This works fine as root (we run it from a Launch Daemon), and I expect it would be fine in a payload free package as well.