2019-12-13 09:48:00 -05:00
|
|
|
################################################################################
|
|
|
|
|
## File: Install-PowershellCore.ps1
|
|
|
|
|
## Desc: Install PowerShell Core
|
2023-09-08 10:48:51 +02:00
|
|
|
## Supply chain security: checksum validation
|
2019-12-13 09:48:00 -05:00
|
|
|
################################################################################
|
|
|
|
|
|
2022-11-18 20:16:09 +01:00
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
|
|
|
|
|
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
|
2023-12-11 22:23:36 +01:00
|
|
|
New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue | Out-Null
|
2022-11-18 20:16:09 +01:00
|
|
|
try {
|
|
|
|
|
$originalValue = [Net.ServicePointManager]::SecurityProtocol
|
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
|
|
|
|
|
|
|
|
$metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json
|
2023-12-28 11:18:57 +01:00
|
|
|
$pwshMajorMinor = (Get-ToolsetContent).pwsh.version
|
|
|
|
|
|
|
|
|
|
$releases = $metadata.LTSReleaseTag -replace '^v'
|
|
|
|
|
foreach ($release in $releases) {
|
|
|
|
|
if ($release -like "${pwshMajorMinor}*") {
|
|
|
|
|
$downloadUrl = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/PowerShell-${release}-win-x64.msi"
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-08 10:48:51 +02:00
|
|
|
|
2023-12-04 10:50:53 +01:00
|
|
|
$installerName = Split-Path $downloadUrl -Leaf
|
|
|
|
|
$externalHash = Get-ChecksumFromUrl -Type "SHA256" `
|
|
|
|
|
-Url ($downloadUrl -replace $installerName, "hashes.sha256") `
|
|
|
|
|
-FileName $installerName
|
|
|
|
|
Install-Binary -Url $downloadUrl -ExpectedSHA256Sum $externalHash
|
2022-11-18 20:16:09 +01:00
|
|
|
} finally {
|
|
|
|
|
# Restore original value
|
|
|
|
|
[Net.ServicePointManager]::SecurityProtocol = $originalValue
|
|
|
|
|
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
|
}
|
2020-07-20 18:57:00 +03:00
|
|
|
|
2020-11-10 11:30:12 +03:00
|
|
|
# about_update_notifications
|
|
|
|
|
# While the update check happens during the first session in a given 24-hour period, for performance reasons,
|
|
|
|
|
# the notification will only be shown on the start of subsequent sessions.
|
|
|
|
|
# Also for performance reasons, the check will not start until at least 3 seconds after the session begins.
|
2023-12-04 10:50:53 +01:00
|
|
|
[Environment]::SetEnvironmentVariable("POWERSHELL_UPDATECHECK", "Off", "Machine")
|
2020-11-10 11:30:12 +03:00
|
|
|
|
2020-07-20 18:57:00 +03:00
|
|
|
Invoke-PesterTests -TestFile "Tools" -TestName "PowerShell Core"
|