Skip to content
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.

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

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

Merged
merged 6 commits into from
Nov 14, 2017

Conversation

SteveL-MSFT
Copy link
Member

To make it easier to selfhost daily:

  1. removed [validate] attribute from parameter so this script can be invoked directly from web.
    This doesn't have any negative impact as the $Destination parameter will have default value if null or empty.
  2. moved removal of destination folder later as installing the package requires packagemanagement module and archive module (on Windows)
  3. on Windows, because files have open handles when run from existing powershell-daily install, I rename the existing files and copy over the new ones. User needs to exit and restart pwsh to take effect (similar to macOS/Linux where you have to exit and restart anyways)

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing.

@@ -50,16 +55,31 @@ if (-not $Destination) {
$Destination = "${Destination}-daily"
}
}
Write-Verbose "Destination: $Destination" -Verbose
Copy link
Member

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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update

@@ -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
Copy link
Member

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
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update

}

Remove-Destination $Destination
Move-Item -Path "$Destination.new" -Destination $Destination
Copy link
Member

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).

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

if (Test-Path -Path "$Destination.old") {
Remove-Item "$Destination.old" -Recurse -Force
}
if ($IsWinEnv -and ($Destination -eq $PSHome)) {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

}

Remove-Destination $Destination
Move-Item -Path "$Destination.new" -Destination $Destination
Copy link
Member

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.

Copy-Item -Path $contentPath\* -Destination $Destination -Recurse -Force
if (Test-Path $Destination) {
Write-Verbose "Copying files" -Verbose
Copy-Item -Recurse -Path "$contentPath\*" -Destination $Destination -ErrorAction Ignore
Copy link
Member

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.

Copy link
Member Author

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


$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
Copy link
Member

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 ...

Copy link
Member Author

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

@TravisEz13
Copy link
Member

restarted macOS ci

@SteveL-MSFT
Copy link
Member Author

Still testing, don't merge yet

@SteveL-MSFT
Copy link
Member Author

Working for me. I think it's ready to go.

@daxian-dbw daxian-dbw merged commit 83e1d64 into PowerShell:master Nov 14, 2017
@SteveL-MSFT SteveL-MSFT deleted the install-powershell branch November 15, 2017 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants