mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Refactor .NET CLI installation into Install-Dotnet
So that it can be reinstalled separately if desired. Also removed the set validation as it was now wrong, and removed the warning about no Invoke-WebRequest on Core PowerShell (it is ported now). I don't like the duplicate parameter logic, especially around -NoSudo.
This commit is contained in:
1 parent
fc2c1b9f7d
commit
427435c8fd
1 file changed
+58
-44
+58
-44
@@ -679,12 +679,66 @@ function Start-PSxUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Install-Dotnet {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[string]$Channel = "rel-1.0.0",
|
||||||
|
[string]$Version = "latest",
|
||||||
|
[switch]$NoSudo
|
||||||
|
)
|
||||||
|
|
||||||
|
# This allows sudo install to be optional; needed when running in containers / as root
|
||||||
|
# Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly
|
||||||
|
$sudo = if (!$NoSudo) { "sudo" }
|
||||||
|
|
||||||
|
$obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain"
|
||||||
|
|
||||||
|
# Install for Linux and OS X
|
||||||
|
if ($IsLinux -or $IsOSX) {
|
||||||
|
# Uninstall all previous dotnet packages
|
||||||
|
$uninstallScript = if ($IsUbuntu) {
|
||||||
|
"dotnet-uninstall-debian-packages.sh"
|
||||||
|
} elseif ($IsOSX) {
|
||||||
|
"dotnet-uninstall-pkgs.sh"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($uninstallScript) {
|
||||||
|
Start-NativeExecution {
|
||||||
|
curl -sO $obtainUrl/uninstall/$uninstallScript
|
||||||
|
Invoke-Expression "$sudo bash ./$uninstallScript"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Write-Warning "This script only removes prior versions of dotnet for Ubuntu 14.04 and OS X"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install new dotnet 1.0.0 preview packages
|
||||||
|
$installScript = "dotnet-install.sh"
|
||||||
|
Start-NativeExecution {
|
||||||
|
curl -sO $obtainUrl/$installScript
|
||||||
|
bash ./$installScript -c $Channel -v $Version
|
||||||
|
}
|
||||||
|
|
||||||
|
# .NET Core's crypto library needs brew's OpenSSL libraries added to its rpath
|
||||||
|
if ($IsOSX) {
|
||||||
|
# This is the library shipped with .NET Core
|
||||||
|
# This is allowed to fail as the user may have installed other versions of dotnet
|
||||||
|
Write-Warning ".NET Core links the incorrect OpenSSL, correcting .NET CLI libraries..."
|
||||||
|
find $env:HOME/.dotnet -name System.Security.Cryptography.Native.dylib | xargs sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib
|
||||||
|
}
|
||||||
|
} elseif ($IsWindows) {
|
||||||
|
Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet
|
||||||
|
$installScript = "dotnet-install.ps1"
|
||||||
|
Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript
|
||||||
|
& ./$installScript -c $Channel -v $Version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function Start-PSBootstrap {
|
function Start-PSBootstrap {
|
||||||
[CmdletBinding(
|
[CmdletBinding(
|
||||||
SupportsShouldProcess=$true,
|
SupportsShouldProcess=$true,
|
||||||
ConfirmImpact="High")]
|
ConfirmImpact="High")]
|
||||||
param(
|
param(
|
||||||
[ValidateSet("dev", "beta", "preview")]
|
|
||||||
[string]$Channel = "rel-1.0.0",
|
[string]$Channel = "rel-1.0.0",
|
||||||
[string]$Version = "latest",
|
[string]$Version = "latest",
|
||||||
[switch]$Package,
|
[switch]$Package,
|
||||||
@@ -769,49 +823,11 @@ function Start-PSBootstrap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$obtainUrl = "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain"
|
$DotnetArguments = @{ Channel=$Channel; Version=$Version; NoSudo=$NoSudo }
|
||||||
|
Install-Dotnet @DotnetArguments
|
||||||
# Install for Linux and OS X
|
|
||||||
if ($IsLinux -or $IsOSX) {
|
|
||||||
# Uninstall all previous dotnet packages
|
|
||||||
$uninstallScript = if ($IsUbuntu) {
|
|
||||||
"dotnet-uninstall-debian-packages.sh"
|
|
||||||
} elseif ($IsOSX) {
|
|
||||||
"dotnet-uninstall-pkgs.sh"
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($uninstallScript) {
|
|
||||||
Start-NativeExecution {
|
|
||||||
curl -sO $obtainUrl/uninstall/$uninstallScript
|
|
||||||
Invoke-Expression "$sudo bash ./$uninstallScript"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Write-Warning "This script only removes prior versions of dotnet for Ubuntu 14.04 and OS X"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install new dotnet 1.0.0 preview packages
|
|
||||||
$installScript = "dotnet-install.sh"
|
|
||||||
Start-NativeExecution {
|
|
||||||
curl -sO $obtainUrl/$installScript
|
|
||||||
bash ./$installScript -c $Channel -v $Version
|
|
||||||
}
|
|
||||||
|
|
||||||
# .NET Core's crypto library needs brew's OpenSSL libraries added to its rpath
|
|
||||||
if ($IsOSX) {
|
|
||||||
# This is the library shipped with .NET Core
|
|
||||||
# This is allowed to fail as the user may have installed other versions of dotnet
|
|
||||||
Write-Warning ".NET Core links the incorrect OpenSSL, correcting .NET CLI libraries..."
|
|
||||||
find $env:HOME/.dotnet -name System.Security.Cryptography.Native.dylib | xargs sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Install for Windows
|
# Install for Windows
|
||||||
if ($IsWindows -and -not $IsCoreCLR) {
|
if ($IsWindows) {
|
||||||
Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet
|
|
||||||
$installScript = "dotnet-install.ps1"
|
|
||||||
Invoke-WebRequest -Uri $obtainUrl/$installScript -OutFile $installScript
|
|
||||||
& ./$installScript -c $Channel -v $Version
|
|
||||||
|
|
||||||
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
|
$machinePath = [Environment]::GetEnvironmentVariable('Path', 'MACHINE')
|
||||||
$newMachineEnvironmentPath = $machinePath
|
$newMachineEnvironmentPath = $machinePath
|
||||||
|
|
||||||
@@ -878,8 +894,6 @@ function Start-PSBootstrap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif ($IsWindows) {
|
|
||||||
Write-Warning "Start-PSBootstrap cannot be run in Core PowerShell on Windows (need Invoke-WebRequest!)"
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
Pop-Location
|
Pop-Location
|
||||||
|
|||||||
Reference in new issue
Block a user