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

Added functionality to install the User variant of Stable Edition #2160

Merged
merged 7 commits into from
Sep 5, 2019
Merged
58 changes: 40 additions & 18 deletions scripts/Install-VSCode.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#PSScriptInfo

.VERSION 1.3
.VERSION 1.4

.GUID 539e5585-7a02-4dd6-b9a6-5dd288d0a5d0

Expand All @@ -25,6 +25,8 @@
.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
30/08/2019 - added functionality to install the "User Install" variant of Stable Edition.
--
07/11/2018 - added support for PowerShell Core and macOS/Linux platforms.
--
15/08/2018 - added functionality to install the new "User Install" variant of Insiders Edition.
Expand Down Expand Up @@ -128,12 +130,12 @@
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[parameter()]
[ValidateSet(, "64-bit", "32-bit")]
[string]$Architecture = "64-bit",
[ValidateSet('64-bit', '32-bit')]
[string]$Architecture = '64-bit',

[parameter()]
[ValidateSet("Stable", "Insider-System", "Insider-User")]
[string]$BuildEdition = "Stable",
[ValidateSet('Stable-System', 'Stable-User', 'Insider-System', 'Insider-User')]
[string]$BuildEdition = "Stable-System",

[Parameter()]
[ValidateNotNull()]
Expand Down Expand Up @@ -166,7 +168,7 @@ gpgkey=https://packages.microsoft.com/keys/microsoft.asc

function Test-IsOsArchX64 {
if ($PSVersionTable.PSVersion.Major -lt 6) {
return (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq "64-bit"
return (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq '64-bit'
}

return [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq [System.Runtime.InteropServices.Architecture]::X64
Expand Down Expand Up @@ -199,7 +201,7 @@ function Get-CodePlatformInformation {
$Bitness,

[Parameter(Mandatory=$true)]
[ValidateSet('Stable', 'Insider-System', 'Insider-User')]
[ValidateSet('Stable-System', 'Stable-User', 'Insider-System', 'Insider-User')]
[string]
$BuildEdition
)
Expand All @@ -226,11 +228,16 @@ function Get-CodePlatformInformation {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
$appName = "Visual Studio Code ($Bitness)"
break
}

'Stable-User' {
$appName = "Visual Studio Code ($($Architecture) - User)"
Copy link
Member

Choose a reason for hiding this comment

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

Any reason you used $Architecture here instead of $Bitness like System?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, I did the same as the Insiders Edition - user install.

break
}

'Insider-System' {
$appName = "Visual Studio Code - Insiders Edition ($Bitness)"
break
Expand Down Expand Up @@ -318,10 +325,14 @@ function Get-CodePlatformInformation {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
$exePath = "$installBase\Microsoft VS Code\bin\code.cmd"
}

'Stable-User' {
Lothindir marked this conversation as resolved.
Show resolved Hide resolved
$exePath = "${env:LocalAppData}\Programs\Microsoft VS Code\bin\code.cmd"
}

'Insider-System' {
$exePath = "$installBase\Microsoft VS Code Insiders\bin\code-insiders.cmd"
}
Expand All @@ -334,11 +345,17 @@ function Get-CodePlatformInformation {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
$channel = 'stable'
break
}

'Stable-User' {
$channel = 'stable'
$platform += '-user'
break
}

'Insider-System' {
$channel = 'insider'
break
Expand Down Expand Up @@ -388,19 +405,19 @@ function Save-WithBitsTransfer {

$bitsDl = Start-BitsTransfer $FileUri -Destination $Destination -Asynchronous

while (($bitsDL.JobState -eq "Transferring") -or ($bitsDL.JobState -eq "Connecting")) {
while (($bitsDL.JobState -eq 'Transferring') -or ($bitsDL.JobState -eq 'Connecting')) {
Write-Progress -Activity "Downloading: $AppName" -Status "$([math]::round($bitsDl.BytesTransferred / 1mb))mb / $([math]::round($bitsDl.BytesTotal / 1mb))mb" -PercentComplete ($($bitsDl.BytesTransferred) / $($bitsDl.BytesTotal) * 100 )
}

switch ($bitsDl.JobState) {

"Transferred" {
'Transferred' {
Complete-BitsTransfer -BitsJob $bitsDl
break
}

"Error" {
throw "Error downloading installation media."
'Error' {
throw 'Error downloading installation media.'
}
}
}
Expand All @@ -417,7 +434,7 @@ function Install-VSCodeFromTar {
)

$tarDir = Join-Path ([System.IO.Path]::GetTempPath()) 'VSCodeTar'
$destDir = "/opt/VSCode-linux-x64"
$destDir = '/opt/VSCode-linux-x64'

New-Item -ItemType Directory -Force -Path $tarDir
try {
Expand All @@ -439,7 +456,12 @@ function Install-VSCodeFromTar {

# We need to be running as elevated on *nix
if (($IsLinux -or $IsMacOS) -and (id -u) -ne 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like -User editions only apply on Windows (we could install anywhere on Linux from a tar and possibly the same on macOS, but it's likely more complexity than it's worth).

In that case, you might want to add another error message here when the $BuildEdition ends in User but we're on macOS or Linux, to say something like VSCode user installation is only supported on Windows

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a similar check at line 226.
It would fire after your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in b696783

throw "Must be running as root to install VSCode.`nInvoke this script with (for example):`n`tsudo pwsh -f Install-VSCode.ps1 -BuildEdition Stable"
throw "Must be running as root to install VSCode.`nInvoke this script with (for example):`n`tsudo pwsh -f Install-VSCode.ps1 -BuildEdition Stable-System"
}

# User builds can only be installed on Windows systems
if ($BuildEdition.EndsWith('User') -and -not ($IsWindows -or $PSVersionTable.PSVersion.Major -lt 5)) {
throw 'User builds are not available for non-Windows systems'
}

try {
Expand Down Expand Up @@ -506,7 +528,7 @@ try {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
& $pacMan install -y code
}

Expand Down Expand Up @@ -550,7 +572,7 @@ try {
break
}

Install-VSCodeFromTar -TarPath $installerPath -Insiders:($BuildEdition -ne 'Stable')
Install-VSCodeFromTar -TarPath $installerPath -Insiders:($BuildEdition -ne 'Stable-System')
break
}

Expand Down