[macos] use mist-cli for downloading OS distribution when generating anka clean vm (#8141)

This commit is contained in:
ilia-shipitsin
2023-08-24 15:15:31 +02:00
committed by GitHub
parent 862df58673
commit 5ff59cadc4
2 changed files with 5 additions and 12 deletions

View File

@@ -180,7 +180,7 @@ Remove-AnkaVM -VMName $TemplateName
Write-Host "`t[*] Creating Anka VM template with name '$TemplateName' and '$TemplateUsername' user"
Write-Host "`t[*] CPU Count: $CPUCount, RamSize: ${RamSizeGb}G, DiskSizeGb: ${DiskSizeGb}G, InstallerPath: $macOSInstaller, TemplateName: $TemplateName"
New-AnkaVMTemplate -InstallerPath $macOSInstaller `
New-AnkaVMTemplate -InstallerPath "$macOSInstaller" `
-TemplateName $TemplateName `
-TemplateUsername $TemplateUsername `
-TemplatePassword $TemplatePassword `

View File

@@ -180,26 +180,19 @@ function Get-MacOSInstaller {
exit 1
}
$installerPathPattern = "/Applications/Install macOS ${macOSName}*.app"
if (Test-Path $installerPathPattern) {
$previousInstallerPath = Get-Item -Path $installerPathPattern
Write-Host "`t[*] Removing '$previousInstallerPath' installation app before downloading the new one"
sudo rm -rf "$previousInstallerPath"
}
# Clear LastRecommendedMajorOSBundleIdentifier to prevent error during fetching updates
# Install failed with error: Update not found
Update-SoftwareBundle
# Download macOS installer
Write-Host "`t[*] Requested macOS '$MacOSVersion' version installer found, fetching it from Apple Software Update"
$result = Invoke-WithRetry { /usr/sbin/softwareupdate --fetch-full-installer --full-installer-version $MacOSVersion } {$LASTEXITCODE -eq 0} | Out-String
if (-not $result.Contains("Install finished successfully")) {
Write-Host "`t[x] Failed to fetch $MacOSVersion macOS `n$result"
Invoke-WithRetry -Command { sudo /usr/local/bin/mist download installer $MacOSVersion application --force --export installer.json --output-directory /Applications } -BreakCondition { $LASTEXITCODE -eq 0 } | Out-Null
if (-not(Test-Path installer.json -PathType leaf)) {
Write-Host "`t[x] Failed to fetch $MacOSVersion macOS"
exit 1
}
$installerPath = (Get-Item -Path $installerPathPattern).FullName
$installerPath = (Get-Content installer.json | Out-String | ConvertFrom-Json).options.applicationPath
if (-not $installerPath) {
Write-Host "`t[x] Path not found using '$installerPathPattern'"
exit 1