From 080812b90a417d408fec927637841de9bfea76f0 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 cc31346f..6f8dc6e1 100644 --- a/scripts/Common/Scripts/Operations.ps1 +++ b/scripts/Common/Scripts/Operations.ps1 @@ -196,33 +196,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; @@ -231,8 +204,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; } } } @@ -383,6 +394,8 @@ $null = New-Module { Clears resources allocated during the operation. #> function Clear-OperationResources { - Uninstall-WslDistribution; + if ($IsWindows) { + Uninstall-WslDistribution; + } } };