diff --git a/images.CI/macos/anka/CreateCleanAnkaTemplate.ps1 b/images.CI/macos/anka/CreateCleanAnkaTemplate.ps1 index 6c3a9050..c7b6c056 100644 --- a/images.CI/macos/anka/CreateCleanAnkaTemplate.ps1 +++ b/images.CI/macos/anka/CreateCleanAnkaTemplate.ps1 @@ -58,6 +58,12 @@ function Invoke-EnableAutoLogon { } function Invoke-SoftwareUpdate { + param ( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $Password + ) + if (-not $InstallSoftwareUpdate) { Write-Host "`t[*] Skip installing software updates" return @@ -83,7 +89,7 @@ function Invoke-SoftwareUpdate { Show-StringWithFormat $newUpdates $listOfNewUpdates = $($($newUpdates.Split("*")).Split("Title") | Where-Object {$_ -match "Label:"}).Replace("Label: ", '') Write-Host "`t[*] Installing Software Updates on '$TemplateName' VM:" - Install-SoftwareUpdate -HostName $ipAddress -listOfUpdates $listOfNewUpdates | Show-StringWithFormat + Install-SoftwareUpdate -HostName $ipAddress -listOfUpdates $listOfNewUpdates -Password $Password | Show-StringWithFormat # Check if Action: restart # Make an array of updates @@ -116,6 +122,11 @@ function Invoke-SoftwareUpdate { } function Invoke-UpdateSettings { + param ( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $Password + ) $isConfRequired = $InstallSoftwareUpdate -or $EnableAutoLogon if (-not $isConfRequired) { Write-Host "`t[*] Skip additional configuration" @@ -132,7 +143,7 @@ function Invoke-UpdateSettings { Invoke-EnableAutoLogon # Install software updates - Invoke-SoftwareUpdate + Invoke-SoftwareUpdate -Password $Password Write-Host "`t[*] Stopping '$TemplateName' VM" Stop-AnkaVM -VMName $TemplateName @@ -154,7 +165,7 @@ Write-Host "`n[#1] Download macOS application installer:" $shortMacOSVersion = Get-ShortMacOSVersion -MacOSVersion $MacOSVersion if ([string]::IsNullOrEmpty($TemplateName)) { $osArch = $(arch) - if ($osArch -eq "arm64"){ + if ($osArch -eq "arm64") { $macOSInstaller = Get-MacOSIPSWInstaller -MacOSVersion $MacOSVersion -DownloadLatestVersion $DownloadLatestVersion -BetaSearch $BetaSearch $TemplateName = "clean_macos_${shortMacOSVersion}_${osArch}_${DiskSizeGb}gb" } else { @@ -178,7 +189,7 @@ New-AnkaVMTemplate -InstallerPath $macOSInstaller ` -DiskSizeGb $DiskSizeGb | Show-StringWithFormat Write-Host "`n[#3] Configure AutoLogon and/or install software updates:" -Invoke-UpdateSettings +Invoke-UpdateSettings -Password $TemplatePassword Write-Host "`n[#4] Finalization '$TemplateName' configuration and push to the registry:" Write-Host "`t[*] The '$TemplateName' VM status is stopped" diff --git a/images.CI/macos/anka/Service.Helpers.psm1 b/images.CI/macos/anka/Service.Helpers.psm1 index 96a663a1..f2ed7dd8 100644 --- a/images.CI/macos/anka/Service.Helpers.psm1 +++ b/images.CI/macos/anka/Service.Helpers.psm1 @@ -20,6 +20,24 @@ function Enable-AutoLogon { Invoke-SSHPassCommand -HostName $HostName -Command $command } +function Invoke-SoftwareUpdateArm64 { + param ( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $HostName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $Password + ) + + $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 +} + function Get-AvailableVersions { param ( [bool] $IsBeta = $false @@ -229,22 +247,27 @@ function Install-SoftwareUpdate { [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string] $HostName, - [array] $listOfUpdates + [array] $listOfUpdates, + [string] $Password ) $osVersion = [Environment]::OSVersion - $osVersionMajorMinor = $osVersion.Version.ToString(2) # If an update is happening on macOS 12 we will use the prepared list of updates, otherwise, we will install all updates. if ($osVersion.Version.Major -eq "12") { foreach ($update in $listOfUpdates){ # Filtering updates that contain "Ventura" word if ($update -notmatch "Ventura") { - $command = "sudo /usr/sbin/softwareupdate --restart --verbose --install $update" + $command = "sudo /usr/sbin/softwareupdate --restart --verbose --install '$($update.trim())'" Invoke-SSHPassCommand -HostName $HostName -Command $command } } } else { - $command = "sudo /usr/sbin/softwareupdate --all --install --restart --verbose" - Invoke-SSHPassCommand -HostName $HostName -Command $command + $osArch = $(arch) + if ($osArch -eq "arm64") { + Invoke-SoftwareUpdateArm64 -HostName $HostName -Password $Password + } else { + $command = "sudo /usr/sbin/softwareupdate --all --install --restart --verbose" + Invoke-SSHPassCommand -HostName $HostName -Command $command + } } } diff --git a/images/macos/provision/configuration/auto-software-update-arm64.exp b/images/macos/provision/configuration/auto-software-update-arm64.exp new file mode 100644 index 00000000..9ef9da47 --- /dev/null +++ b/images/macos/provision/configuration/auto-software-update-arm64.exp @@ -0,0 +1,7 @@ +#! /usr/bin/expect -f + +set timeout -1 +spawn sudo /usr/sbin/softwareupdate --all --install --restart --verbose +expect "Password*" +send "[lindex $argv 0]\r" +expect eof