diff --git a/images/macos/helpers/Common.Helpers.psm1 b/images/macos/helpers/Common.Helpers.psm1 index f8d758b3b..0dbe23831 100644 --- a/images/macos/helpers/Common.Helpers.psm1 +++ b/images/macos/helpers/Common.Helpers.psm1 @@ -28,17 +28,14 @@ function Get-EnvironmentVariable($variable) { function Get-OSVersion { $osVersion = [Environment]::OSVersion $osVersionMajorMinor = $osVersion.Version.ToString(2) - # Monterey needs future review: - # [Environment]::OSVersion returns 11.0 for Monterey preview. - [SemVer]$osMontereyVersion = sw_vers -productVersion return [PSCustomObject]@{ Version = $osVersion.Version Platform = $osVersion.Platform IsCatalina = $osVersionMajorMinor -eq "10.15" - IsBigSur = $osVersionMajorMinor -eq "11.0" - IsMonterey = $osMontereyVersion.Major -eq "12" - IsLessThanMonterey = $osMontereyVersion -lt "12.0" - IsHigherThanCatalina = [SemVer]$osVersion.Version -ge "11.0" + IsBigSur = $osVersion.Version.Major -eq "11" + IsMonterey = $osVersion.Version.Major -eq "12" + IsLessThanMonterey = $osVersion.Version.Major -lt "12" + IsHigherThanCatalina = $osVersion.Version.Major -ge "11" } } diff --git a/images/macos/provision/core/commonutils.sh b/images/macos/provision/core/commonutils.sh index f51d9b9ec..daa06627a 100644 --- a/images/macos/provision/core/commonutils.sh +++ b/images/macos/provision/core/commonutils.sh @@ -16,6 +16,12 @@ for package in $cask_packages; do brew install --cask $package done +# Execute AppleScript to change security preferences for virtualbox +# System Preferences -> Security & Privacy -> General -> Unlock -> Allow -> Not now +if is_Monterey; then + osascript $HOME/utils/confirm-identified-developers.scpt $USER_PASSWORD +fi + # Invoke bazel to download bazel version via bazelisk bazel diff --git a/images/macos/provision/utils/confirm-identified-developers.scpt b/images/macos/provision/utils/confirm-identified-developers.scpt new file mode 100644 index 000000000..a445d8be1 --- /dev/null +++ b/images/macos/provision/utils/confirm-identified-developers.scpt @@ -0,0 +1,53 @@ +# This AppleScript confirms developers in security preferences via macOS UI. +# It uses after VirtualBox installation to add 'Oracle Inc' as identified developer. +# Steps: +# - Close security preferences pop-up (it can be open after VirtualBox installation) +# - Open System Preferences -> Security & Privacy -> General +# - Unlock security preferences with user password (button 'Click the lock to make changes') +# - Click 'Allow' or 'Details…' button to confirm developers +# - Click 'Not now' button on restarting pop-up +# - Close System Preferences + +on run argv + set userpassword to item 1 of argv + set secpane to "Security & Privacy" + + tell application "System Events" + tell security preferences + keystroke return + delay 5 + end tell + end tell + + activate application "System Preferences" + delay 5 + tell application "System Events" + tell process "System Preferences" + click menu item secpane of menu "View" of menu bar 1 + delay 5 + click button 1 of window 1 + delay 5 + keystroke userpassword + delay 5 + keystroke return + delay 5 + click radio button "General" of tab group 1 of window 1 + delay 5 + if exists of UI element "Details…" of tab group 1 of window 1 then + click button "Details…" of tab group 1 of window 1 + delay 5 + keystroke return + delay 5 + keystroke return + delay 5 + end if + if exists of UI element "Allow" of tab group 1 of window 1 then + click button "Allow" of tab group 1 of window 1 + delay 5 + keystroke return + delay 5 + end if + click button 5 of window 1 + end tell + end tell +end run \ No newline at end of file diff --git a/images/macos/software-report/SoftwareReport.Common.psm1 b/images/macos/software-report/SoftwareReport.Common.psm1 index d4cf17e32..c2dc9234d 100644 --- a/images/macos/software-report/SoftwareReport.Common.psm1 +++ b/images/macos/software-report/SoftwareReport.Common.psm1 @@ -389,7 +389,7 @@ function Get-NewmanVersion { function Get-VirtualBoxVersion { $virtualBox = Run-Command "vboxmanage -v" - return "virtualbox $virtualBox" + return "VirtualBox $virtualBox" } function Get-VagrantVersion { diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index a97a29906..fb974d7ef 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -141,12 +141,17 @@ if ($os.IsLessThanMonterey) { if ($os.IsCatalina) { $utilitiesList += @( - (Get-VirtualBoxVersion), (Get-VagrantVersion), (Get-ParallelVersion) ) } +if (-not $os.IsBigSur) { + $utilitiesList += @( + (Get-VirtualBoxVersion) + ) +} + $markdown += New-MDList -Style Unordered -Lines ($utilitiesList | Sort-Object) # Tools diff --git a/images/macos/templates/macOS-12.json b/images/macos/templates/macOS-12.json index 19cacb0e4..e4b980b08 100644 --- a/images/macos/templates/macOS-12.json +++ b/images/macos/templates/macOS-12.json @@ -152,10 +152,12 @@ "./provision/core/ruby.sh", "./provision/core/rubygem.sh", "./provision/core/git.sh", - "./provision/core/node.sh" + "./provision/core/node.sh", + "./provision/core/commonutils.sh" ], "environment_vars": [ - "API_PAT={{user `github_api_pat`}}" + "API_PAT={{user `github_api_pat`}}", + "USER_PASSWORD={{user `vm_password`}}" ] }, { @@ -177,7 +179,6 @@ "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "scripts": [ - "./provision/core/commonutils.sh", "./provision/core/llvm.sh", "./provision/core/golang.sh", "./provision/core/swiftlint.sh", diff --git a/images/macos/tests/BasicTools.Tests.ps1 b/images/macos/tests/BasicTools.Tests.ps1 index 21f6de5e0..8bfa45aea 100644 --- a/images/macos/tests/BasicTools.Tests.ps1 +++ b/images/macos/tests/BasicTools.Tests.ps1 @@ -144,7 +144,7 @@ Describe "vagrant" -Skip:($os.IsHigherThanCatalina) { } } -Describe "virtualbox" -Skip:($os.IsHigherThanCatalina) { +Describe "virtualbox" -Skip:($os.IsBigSur) { It "virtualbox" { "vboxmanage -v" | Should -ReturnZeroExitCode } diff --git a/images/macos/tests/Common.Tests.ps1 b/images/macos/tests/Common.Tests.ps1 index 7938abfa9..88f148e05 100644 --- a/images/macos/tests/Common.Tests.ps1 +++ b/images/macos/tests/Common.Tests.ps1 @@ -120,4 +120,10 @@ Describe "GraalVM" { It "native-image" { '$GRAALVM_11_ROOT/native-image --version' | Should -ReturnZeroExitCode } +} + +Describe "VirtualBox" -Skip:($os.IsBigSur) { + It "Check kext kernel modules" { + kextstat | Out-String | Should -Match "org.virtualbox.kext" + } } \ No newline at end of file diff --git a/images/macos/toolsets/toolset-12.json b/images/macos/toolsets/toolset-12.json index b152660de..1cb3633a1 100644 --- a/images/macos/toolsets/toolset-12.json +++ b/images/macos/toolsets/toolset-12.json @@ -149,7 +149,8 @@ "imagemagick" ], "cask_packages": [ - "julia" + "julia", + "virtualbox" ] }, "gcc": {