Updated install-powershell.ps1

This commit is contained in:
Markus Fleschutz 2025-04-30 17:06:19 +02:00
parent 7bc0509211
commit 6683e179fc

View File

@ -135,7 +135,7 @@ function Remove-Destination([string]$Destination) {
} }
} }
} else { } else {
Write-Host "⏳ (3/4) Moving old installation to $($Destination).old... " Write-Host "⏳ (3/5) Moving old installation to $($Destination).old... "
# Unix systems don't keep open file handles so you can just move files/folders even if in use # Unix systems don't keep open file handles so you can just move files/folders even if in use
sudo mv "$Destination" "$($Destination).old" sudo mv "$Destination" "$($Destination).old"
} }
@ -355,7 +355,7 @@ try {
tar zxf $packagePath -C $contentPath tar zxf $packagePath -C $contentPath
} }
} else { } else {
Write-Host "⏳ (1/4) Querying infos from https://raw.githubusercontent.com ..." Write-Host "⏳ (1/5) Querying infos from https://raw.githubusercontent.com ..."
$metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json $metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json
if ($Preview) { if ($Preview) {
$release = $metadata.PreviewReleaseTag -replace '^v' $release = $metadata.PreviewReleaseTag -replace '^v'
@ -381,7 +381,7 @@ try {
Write-Host " Latest release is $release for $architecture, package name is: $packageName" Write-Host " Latest release is $release for $architecture, package name is: $packageName"
$downloadURL = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/${packageName}" $downloadURL = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/${packageName}"
Write-Host "⏳ (2/4) Loading $downloadURL" Write-Host "⏳ (2/5) Loading $downloadURL"
$packagePath = Join-Path -Path $tempDir -ChildPath $packageName $packagePath = Join-Path -Path $tempDir -ChildPath $packageName
if (!$PSVersionTable.ContainsKey('PSEdition') -or $PSVersionTable.PSEdition -eq "Desktop") { if (!$PSVersionTable.ContainsKey('PSEdition') -or $PSVersionTable.PSEdition -eq "Desktop") {
@ -424,13 +424,13 @@ try {
Expand-ArchiveInternal -Path $packagePath -DestinationPath $contentPath Expand-ArchiveInternal -Path $packagePath -DestinationPath $contentPath
} }
} else { } else {
Write-Host "⏳ (3/4) Extracting package to: $contentPath..." Write-Host "⏳ (3/5) Extracting package to $contentPath..."
tar zxf $packagePath -C $contentPath tar zxf $packagePath -C $contentPath
} }
} }
if (-not $UseMSI) { if (-not $UseMSI) {
Write-Host "⏳ (4/5) Removing current installation at: $Destination ..." Write-Host "⏳ (4/5) Removing old installation at $Destination ..."
if ($IsLinuxEnv) { if ($IsLinuxEnv) {
& sudo rm -rf "$Destination" & sudo rm -rf "$Destination"
} else { } else {
@ -438,18 +438,18 @@ try {
} }
if (Test-Path $Destination) { if (Test-Path $Destination) {
Write-Host "⏳ (4/4) Copying files to $Destination... " Write-Host "⏳ (4/5) Copying files to $Destination... "
# only copy files as folders will already exist at $Destination # only copy files as folders will already exist at $Destination
Get-ChildItem -Recurse -Path "$contentPath" -File | ForEach-Object { Get-ChildItem -Recurse -Path "$contentPath" -File | ForEach-Object {
$DestinationFilePath = Join-Path $Destination $_.fullname.replace($contentPath, "") $DestinationFilePath = Join-Path $Destination $_.fullname.replace($contentPath, "")
Copy-Item $_.fullname -Destination $DestinationFilePath Copy-Item $_.fullname -Destination $DestinationFilePath
} }
} elseif ($IsWinEnv) { } elseif ($IsWinEnv) {
Write-Host "⏳ (4/4) Moving new installation to $Destination... " Write-Host "⏳ (4/5) Moving new installation to $Destination... "
$null = New-Item -Path (Split-Path -Path $Destination -Parent) -ItemType Directory -ErrorAction SilentlyContinue $null = New-Item -Path (Split-Path -Path $Destination -Parent) -ItemType Directory -ErrorAction SilentlyContinue
Move-Item -Path $contentPath -Destination $Destination Move-Item -Path $contentPath -Destination $Destination
} else { } else {
Write-Host "⏳ (4/4) Moving new installation to $Destination... " Write-Host "⏳ (4/5) Moving new installation to $Destination... "
& sudo mv "$contentPath" "$Destination" & sudo mv "$contentPath" "$Destination"
} }
} }
@ -519,7 +519,7 @@ try {
} }
if (-not $UseMSI) { if (-not $UseMSI) {
Write-Host "Installed PowerShell $release at $Destination" -noNewline Write-Host "PowerShell $release installed at $Destination" -noNewline
if ($Destination -eq $PSHOME) { if ($Destination -eq $PSHOME) {
Write-Host " - Please restart pwsh now." Write-Host " - Please restart pwsh now."
} else { } else {