[macOS] update scripts to fix image generation (#7608)
This commit is contained in:
@@ -58,6 +58,12 @@ function Invoke-EnableAutoLogon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-SoftwareUpdate {
|
function Invoke-SoftwareUpdate {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[string] $Password
|
||||||
|
)
|
||||||
|
|
||||||
if (-not $InstallSoftwareUpdate) {
|
if (-not $InstallSoftwareUpdate) {
|
||||||
Write-Host "`t[*] Skip installing software updates"
|
Write-Host "`t[*] Skip installing software updates"
|
||||||
return
|
return
|
||||||
@@ -83,7 +89,7 @@ function Invoke-SoftwareUpdate {
|
|||||||
Show-StringWithFormat $newUpdates
|
Show-StringWithFormat $newUpdates
|
||||||
$listOfNewUpdates = $($($newUpdates.Split("*")).Split("Title") | Where-Object {$_ -match "Label:"}).Replace("Label: ", '')
|
$listOfNewUpdates = $($($newUpdates.Split("*")).Split("Title") | Where-Object {$_ -match "Label:"}).Replace("Label: ", '')
|
||||||
Write-Host "`t[*] Installing Software Updates on '$TemplateName' VM:"
|
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
|
# Check if Action: restart
|
||||||
# Make an array of updates
|
# Make an array of updates
|
||||||
@@ -116,6 +122,11 @@ function Invoke-SoftwareUpdate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Invoke-UpdateSettings {
|
function Invoke-UpdateSettings {
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[string] $Password
|
||||||
|
)
|
||||||
$isConfRequired = $InstallSoftwareUpdate -or $EnableAutoLogon
|
$isConfRequired = $InstallSoftwareUpdate -or $EnableAutoLogon
|
||||||
if (-not $isConfRequired) {
|
if (-not $isConfRequired) {
|
||||||
Write-Host "`t[*] Skip additional configuration"
|
Write-Host "`t[*] Skip additional configuration"
|
||||||
@@ -132,7 +143,7 @@ function Invoke-UpdateSettings {
|
|||||||
Invoke-EnableAutoLogon
|
Invoke-EnableAutoLogon
|
||||||
|
|
||||||
# Install software updates
|
# Install software updates
|
||||||
Invoke-SoftwareUpdate
|
Invoke-SoftwareUpdate -Password $Password
|
||||||
|
|
||||||
Write-Host "`t[*] Stopping '$TemplateName' VM"
|
Write-Host "`t[*] Stopping '$TemplateName' VM"
|
||||||
Stop-AnkaVM -VMName $TemplateName
|
Stop-AnkaVM -VMName $TemplateName
|
||||||
@@ -154,7 +165,7 @@ Write-Host "`n[#1] Download macOS application installer:"
|
|||||||
$shortMacOSVersion = Get-ShortMacOSVersion -MacOSVersion $MacOSVersion
|
$shortMacOSVersion = Get-ShortMacOSVersion -MacOSVersion $MacOSVersion
|
||||||
if ([string]::IsNullOrEmpty($TemplateName)) {
|
if ([string]::IsNullOrEmpty($TemplateName)) {
|
||||||
$osArch = $(arch)
|
$osArch = $(arch)
|
||||||
if ($osArch -eq "arm64"){
|
if ($osArch -eq "arm64") {
|
||||||
$macOSInstaller = Get-MacOSIPSWInstaller -MacOSVersion $MacOSVersion -DownloadLatestVersion $DownloadLatestVersion -BetaSearch $BetaSearch
|
$macOSInstaller = Get-MacOSIPSWInstaller -MacOSVersion $MacOSVersion -DownloadLatestVersion $DownloadLatestVersion -BetaSearch $BetaSearch
|
||||||
$TemplateName = "clean_macos_${shortMacOSVersion}_${osArch}_${DiskSizeGb}gb"
|
$TemplateName = "clean_macos_${shortMacOSVersion}_${osArch}_${DiskSizeGb}gb"
|
||||||
} else {
|
} else {
|
||||||
@@ -178,7 +189,7 @@ New-AnkaVMTemplate -InstallerPath $macOSInstaller `
|
|||||||
-DiskSizeGb $DiskSizeGb | Show-StringWithFormat
|
-DiskSizeGb $DiskSizeGb | Show-StringWithFormat
|
||||||
|
|
||||||
Write-Host "`n[#3] Configure AutoLogon and/or install software updates:"
|
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 "`n[#4] Finalization '$TemplateName' configuration and push to the registry:"
|
||||||
Write-Host "`t[*] The '$TemplateName' VM status is stopped"
|
Write-Host "`t[*] The '$TemplateName' VM status is stopped"
|
||||||
|
|||||||
@@ -20,6 +20,24 @@ function Enable-AutoLogon {
|
|||||||
Invoke-SSHPassCommand -HostName $HostName -Command $command
|
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 {
|
function Get-AvailableVersions {
|
||||||
param (
|
param (
|
||||||
[bool] $IsBeta = $false
|
[bool] $IsBeta = $false
|
||||||
@@ -229,22 +247,27 @@ function Install-SoftwareUpdate {
|
|||||||
[Parameter(Mandatory)]
|
[Parameter(Mandatory)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string] $HostName,
|
[string] $HostName,
|
||||||
[array] $listOfUpdates
|
[array] $listOfUpdates,
|
||||||
|
[string] $Password
|
||||||
)
|
)
|
||||||
$osVersion = [Environment]::OSVersion
|
$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 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") {
|
if ($osVersion.Version.Major -eq "12") {
|
||||||
foreach ($update in $listOfUpdates){
|
foreach ($update in $listOfUpdates){
|
||||||
# Filtering updates that contain "Ventura" word
|
# Filtering updates that contain "Ventura" word
|
||||||
if ($update -notmatch "Ventura") {
|
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
|
Invoke-SSHPassCommand -HostName $HostName -Command $command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$command = "sudo /usr/sbin/softwareupdate --all --install --restart --verbose"
|
$osArch = $(arch)
|
||||||
Invoke-SSHPassCommand -HostName $HostName -Command $command
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user