Auto select macOS installer

clothoest
New Contributor

Hi all,

I want to write a scripts to auto select Monterey or Ventura installer.

The scripts is here:

#!/bin/bash
### CHECK AVAILABLE DOWNLOADS
 
GET_OS_UPDATE=$(softwareupdate --list-full-installer | sed -n 3p)
sleep 1
TRIM_OS_VERSION=${GET_OS_UPDATE#*Version: }
echo "$TRIM_OS_VERSION"
OS_BUILD=${TRIM_OS_VERSION%%, Size*}
 
### GET THE MAJOR AND MINOR VERSIONS:
 
majorVersion=$(echo "$OS_BUILD" | cut -d "." -f 1)
minorVersion=$(echo "$OS_BUILD" | cut -d "." -f 2)
 
### GET THE NAME:
 
TRIM_OS_NAME=${GET_OS_UPDATE#*Title: }
echo "$TRIM_OS_NAME"
OS_NAME=${TRIM_OS_NAME%%, Version:*}
InstallerPath="/Applications/Install\ "$OS_NAME".app/Contents/Resources/startosinstall"
 
osascript -e 'tell app "System Events" to display alert "Downloading '$OS_NAME $OS_BUILD' update"'
softwareupdate --fetch-full-installer --full-installer-version $OS_BUILD
####Variables
 
# Determine the current user
currentUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
 
# Determine the current user id
currentUID=$(id -u "$currentUser")
 
###Functions
 
Password(){
# Prompts the user to input their FileVault password using Applescript. This password is used for a SecureToken into the startosinstall.
/bin/launchctl asuser "$currentUID" sudo -iu "$currentUser" /usr/bin/osascript <<APPLESCRIPT
set validatedPass to false
repeat while (validatedPass = false)
-- Prompt the user to enter their filevault password
display dialog "Before starting the '$OS_NAME $OS_BUILD' upgrade, make sure to save your all documents and close all applications. Then, enter your MacOS local account password twice to begin the upgrade process." with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:FileVaultIcon.icns" default answer "" buttons {"Continue"} with text and hidden answer default button "Continue"
set fvPass to (text returned of result)
display dialog "Re-enter your MacOS local accountpassword to verify it was entered correctly." with text and hidden answer buttons {"Continue"} with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:FileVaultIcon.icns" default answer "" default button "Continue"
if text returned of result is equal to fvPass then
set validatedPass to true
fvPass
else
display dialog "The MacOS local account passwords you have entered do not match. Please enter matching passwords." with title "FileVault Password Validation Failed" buttons {"Re-Enter Password"} default button "Re-Enter Password" with icon file "System:Library:CoreServices:CoreTypes.bundle:Contents:Resources:FileVaultIcon.icns"
end if
end repeat
APPLESCRIPT
}
executeUpdate(){
    osascript -e 'tell app "System Events" to display alert "installing '$OS_NAME $OS_BUILD' update"'
    Password | $InstallerPath --agreetolicense --forcequitapps --nointeraction --user $currentUser --stdinpass
}
 
###Script
 
 
executeUpdate
 
exit 0 ## Success
exit 1 ## Failure
 
It also report that "syntax error: Expected string but found end of script. (-2741) /Library/Application Support/JAMF/tmp/Download Laterest OS with depnoifty: line 54: /Applications/Install\: No such file or directory"
1 ACCEPTED SOLUTION

sdagley
Esteemed Contributor II

@clothoest You really should take a look at erase-install which despite the name is a tool that also supports macOS updates. There is an extensive wiki covering usage, including a section on Jamf Pro: https://github.com/grahampugh/erase-install/wiki/6.-Use-in-Jamf-Pro

View solution in original post

1 REPLY 1

sdagley
Esteemed Contributor II

@clothoest You really should take a look at erase-install which despite the name is a tool that also supports macOS updates. There is an extensive wiki covering usage, including a section on Jamf Pro: https://github.com/grahampugh/erase-install/wiki/6.-Use-in-Jamf-Pro