|
Expand Up
|
@@ -19,7 +19,6 @@ |
|
|
[CmdletBinding()] |
|
|
param( |
|
|
[Parameter()] |
|
|
[ValidateNotNullOrEmpty()] |
|
|
[string] $Destination, |
|
|
|
|
|
[Parameter()] |
|
Expand All
|
@@ -39,6 +38,12 @@ $IsLinuxEnv = (Get-Variable -Name "IsLinux" -ErrorAction Ignore) -and $IsLinux |
|
|
$IsMacOSEnv = (Get-Variable -Name "IsMacOS" -ErrorAction Ignore) -and $IsMacOS |
|
|
$IsWinEnv = !$IsLinuxEnv -and !$IsMacOSEnv |
|
|
|
|
|
if ($env:PSCoreDaily -eq $true) |
|
|
{ |
|
|
$Daily = $true |
|
|
$AddToPath = $true |
|
|
} |
|
|
|
|
|
if (-not $Destination) { |
|
|
$Destination = if ($IsWinEnv) { |
|
|
"$env:LOCALAPPDATA\Microsoft\powershell" |
|
Expand All
|
@@ -50,16 +55,31 @@ if (-not $Destination) { |
|
|
$Destination = "${Destination}-daily" |
|
|
} |
|
|
} |
|
|
Write-Verbose "Destination: $Destination" -Verbose |
Comment thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should get the unresolved absolute provider path for $Destination. Otherwise, the $Destination -eq $PSHome check below may fail when it should succeed.
You can use
$Destination = $PSCmdlet.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
|
|
|
if (Test-Path -Path $Destination) { |
|
|
if ($DoNotOverwrite) { |
|
|
throw "Destination folder '$Destination' already exist. Use a different path or omit '-DoNotOverwrite' to overwrite." |
|
|
Function Remove-Destination([string] $Destination) { |
|
|
if (Test-Path -Path $Destination) { |
|
|
if ($DoNotOverwrite) { |
|
|
throw "Destination folder '$Destination' already exist. Use a different path or omit '-DoNotOverwrite' to overwrite." |
|
|
} |
|
|
Write-Verbose "Removing old installation: $Destination" -Verbose |
|
|
if (Test-Path -Path "$Destination.old") { |
|
|
Remove-Item "$Destination.old" -Recurse -Force |
|
|
} |
|
|
if ($IsWinEnv -and ($Destination -eq $PSHome)) { |
Comment thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know that on Linux you can delete $PSHome from a running powershell.
Can you please add some comment in Remove-Destination about the different scenarios of the remove operation?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
# handle the case where the updated folder is currently in use |
|
|
Get-ChildItem -Recurse -File -Path $PSHome | ForEach-Object { |
|
|
if ($_.extension -eq "old") { |
|
|
Remove-Item $_ |
|
|
} else { |
|
|
Move-Item $_.fullname "$($_.fullname).old" |
|
|
} |
|
|
} |
|
|
} else { |
|
|
Move-Item "$Destination" "$Destination.old" |
|
|
} |
|
|
} |
|
|
Remove-Item -Path $Destination -Recurse -Force |
|
|
} |
|
|
New-Item -ItemType Directory -Path $Destination -Force > $null |
|
|
$Destination = Resolve-Path -Path $Destination | ForEach-Object -MemberName Path |
|
|
Write-Verbose "Destination: $Destination" -Verbose |
|
|
|
|
|
$architecture = if (-not $IsWinEnv) { |
|
|
"x64" |
|
Expand All
|
@@ -79,7 +99,7 @@ try { |
|
|
} |
|
|
|
|
|
if ($architecture -ne "x64") { |
|
|
throw "The OS architecture is '$architecture'. However, we currently only support daily package for x64 Windows." |
|
|
throw "The OS architecture is '$architecture'. However, we currently only support daily package for x64." |
|
|
} |
|
|
|
|
|
## Register source if not yet |
|
Expand All
|
@@ -99,10 +119,17 @@ try { |
|
|
|
|
|
$package = Find-Package -Source powershell-core-daily -AllowPrereleaseVersions -Name $packageName |
|
|
Write-Verbose "Daily package found. Name: $packageName; Version: $($package.Version)" -Verbose |
|
|
Install-Package -InputObject $package -Destination $tempDir -ExcludeVersion > $null |
|
|
|
|
|
Install-Package -InputObject $package -Destination $tempDir -ExcludeVersion > $null |
|
|
Remove-Destination $Destination |
|
|
|
|
|
$contentPath = [System.IO.Path]::Combine($tempDir, $packageName, "content") |
|
|
Copy-Item -Path $contentPath\* -Destination $Destination -Recurse -Force |
|
|
if (Test-Path $Destination) { |
|
|
Write-Verbose "Copying files" -Verbose |
Comment thread
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this log message should be moved before if (Test-Path $Destination) since both copy-item and move-item would take time. Maybe change the message to Deploying files ...
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move-Item is just updating a single directory pointer so shouldn't take any time
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
Copy-Item -Recurse -Path "$contentPath\*" -Destination $Destination -ErrorAction Ignore |
Comment thread
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't specify -ErrorAction Ignore, if it fails to copy a file then the installation fails. And maybe add -Force.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failure is due to it copying folders, I can change this to filter to just files and letting it fail
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
} else { |
|
|
Move-Item -Path $contentPath -Destination $Destination |
|
|
} |
|
|
} else { |
|
|
$metadata = Invoke-RestMethod https://api.github.com/repos/powershell/powershell/releases/latest |
|
|
$release = $metadata.tag_name -replace '^v' |
|
Expand All
|
@@ -121,15 +148,19 @@ try { |
|
|
$packagePath = Join-Path -Path $tempDir -ChildPath $packageName |
|
|
Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath |
|
|
|
|
|
New-Item -ItemType Directory -Path "$Destination.new" > $null |
Comment thread
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the $tempDir for anything that is temporary, it's cleaner and also prevent the corner case that $Destination.new already exists.
For example
$packageContent = Join-Path -Path $tempDir -ChildPath content
New-Item -ItemType Directory -Path $packageContent > $null
...
if ($IsWinEnv) {
Expand-Archive ... -DestinationPath $packageContent
} else {
tar zxf ... -C $packageContent
}
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
if ($IsWinEnv) { |
|
|
Expand-Archive -Path $packagePath -DestinationPath $Destination |
|
|
Expand-Archive -Path $packagePath -DestinationPath "$Destination.new" |
|
|
} else { |
|
|
tar zxf $packagePath -C $Destination |
|
|
tar zxf $packagePath -C "$Destination.new" |
|
|
} |
|
|
|
|
|
Remove-Destination $Destination |
|
|
Move-Item -Path "$Destination.new" -Destination $Destination |
Comment thread
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can use Move-Item here, I think you can do the same in the daily code path without having to differentiate between $Destination exists or not (line 127).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The differentiation is needed when $Destination is in use (because install-powershell was run from $Destination) so I can't use the Move-Item optimization.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When installing a release package here, the Destination could also be $PSHOME, right?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's true. Will fix.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tried install-powershell.ps1 -Destination $PSHOME on Windows, and new files are not moved to $PSHOME after the run.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
} |
|
|
|
|
|
## Change the mode of 'pwsh' to 'rwxr-xr-x' to allow execution |
|
|
if (-not $IsWinEnv) { chmod 755 "$Destination/pwsh" } |
|
|
if (-not $IsWinEnv) { chmod 755 $Destination/pwsh } |
|
|
|
|
|
if ($AddToPath) { |
|
|
if ($IsWinEnv -and (-not $env:Path.Contains($Destination))) { |
|
Expand Down
Expand Up
|
@@ -179,6 +210,9 @@ try { |
|
|
} |
|
|
|
|
|
Write-Host "PowerShell Core has been installed at $Destination" -ForegroundColor Green |
|
|
if ($Destination -eq $PSHome) { |
|
|
Write-Host "Please restart pwsh" -ForegroundColor Magenta |
|
|
} |
|
|
} finally { |
|
|
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
|
|
} |