From 8fef437f75bbcbdf3af9b8d9c3694b54895f0bac Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 27 Aug 2024 22:27:44 +0200 Subject: [PATCH] Make `Operations` script cross platform --- scripts/Common/Scripts/Operations.ps1 | 71 ++++++++++++++++----------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/scripts/Common/Scripts/Operations.ps1 b/scripts/Common/Scripts/Operations.ps1 index 1fc1b4b6..7805bb98 100644 --- a/scripts/Common/Scripts/Operations.ps1 +++ b/scripts/Common/Scripts/Operations.ps1 @@ -195,33 +195,6 @@ $null = New-Module { continue; } - Invoke-Hook "Install-PSModules" -Fallback { - $modules = @( - @("KnownFolders"), - @("PSWindowsUpdate"), - @("PSScriptAnalyzer"), - @("LocalAccounts", $true), - @("NuGet") - ); - - foreach ($module in $modules) { - $parameters = @{ }; - - if ($module[1]) { - $parameters = @{ - allowPrerelease = $true; - }; - } - - if (-not (Test-PSModule $module[0])) { - Install-Module -Scope AllUsers -AcceptLicense -Force -AllowClobber $module[0] @parameters; - Import-Module $module[0]; - } - } - - . "$PSScriptRoot/../../Windows/Software/PinnedItem/Manage.ps1"; - }; - if (-not (Test-PSPackage Selenium.WebDriver)) { Write-Host "Installing browser automation tools…"; $null = Install-Package -Force Selenium.WebDriver -RequiredVersion 4.10.0 -SkipDependencies; @@ -230,8 +203,46 @@ $null = New-Module { Install-ChocoPackage selenium-gecko-driver firefox; Install-WingetPackage AutoHotkey.AutoHotkey; - $initialized = $true; + . "$PSScriptRoot/../../Windows/Software/PinnedItem/Manage.ps1"; } + + Invoke-Hook "Install-PSModules" -Fallback { + $modules = @( + @("PSScriptAnalyzer") + ) + (& { + if (-not $IsWindows) { + @() + } else { + @( + @("KnownFolders"), + @("PSWindowsUpdate"), + @("LocalAccounts", $true), + @("NuGet") + ) + } + }); + + foreach ($module in $modules) { + $parameters = @{ }; + + if ($module -is [string]) { + $module = @($module); + } + + if ($module[1]) { + $parameters = @{ + allowPrerelease = $true; + }; + } + + if (-not (Test-PSModule $module[0])) { + Install-Module -Scope AllUsers -AcceptLicense -Force -AllowClobber $module[0] @parameters; + Import-Module $module[0]; + } + } + }; + + $initialized = $true; } } } @@ -384,6 +395,8 @@ $null = New-Module { Clears resources allocated during the operation. #> function Clear-OperationResources { - Uninstall-WslDistribution; + if ($IsWindows) { + Uninstall-WslDistribution; + } } };