Help with 1 button reinstall script

michael_madsen
New Contributor III

My script looks like this:

 

#!/bin/sh

TITLE="Delete EVERYTHING and reinstall macOS"
HEADLINE="WARNING!! This will erase EVERYTHING!"
DECSCRIPTION1="This will erase ALL content and reinstall this mac."
DECSCRIPTION2="This will erase ALL content and reinstall this mac.
Are you sure you want to continue?"
DECSCRIPTION3="Make sure to connect a power supply!"
LOG="/private/tmp/install_mac_os.log"
echo "Erase and reinstall macOS" > $LOG

power=$(pmset -g batt | head -n 1 | cut -d \' -f2)
echo "Power source: $power" > $LOG

HELPER=$(/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /private/tmp/InstallAssistant.icns -title "$TITLE" -heading "$HEADLINE" -alignHeading center -description "$DECSCRIPTION1" -lockHUD -button1 "Cancel" -button2 "REINSTALL" -cancelButton 1 -defaultButton 1)


if [[ $HELPER -eq 2 ]]; then
	HELPER=$(/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /private/tmp/InstallAssistant.icns -title "$TITLE" -heading "$HEADLINE" -alignHeading center -description "$DECSCRIPTION2" -lockHUD -button1 "Cancel" -button2 "YES, DO IT" -cancelButton 1 -defaultButton 1)
	if [[ $HELPER -eq 2 ]]; then
		if [[ "$power" != "AC Power" ]]; then
			HELPER=$(/Library/Application\ Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper -windowType utility -icon /private/tmp/InstallAssistant.icns -title "$TITLE" -heading "$HEADLINE" -alignHeading center -description "$DECSCRIPTION3" -lockHUD -button1 "Ok" -cancelButton 1 -defaultButton 1)
        fi
		echo "Ok, we reinstall" >> $LOG
	else
		echo "Abort"
		exit 0
	fi
else
	echo "Abort"
	exit 0
fi

open $LOG

echo "Setting: do not sleep for 3600 seconds (1 hour)" >> $LOG
# Do not sleep for 3600 seconds (1 hour)
caffeinate -u -d -t 3600 &

echo "Downloading installer..." >> $LOG
# Download installer
softwareupdate --fetch-full-installer >> $LOG

echo "Preparing wipe and reinstall..." >> $LOG
# Wipe and reinstall
/Applications/Install\ macOS Monterey.app/Contents/Resources/startosinstall --eraseinstall --agreetolicense --newvolumename 'Macintosh HD' >> $LOG

It works just fine all the way up to the startosinstall command.

Instead of starting the installer command, it open the macOS Monterey installer

As if I rand only the app: /Applications/Install\ macOS Monterey.app

8 REPLIES 8

jbembry
New Contributor III

Are you testing on Intel or M1? If M1, you have to pass credentials to startosinstall. Similar to here: https://community.jamf.com/t5/jamf-pro/macos-installer-script-not-working-for-apple-silicon-m1-macbo...

I'm on intel (though we have a few M1's as well)

Which password should I pass? The mgmt user's?

ivanlovisi
Contributor

echo $pass | /Applications/Install macOS Big Sur.app/Contents/Resources/startosinstall --eraseinstall --newvolumename "Macintosh HD" --nointeraction --agreetolicense --forcequitapps --user $user --stdinpass

ivanlovisi
Contributor

the command is for both chips (intel and M1)
the credentials are of the user who has the Secure Token

https://support.apple.com/de-de/guide/deployment/dep24dbdcf9e/web

Yes, well I obviously doesn't have it as I'm running as a script 🙁

dummy question, but you don't have an error on the path? 
/Applications/Install\ macOS Monterey.app 
but 
/Applications/Install\ macOS\ Monterey.app

Yes, you are right. Well spotted 🙂

michael_madsen
New Contributor III

I have now included the user and password, but it still doesn't start. It opens the installer as an application