From ac18dfbf3454d59847d000cecb72d3cf7272b83f Mon Sep 17 00:00:00 2001 From: Graham Pugh Date: Fri, 23 Jul 2021 12:30:02 +0200 Subject: [PATCH] Now checks for network and for the Rosetta process --- README.md | 26 +++++++++++++--- Rosetta-2-install.sh | 43 ++++++++++++++++++++------ pkg/Rosetta-2-install/build-info.plist | 2 +- 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index e3630dc..5dab9f7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,29 @@ # Rosetta-2-install -Make a payload-free package containing a script to install Rosetta 2. -If you have `munkipkg` installed and available at `/usr/local/bin/munkipkg`, use `make` to make an unsigned payload-free package. +This script checks that the computer on which it is running has an Apple Silicon processor. If it is, it checks whether Rosetta 2 is installed. If it is not installed, it will check for a network connection and then proceed to install Rosetta 2. -If you have `sign_pkg.py` available at `../jamf-upload/sign_pkg.py`, use `make; make sign` to make a signed package. +## Payload-free package + +You may wish to make a payload-free package containing a script to install Rosetta 2. + +If you have `munkipkg` installed and available at `/usr/local/bin/munkipkg`, use `make` to make an unsigned payload-free package. Note that you should compile the computer on an Apple Silicon Mac to get a universal package, which you are obviously going to need! + +I have also included a signed package in the Releases section of this repo. + +### Signing the package + +You may wish to sign the package for use in DEP enrollment. I have a script in the [Jamf-Upload](https://github.com/grahampugh/jamf-upload) repo to help with this. + +Clone the Jamf-Upload repo to the same folder that contains this repo's folder. + +You also need AutoPkg to be installed to use this script, and you need to add your Developer ID Installer certificate in your login keychain. + +Once you have met these requirements, use `make; make sign` to make a signed package. ## Use in Jamf Pro -You can add this script or package to a policy that is scoped to **all computers**, because the script will do nothing if Rosetta is already installed, or when run on an Intel device. -It is recommended to target at **Enrollment Complete** and **Recurring Check-in**, **Once per Computer**. +You can add this script (or package) to a policy that is scoped to **All Computers**, because the script will do nothing if Rosetta is already installed, or when run on an Intel device. + +It is recommended to target at **Enrollment Complete** and **Recurring Check-in**, **Once per Computer**. Use a Policy name that will be alphabetically first in your Jamf instance. We use **0001 - Install Rosetta 2**. diff --git a/Rosetta-2-install.sh b/Rosetta-2-install.sh index 2a05ab6..3b6b6d5 100755 --- a/Rosetta-2-install.sh +++ b/Rosetta-2-install.sh @@ -4,25 +4,48 @@ Determine whether Rosetta is installed - install if not. DOC +max_wait_count=10 + +wait_for_network() { + # check for + n=1 + while [[ $(ifconfig -a inet 2>/dev/null | sed -n -e '/127.0.0.1/d' -e '/0.0.0.0/d' -e '/inet/p' | wc -l) -lt 1 ]] ; do + if [[ $n -gt $max_wait_count ]] ; then + echo "[Rosetta-2-install] No network - Rosetta 2 installation failed" + exit 1 + fi + echo "[Rosetta-2-install] Waiting for network access... attempt $n" + sleep 5 + (( n++ )) + done + while ! curl --silent http://captive.apple.com/hotspot-detect.html 2>/dev/null | grep -q Success; do + echo "[Rosetta-2-install] Waiting for network access" + sleep 5 + done +} + # is this an ARM Mac? -arch=$(/usr/bin/arch) -if [ "$arch" == "arm64" ]; then - echo "This is an arm64 Mac." +if [[ "$(/usr/bin/arch)" == "arm64"* ]]; then + echo "[Rosetta-2-install] This is an arm64 Mac." # is Rosetta 2 installed? - if arch -x86_64 /usr/bin/true 2>/dev/null ; then - echo "Rosetta 2 is already installed" + if /usr/bin/pgrep oahd >/dev/null 2>&1 ; then + echo "[Rosetta-2-install] Rosetta 2 is already installed" else - echo "Rosetta 2 is missing - installing" + echo "[Rosetta-2-install] Rosetta 2 is missing - installing" + wait_for_network + echo "[Rosetta-2-install] Network is connected: proceeding with Rosetta 2 installation..." + echo /usr/sbin/softwareupdate --install-rosetta --agree-to-license - if arch -x86_64 /usr/bin/true 2>/dev/null; then - echo "Rosetta 2 is now installed" + echo + if /usr/bin/pgrep oahd >/dev/null 2>&1 ; then + echo "[Rosetta-2-install] Rosetta 2 is now installed" else - echo "Rosetta 2 installation failed" + echo "[Rosetta-2-install] Rosetta 2 installation failed" exit 1 fi fi else - echo "This is an Intel Mac." + echo "[Rosetta-2-install] This is an Intel Mac." fi exit 0 \ No newline at end of file diff --git a/pkg/Rosetta-2-install/build-info.plist b/pkg/Rosetta-2-install/build-info.plist index be4e86c..b6259fe 100644 --- a/pkg/Rosetta-2-install/build-info.plist +++ b/pkg/Rosetta-2-install/build-info.plist @@ -17,6 +17,6 @@ suppress_bundle_relocation version - 1.1 + 1.2