I need help with a macOS installer download script.

howie_isaacks
Valued Contributor II

I am working on getting a lot of systems upgraded to macOS Ventura. Some of the systems are not compatible with macOS Sonoma, and we won't be making Sonoma available for a while. I had previously written a script to download the macOS Ventura installer. That script works very well. No issues. For this new script, I wanted to make sure that any older versions of the Ventura installer got deleted first. I want everyone on macOS 13.5.2. I don't want anyone to have to run a software update after upgrading to Ventura. Working from the previous script, I wrote this one. The "downloadURL" variable uses Parameter 4 in the Jamf policy. I fill in the download URL that I get from the Download Full Installer app. I use Parameter 5 to specify the macOS version that the script is downloading. This will be the name of the Install Assistant package when it is downloaded. I added a variable "installerVersion" to check the version of the currently installed macOS installer app if it's present. My intent with this script is that if a Ventura installer is present, I want to check its version. If the version is not 18.5.03 (which is the installer version that installs macOS 13.5.2), I want the installer app to be deleted, and then download the one I want using the parameters defined for the download URL and macOS Version variables. If the macOS Ventura installer is present, and its version is 18.5.03 then nothing should happen. If there is no macOS Ventura installer present, then I want it downloaded. Oddly, when I tested this script in a policy earlier today, it worked. When I saw it not working later on, I decided to take another crack at it and try to make it better. What am I doing wrong? The current script is below:

#!/bin/zsh

#############################################################################################################################
# This script will download the desired macOS installer using the URL that we specify in parameter 4. To name the installer package, specify the macOS version number in parameter 5. Example: 13.4.1. The downloaded package will be named "13.4.1.pkg". It will be saved to /private/tmp. After the package is downloaded, the package is ran to place the macOS installer in the Applications folder. The installer package is then deleted to free up drive space. 
#############################################################################################################################

# Use the Download Full Installer app from scriptingosx GitHub.
# https://github.com/scriptingosx/DownloadFullInstaller/releases

# Parameters for Jamf Pro
downloadURL="$4"  # Obtain this by right-clicking the macOS version you want from the list
macOSVersion="$5" # Example: 13.4.1
venturaInstaller="/Applications/Install macOS Ventura.app"
installerVersion=$(defaults read "/Applications/Install macOS Ventura.app/Contents/version.plist" CFBundleShortVersionString)

# Download destination
pathToInstaller=/private/tmp/$macOSVersion.pkg

### Check if the macOS Ventura Installer is already in Applications folder. Is it current?
if [ -d "$venturaInstaller" ]; then
	if [[ "$installerVersion" != 18.5.03 ]]; then	
		echo "Older macOS Ventura installer present. Removing older macOS Ventura Installer"
		rm -rf "$venturaInstaller"
		### Download the macOS installer using the URL obtained from Download Full Installer app.
		echo "Downloading macOS $macOSVersion installer package"
		curl -o $pathToInstaller $downloadURL
		### Extract the macOS install app from the downloaded package
		installer -pkg $pathToInstaller -target /
		### Delete the installer package to free up space
		rm $pathToInstaller
	else
		if [[ "$installerVersion" = 18.5.03 ]]; then
			echo "maOS Ventura installer is present and up to date"
		fi
	fi
		
fi
### Checking if the macOS  Ventura installer is not in Applications folder.
if [ -z "$venturaInstaller" ]; then
	### Download the macOS installer using the URL obtained from Download Full Installer app.
	echo "Downloading macOS $macOSVersion installer package"
	curl -o $pathToInstaller $downloadURL
	### Extract the macOS install app from the downloaded package
	installer -pkg $pathToInstaller -target /
	### Delete the installer package to free up space
	rm $pathToInstaller
fi

exit 0
0 REPLIES 0