From ece5408a8929735b083383b6efaa1d885d3381e7 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 2 Sep 2021 17:12:55 +0300 Subject: [PATCH 1/6] Install virtualbox on macOS-11 --- images/macos/provision/core/commonutils.sh | 3 ++ .../core/confirm-identified-developers.scpt | 43 +++++++++++++++++++ images/macos/templates/macOS-11.json | 9 ++++ images/macos/tests/BasicTools.Tests.ps1 | 2 +- images/macos/toolsets/toolset-11.json | 3 +- 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 images/macos/provision/core/confirm-identified-developers.scpt diff --git a/images/macos/provision/core/commonutils.sh b/images/macos/provision/core/commonutils.sh index 550e1abe0832..c922242e047a 100644 --- a/images/macos/provision/core/commonutils.sh +++ b/images/macos/provision/core/commonutils.sh @@ -13,6 +13,9 @@ for package in $cask_packages; do brew install --cask $package done +# Execute AppleScript to change security preferences for virtualbox +osascript confirm-identified-developers.scpt $USER_PASSWORD + # Specify Bazel version 3.7.1 to install due to the bug with 4.0.0: https://github.com/bazelbuild/bazel/pull/12882 if is_Less_Catalina; then export USE_BAZEL_VERSION="3.7.1" diff --git a/images/macos/provision/core/confirm-identified-developers.scpt b/images/macos/provision/core/confirm-identified-developers.scpt new file mode 100644 index 000000000000..4fa30dba6846 --- /dev/null +++ b/images/macos/provision/core/confirm-identified-developers.scpt @@ -0,0 +1,43 @@ +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/templates/macOS-11.json b/images/macos/templates/macOS-11.json index cf8bcbc9812d..98ca121ffc33 100644 --- a/images/macos/templates/macOS-11.json +++ b/images/macos/templates/macOS-11.json @@ -191,8 +191,17 @@ "./provision/core/pypy.sh", "./provision/core/pipx-packages.sh", "./provision/core/bicep.sh" + ], + "environment_vars": [ + "USER_PASSWORD={{user `vm_password`}}" ] }, + { + "type": "shell", + "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}", + "script": "./provision/core/reboot.sh", + "expect_disconnect": true + }, { "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", diff --git a/images/macos/tests/BasicTools.Tests.ps1 b/images/macos/tests/BasicTools.Tests.ps1 index e5248800c938..7a2150278452 100644 --- a/images/macos/tests/BasicTools.Tests.ps1 +++ b/images/macos/tests/BasicTools.Tests.ps1 @@ -144,7 +144,7 @@ Describe "vagrant" -Skip:($os.IsBigSur) { } } -Describe "virtualbox" -Skip:($os.IsBigSur) { +Describe "virtualbox" { It "virtualbox" { "vboxmanage -v" | Should -ReturnZeroExitCode } diff --git a/images/macos/toolsets/toolset-11.json b/images/macos/toolsets/toolset-11.json index 0b45dd16c818..9790588697b5 100644 --- a/images/macos/toolsets/toolset-11.json +++ b/images/macos/toolsets/toolset-11.json @@ -155,7 +155,8 @@ "zstd" ], "cask_packages": [ - "julia" + "julia", + "virtualbox" ] }, "gcc": { From 304b3a362eea0aadc9ff43185c582a1fffc04810 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Thu, 2 Sep 2021 18:00:42 +0300 Subject: [PATCH 2/6] Add virtualbox to software report for macos-11 --- images/macos/software-report/SoftwareReport.Generator.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/macos/software-report/SoftwareReport.Generator.ps1 b/images/macos/software-report/SoftwareReport.Generator.ps1 index c4b82d9f70db..534bf0c5ca02 100644 --- a/images/macos/software-report/SoftwareReport.Generator.ps1 +++ b/images/macos/software-report/SoftwareReport.Generator.ps1 @@ -129,7 +129,8 @@ $utilitiesList = @( (Get-MongodVersion), (Get-7zipVersion), (Get-BsdtarVersion), - (Get-GnuTarVersion) + (Get-GnuTarVersion), + (Get-VirtualBoxVersion) ) if ($os.IsHigherThanMojave) { @@ -140,7 +141,6 @@ if ($os.IsHigherThanMojave) { if ($os.IsLessThanBigSur) { $utilitiesList += @( - (Get-VirtualBoxVersion), (Get-VagrantVersion), (Get-ParallelVersion) ) From 4c4e96b786eb1ba9f8faab83704623990283a37f Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 3 Sep 2021 10:59:57 +0300 Subject: [PATCH 3/6] Add common test for VirtualBox kext kernel modules --- images/macos/provision/core/commonutils.sh | 5 ++++- .../confirm-identified-developers.scpt | 10 ++++++++++ .../software-report/SoftwareReport.Common.psm1 | 2 +- images/macos/templates/macOS-11.json | 16 +++++----------- images/macos/tests/Common.Tests.ps1 | 6 ++++++ 5 files changed, 26 insertions(+), 13 deletions(-) rename images/macos/provision/{core => utils}/confirm-identified-developers.scpt (68%) diff --git a/images/macos/provision/core/commonutils.sh b/images/macos/provision/core/commonutils.sh index c922242e047a..bb4c2873520a 100644 --- a/images/macos/provision/core/commonutils.sh +++ b/images/macos/provision/core/commonutils.sh @@ -14,7 +14,10 @@ for package in $cask_packages; do done # Execute AppleScript to change security preferences for virtualbox -osascript confirm-identified-developers.scpt $USER_PASSWORD +# System Preferences -> Security & Privacy -> General -> Unlock -> Allow -> Not now +if is_BigSur; then + osascript $HOME/utils/confirm-identified-developers.scpt $USER_PASSWORD +fi # Specify Bazel version 3.7.1 to install due to the bug with 4.0.0: https://github.com/bazelbuild/bazel/pull/12882 if is_Less_Catalina; then diff --git a/images/macos/provision/core/confirm-identified-developers.scpt b/images/macos/provision/utils/confirm-identified-developers.scpt similarity index 68% rename from images/macos/provision/core/confirm-identified-developers.scpt rename to images/macos/provision/utils/confirm-identified-developers.scpt index 4fa30dba6846..9c293cae3dba 100644 --- a/images/macos/provision/core/confirm-identified-developers.scpt +++ b/images/macos/provision/utils/confirm-identified-developers.scpt @@ -1,3 +1,13 @@ +# 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" diff --git a/images/macos/software-report/SoftwareReport.Common.psm1 b/images/macos/software-report/SoftwareReport.Common.psm1 index 240efc0cf9aa..bc6493ec4dc2 100644 --- a/images/macos/software-report/SoftwareReport.Common.psm1 +++ b/images/macos/software-report/SoftwareReport.Common.psm1 @@ -394,7 +394,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/templates/macOS-11.json b/images/macos/templates/macOS-11.json index 98ca121ffc33..6e3480c435f7 100644 --- a/images/macos/templates/macOS-11.json +++ b/images/macos/templates/macOS-11.json @@ -142,7 +142,11 @@ "./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": [ + "USER_PASSWORD={{user `vm_password`}}" ] }, { @@ -164,7 +168,6 @@ "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}", "scripts": [ - "./provision/core/commonutils.sh", "./provision/core/swiftlint.sh", "./provision/core/openjdk.sh", "./provision/core/php.sh", @@ -191,17 +194,8 @@ "./provision/core/pypy.sh", "./provision/core/pipx-packages.sh", "./provision/core/bicep.sh" - ], - "environment_vars": [ - "USER_PASSWORD={{user `vm_password`}}" ] }, - { - "type": "shell", - "execute_command": "chmod +x {{ .Path }}; sudo {{ .Vars }} {{ .Path }}", - "script": "./provision/core/reboot.sh", - "expect_disconnect": true - }, { "type": "shell", "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} pwsh -f {{ .Path }}", diff --git a/images/macos/tests/Common.Tests.ps1 b/images/macos/tests/Common.Tests.ps1 index 0c2366a1b7f9..f9e09f0b6149 100644 --- a/images/macos/tests/Common.Tests.ps1 +++ b/images/macos/tests/Common.Tests.ps1 @@ -97,4 +97,10 @@ Describe "Bicep" { It "Bicep" { "bicep --version" | Should -ReturnZeroExitCode } +} + +Describe "VirtualBox" { + It "Check kext kernel modules" { + "kextstat | grep 'virtualbox.kext'" | Should -ReturnZeroExitCode + } } \ No newline at end of file From c0ad6974ff92682f81138d93216b0e3d06b19cf6 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 3 Sep 2021 11:12:38 +0300 Subject: [PATCH 4/6] Use should match expression in VirutalBox common test --- images/macos/tests/Common.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/macos/tests/Common.Tests.ps1 b/images/macos/tests/Common.Tests.ps1 index f9e09f0b6149..743cec6d8751 100644 --- a/images/macos/tests/Common.Tests.ps1 +++ b/images/macos/tests/Common.Tests.ps1 @@ -101,6 +101,6 @@ Describe "Bicep" { Describe "VirtualBox" { It "Check kext kernel modules" { - "kextstat | grep 'virtualbox.kext'" | Should -ReturnZeroExitCode + "kextstat" | Should -Match "virtualbox.kext" } } \ No newline at end of file From cd20e37da14a43c06deadfc5f8acd66bfd5f8bf5 Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 3 Sep 2021 11:17:12 +0300 Subject: [PATCH 5/6] Fix title for VirtualBox test --- images/macos/tests/BasicTools.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/images/macos/tests/BasicTools.Tests.ps1 b/images/macos/tests/BasicTools.Tests.ps1 index 7a2150278452..a57c723b3056 100644 --- a/images/macos/tests/BasicTools.Tests.ps1 +++ b/images/macos/tests/BasicTools.Tests.ps1 @@ -144,8 +144,8 @@ Describe "vagrant" -Skip:($os.IsBigSur) { } } -Describe "virtualbox" { - It "virtualbox" { +Describe "VirtualBox" { + It "vboxmanage" { "vboxmanage -v" | Should -ReturnZeroExitCode } } From 991841575d2133cae7ab88dc05006e1833a7ddfb Mon Sep 17 00:00:00 2001 From: Vladimir Safonkin Date: Fri, 3 Sep 2021 15:56:30 +0300 Subject: [PATCH 6/6] Convert kextstat output to single string --- images/macos/tests/Common.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/macos/tests/Common.Tests.ps1 b/images/macos/tests/Common.Tests.ps1 index 743cec6d8751..7b9a3b7608ca 100644 --- a/images/macos/tests/Common.Tests.ps1 +++ b/images/macos/tests/Common.Tests.ps1 @@ -101,6 +101,6 @@ Describe "Bicep" { Describe "VirtualBox" { It "Check kext kernel modules" { - "kextstat" | Should -Match "virtualbox.kext" + kextstat | Out-String | Should -Match "org.virtualbox.kext" } } \ No newline at end of file