GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enable install-powershell.ps1 to work from powershell-daily folder by SteveL-MSFT · Pull Request #5429 · PowerShell/PowerShell

Enable install-powershell.ps1 to work from powershell-daily folder #5429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Dongbo Wang (daxian-dbw) merged 6 commits into PowerShell:master from SteveL-MSFT:install-powershell
Nov 14, 2017

Uh oh!

There was an error while loading. Please reload this page.

Merged

Enable install-powershell.ps1 to work from powershell-daily folder #5429

Changes from 3 commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
e58ec0e
remove [validate] attribute so script can be called directly from inv…
SteveL-MSFT Nov 12, 2017
402eb03
enable installing daily build using $env:PSCoreDaily
SteveL-MSFT Nov 12, 2017
5c1c8e2
if using from same folder as being installed for daily, rename existi…
SteveL-MSFT Nov 13, 2017
391ac68
remove $env:pscoredaily usage, can use: iex "& { $(irm 'url') } -daily"
SteveL-MSFT Nov 13, 2017
117427b
address PR feedback
SteveL-MSFT Nov 13, 2017
c1dc92f
fix copying of files to correct destination folder
SteveL-MSFT Nov 14, 2017
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

62 changes: 48 additions & 14 deletions 62 tools/install-powershell.ps1
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
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

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

Will update

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

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

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

Sure

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
# 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

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

All reactions
Copy-Item -Recurse -Path "$contentPath\*" -Destination $Destination -ErrorAction Ignore
Comment thread Outdated

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

All reactions
} 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

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

Will update

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions

@SteveL-MSFT Steve Lee (SteveL-MSFT) Nov 13, 2017

Copy link
Copy Markdown
Member Author

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.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Nov 13, 2017

Copy link
Copy Markdown
Member

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.

All reactions
}

## 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
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.