Skip to content

Commit

Permalink
Fix macOS 13 arm64 software update part (actions#8772)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexey Ayupov <“[email protected]”>
  • Loading branch information
Alexey-Ayupov and Alexey Ayupov authored Nov 9, 2023
1 parent e2f77cd commit 7a11d3f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
19 changes: 15 additions & 4 deletions images.CI/macos/anka/CreateCleanAnkaTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ function Invoke-SoftwareUpdate {
Install-SoftwareUpdate -HostName $ipAddress -listOfUpdates $listOfNewUpdates -Password $Password | Show-StringWithFormat

# Check if Action: restart
# Define the next macOS version
$command = "sw_vers"
$guestMacosVersion = Invoke-SSHPassCommand -HostName $ipAddress -Command $command
switch -regex ($guestMacosVersion[1]) {
'12.\d' { $nextOSVersion = 'macOS Ventura' }
'13.\d' { $nextOSVersion = 'macOS Sonoma' }
}
# Make an array of updates
$listOfNewUpdates = $newUpdates.split('*').Trim('')
foreach ($newupdate in $listOfNewUpdates) {
# Will be True if the value is not Venture, not empty, and contains "Action: restart" words
if ($newupdate.Contains("Action: restart") -and !$newupdate.Contains("macOS Ventura") -and !$newupdate.Contains("macOS Sonoma") -and (-not [String]::IsNullOrEmpty($newupdate))) {
Write-Host "`t[*] Sleep 60 seconds before the software updates have been installed"
Start-Sleep -Seconds 60
if ($newupdate.Contains("Action: restart") -and !$newupdate.Contains("$nextOSVersion") -and (-not [String]::IsNullOrEmpty($newupdate))) {
Write-Host "`t[*] Sleep 120 seconds before the software updates have been installed"
Start-Sleep -Seconds 120

Write-Host "`t[*] Waiting for loginwindow process"
Wait-LoginWindow -HostName $ipAddress | Show-StringWithFormat
Expand All @@ -112,7 +119,7 @@ function Invoke-SoftwareUpdate {

# Check software updates have been installed
$updates = Get-SoftwareUpdate -HostName $ipAddress
if ($updates.Contains("Action: restart")) {
if ($updates.Contains("Action: restart") -and !$updates.Contains("$nextOSVersion")) {
Write-Host "`t[x] Software updates failed to install: "
Show-StringWithFormat $updates
exit 1
Expand All @@ -123,6 +130,10 @@ function Invoke-SoftwareUpdate {
Write-Host "`t[*] Show the install history:"
$hUpdates = Get-SoftwareUpdateHistory -HostName $ipAddress
Show-StringWithFormat $hUpdates

Write-Host "`t[*] The current macOS version:"
$command = "sw_vers"
Invoke-SSHPassCommand -HostName $ipAddress -Command $command | Show-StringWithFormat
}

function Invoke-UpdateSettings {
Expand Down
42 changes: 32 additions & 10 deletions images.CI/macos/anka/Service.Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,31 @@ function Invoke-SoftwareUpdateArm64 {

[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $Password
[string] $Password,

[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[array] $ListOfUpdates
)

# Define the next macOS version
$command = "sw_vers"
$guestMacosVersion = Invoke-SSHPassCommand -HostName $HostName -Command $command
switch -regex ($guestMacosVersion[1]) {
'13.\d' { $nextOSVersion = 'Sonoma' }
'14.\d' { $nextOSVersion = 'NotYetDefined' }
}

$url = "https://raw.githubusercontent.com/actions/runner-images/main/images/macos/provision/configuration/auto-software-update-arm64.exp"
$script = Invoke-RestMethod -Uri $url
$base64 = [Convert]::ToBase64String($script.ToCharArray())
$command = "echo $base64 | base64 --decode > ./auto-software-update-arm64.exp;chmod +x ./auto-software-update-arm64.exp; ./auto-software-update-arm64.exp ${Password};rm ./auto-software-update-arm64.exp"
Invoke-SSHPassCommand -HostName $HostName -Command $command
foreach ($update in $listOfUpdates) {
if ($update -notmatch "$nextOSVersion") {
$updatedScript = $script.Replace("MACOSUPDATE", $($($update.trim()).Replace(" ","\ ")))
$base64 = [Convert]::ToBase64String($updatedScript.ToCharArray())
$command = "echo $base64 | base64 --decode > ./auto-software-update-arm64.exp;chmod +x ./auto-software-update-arm64.exp; ./auto-software-update-arm64.exp ${Password};rm ./auto-software-update-arm64.exp"
Invoke-SSHPassCommand -HostName $HostName -Command $command
}
}
}

function Get-AvailableVersions {
Expand Down Expand Up @@ -261,17 +278,22 @@ function Install-SoftwareUpdate {
}
}
} elseif ($guestMacosVersion[1] -match "13") {
foreach ($update in $listOfUpdates) {
# Filtering updates that contain "Sonoma" word
if ($update -notmatch "Sonoma") {
$command = "sudo /usr/sbin/softwareupdate --restart --verbose --install '$($update.trim())'"
Invoke-SSHPassCommand -HostName $HostName -Command $command
$osArch = $(arch)
if ($osArch -eq "arm64") {
Invoke-SoftwareUpdateArm64 -HostName $HostName -Password $Password -ListOfUpdates $listOfUpdates
} else {
foreach ($update in $listOfUpdates) {
# Filtering updates that contain "Sonoma" word
if ($update -notmatch "Sonoma") {
$command = "sudo /usr/sbin/softwareupdate --restart --verbose --install '$($update.trim())'"
Invoke-SSHPassCommand -HostName $HostName -Command $command
}
}
}
} else {
$osArch = $(arch)
if ($osArch -eq "arm64") {
Invoke-SoftwareUpdateArm64 -HostName $HostName -Password $Password
Invoke-SoftwareUpdateArm64 -HostName $HostName -Password $Password -ListOfUpdates $listOfUpdates
} else {
$command = "sudo /usr/sbin/softwareupdate --all --install --restart --verbose"
Invoke-SSHPassCommand -HostName $HostName -Command $command
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/expect -f

set timeout -1
spawn sudo /usr/sbin/softwareupdate --all --install --restart --verbose
spawn sudo /usr/sbin/softwareupdate --restart --verbose --install "MACOSUPDATE"
expect "Password*"
send "[lindex $argv 0]\r"
expect eof

0 comments on commit 7a11d3f

Please sign in to comment.