Update the installation scripts in release/2.0.0 branch.

This commit is contained in:
John Beisner 2017-09-22 11:25:15 -07:00
parent 5d4d7bf619
commit 0722cce590
2 changed files with 85 additions and 45 deletions

View file

@ -58,6 +58,9 @@
.PARAMETER ProxyUseDefaultCredentials .PARAMETER ProxyUseDefaultCredentials
Default: false Default: false
Use default credentials, when using proxy address. Use default credentials, when using proxy address.
.PARAMETER SkipNonVersionedFiles
Default: false
Skips installing non-versioned files if they already exist, such as dotnet.exe.
#> #>
[cmdletbinding()] [cmdletbinding()]
param( param(
@ -71,7 +74,8 @@ param(
[string]$AzureFeed="https://dotnetcli.azureedge.net/dotnet", [string]$AzureFeed="https://dotnetcli.azureedge.net/dotnet",
[string]$UncachedFeed="https://dotnetcli.blob.core.windows.net/dotnet", [string]$UncachedFeed="https://dotnetcli.blob.core.windows.net/dotnet",
[string]$ProxyAddress, [string]$ProxyAddress,
[switch]$ProxyUseDefaultCredentials [switch]$ProxyUseDefaultCredentials,
[switch]$SkipNonVersionedFiles
) )
Set-StrictMode -Version Latest Set-StrictMode -Version Latest
@ -82,10 +86,10 @@ $BinFolderRelativePath=""
# example path with regex: shared/1.0.0-beta-12345/somepath # example path with regex: shared/1.0.0-beta-12345/somepath
$VersionRegEx="/\d+\.\d+[^/]+/" $VersionRegEx="/\d+\.\d+[^/]+/"
$OverrideNonVersionedFiles=$true $OverrideNonVersionedFiles = !$SkipNonVersionedFiles
function Say($str) { function Say($str) {
Write-Output "dotnet-install: $str" Write-Host "dotnet-install: $str"
} }
function Say-Verbose($str) { function Say-Verbose($str) {
@ -168,21 +172,27 @@ function GetHTTPResponse([Uri] $Uri)
# HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet. # HttpClient is used vs Invoke-WebRequest in order to support Nano Server which doesn't support the Invoke-WebRequest cmdlet.
Load-Assembly -Assembly System.Net.Http Load-Assembly -Assembly System.Net.Http
if(-not $ProxyAddress) if(-not $ProxyAddress) {
{ try {
# Despite no proxy being explicitly specified, we may still be behind a default proxy # Despite no proxy being explicitly specified, we may still be behind a default proxy
$DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy; $DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy;
if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){ if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))) {
$ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString $ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString
$ProxyUseDefaultCredentials = $true $ProxyUseDefaultCredentials = $true
}
} catch {
# Eat the exception and move forward as the above code is an attempt
# at resolving the DefaultProxy that may not have been a problem.
$ProxyAddress = $null
Say-Verbose("Exception ignored: $_.Exception.Message - moving forward...")
} }
} }
if($ProxyAddress){ if($ProxyAddress) {
$HttpClientHandler = New-Object System.Net.Http.HttpClientHandler $HttpClientHandler = New-Object System.Net.Http.HttpClientHandler
$HttpClientHandler.Proxy = New-Object System.Net.WebProxy -Property @{Address=$ProxyAddress;UseDefaultCredentials=$ProxyUseDefaultCredentials} $HttpClientHandler.Proxy = New-Object System.Net.WebProxy -Property @{Address=$ProxyAddress;UseDefaultCredentials=$ProxyUseDefaultCredentials}
$HttpClient = New-Object System.Net.Http.HttpClient -ArgumentList $HttpClientHandler $HttpClient = New-Object System.Net.Http.HttpClient -ArgumentList $HttpClientHandler
} }
else { else {
$HttpClient = New-Object System.Net.Http.HttpClient $HttpClient = New-Object System.Net.Http.HttpClient
} }
@ -190,11 +200,9 @@ function GetHTTPResponse([Uri] $Uri)
# 10 minutes allows it to work over much slower connections. # 10 minutes allows it to work over much slower connections.
$HttpClient.Timeout = New-TimeSpan -Minutes 10 $HttpClient.Timeout = New-TimeSpan -Minutes 10
$Response = $HttpClient.GetAsync($Uri).Result $Response = $HttpClient.GetAsync($Uri).Result
if (($Response -eq $null) -or (-not ($Response.IsSuccessStatusCode))) if (($Response -eq $null) -or (-not ($Response.IsSuccessStatusCode))) {
{
$ErrorMsg = "Failed to download $Uri." $ErrorMsg = "Failed to download $Uri."
if ($Response -ne $null) if ($Response -ne $null) {
{
$ErrorMsg += " $Response" $ErrorMsg += " $Response"
} }
@ -208,7 +216,7 @@ function GetHTTPResponse([Uri] $Uri)
$HttpClient.Dispose() $HttpClient.Dispose()
} }
} }
}) })
} }
@ -227,7 +235,7 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co
$VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.version" $VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.version"
} }
} }
$Response = GetHTTPResponse -Uri $VersionFileUrl $Response = GetHTTPResponse -Uri $VersionFileUrl
$StringContent = $Response.Content.ReadAsStringAsync().Result $StringContent = $Response.Content.ReadAsStringAsync().Result
@ -260,9 +268,9 @@ function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel,
} }
} }
function Get-Download-Link([string]$AzureFeed, [string]$Channel, [string]$SpecificVersion, [string]$CLIArchitecture) { function Get-Download-Link([string]$AzureFeed, [string]$SpecificVersion, [string]$CLIArchitecture) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
if ($SharedRuntime) { if ($SharedRuntime) {
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-runtime-$SpecificVersion-win-$CLIArchitecture.zip" $PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-runtime-$SpecificVersion-win-$CLIArchitecture.zip"
} }
@ -275,9 +283,9 @@ function Get-Download-Link([string]$AzureFeed, [string]$Channel, [string]$Specif
return $PayloadURL return $PayloadURL
} }
function Get-LegacyDownload-Link([string]$AzureFeed, [string]$Channel, [string]$SpecificVersion, [string]$CLIArchitecture) { function Get-LegacyDownload-Link([string]$AzureFeed, [string]$SpecificVersion, [string]$CLIArchitecture) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
if ($SharedRuntime) { if ($SharedRuntime) {
$PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-win-$CLIArchitecture.$SpecificVersion.zip" $PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-win-$CLIArchitecture.$SpecificVersion.zip"
} }
@ -314,7 +322,7 @@ function Get-Version-Info-From-Version-File([string]$InstallRoot, [string]$Relat
$VersionFile = Join-Path -Path $InstallRoot -ChildPath $RelativePathToVersionFile $VersionFile = Join-Path -Path $InstallRoot -ChildPath $RelativePathToVersionFile
Say-Verbose "Local version file: $VersionFile" Say-Verbose "Local version file: $VersionFile"
if (Test-Path $VersionFile) { if (Test-Path $VersionFile) {
$VersionText = cat $VersionFile $VersionText = cat $VersionFile
Say-Verbose "Local version file text: $VersionText" Say-Verbose "Local version file text: $VersionText"
@ -328,7 +336,7 @@ function Get-Version-Info-From-Version-File([string]$InstallRoot, [string]$Relat
function Is-Dotnet-Package-Installed([string]$InstallRoot, [string]$RelativePathToPackage, [string]$SpecificVersion) { function Is-Dotnet-Package-Installed([string]$InstallRoot, [string]$RelativePathToPackage, [string]$SpecificVersion) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
$DotnetPackagePath = Join-Path -Path $InstallRoot -ChildPath $RelativePathToPackage | Join-Path -ChildPath $SpecificVersion $DotnetPackagePath = Join-Path -Path $InstallRoot -ChildPath $RelativePathToPackage | Join-Path -ChildPath $SpecificVersion
Say-Verbose "Is-Dotnet-Package-Installed: Path to a package: $DotnetPackagePath" Say-Verbose "Is-Dotnet-Package-Installed: Path to a package: $DotnetPackagePath"
return Test-Path $DotnetPackagePath -PathType Container return Test-Path $DotnetPackagePath -PathType Container
@ -346,13 +354,13 @@ function Get-Path-Prefix-With-Version($path) {
if ($match.Success) { if ($match.Success) {
return $entry.FullName.Substring(0, $match.Index + $match.Length) return $entry.FullName.Substring(0, $match.Index + $match.Length)
} }
return $null return $null
} }
function Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package([System.IO.Compression.ZipArchive]$Zip, [string]$OutPath) { function Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package([System.IO.Compression.ZipArchive]$Zip, [string]$OutPath) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
$ret = @() $ret = @()
foreach ($entry in $Zip.Entries) { foreach ($entry in $Zip.Entries) {
$dir = Get-Path-Prefix-With-Version $entry.FullName $dir = Get-Path-Prefix-With-Version $entry.FullName
@ -363,12 +371,12 @@ function Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package([Sys
} }
} }
} }
$ret = $ret | Sort-Object | Get-Unique $ret = $ret | Sort-Object | Get-Unique
$values = ($ret | foreach { "$_" }) -join ";" $values = ($ret | foreach { "$_" }) -join ";"
Say-Verbose "Directories to unpack: $values" Say-Verbose "Directories to unpack: $values"
return $ret return $ret
} }
@ -392,9 +400,9 @@ function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) {
Set-Variable -Name Zip Set-Variable -Name Zip
try { try {
$Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath) $Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath)
$DirectoriesToUnpack = Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package -Zip $Zip -OutPath $OutPath $DirectoriesToUnpack = Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package -Zip $Zip -OutPath $OutPath
foreach ($entry in $Zip.Entries) { foreach ($entry in $Zip.Entries) {
$PathWithVersion = Get-Path-Prefix-With-Version $entry.FullName $PathWithVersion = Get-Path-Prefix-With-Version $entry.FullName
if (($PathWithVersion -eq $null) -Or ($DirectoriesToUnpack -contains $PathWithVersion)) { if (($PathWithVersion -eq $null) -Or ($DirectoriesToUnpack -contains $PathWithVersion)) {
@ -445,14 +453,14 @@ function Prepend-Sdk-InstallRoot-To-Path([string]$InstallRoot, [string]$BinFolde
$CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture $CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version $SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version
$DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture $DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
$LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture $LegacyDownloadLink = Get-LegacyDownload-Link -AzureFeed $AzureFeed -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
if ($DryRun) { if ($DryRun) {
Say "Payload URLs:" Say "Payload URLs:"
Say "Primary - $DownloadLink" Say "Primary - $DownloadLink"
Say "Legacy - $LegacyDownloadLink" Say "Legacy - $LegacyDownloadLink"
Say "Repeatable invocation: .\$($MyInvocation.MyCommand) -Version $SpecificVersion -Channel $Channel -Architecture $CLIArchitecture -InstallDir $InstallDir" Say "Repeatable invocation: .\$($MyInvocation.Line)"
exit 0 exit 0
} }
@ -470,14 +478,13 @@ if ($IsSdkInstalled) {
New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null
$installDrive = $((Get-Item $InstallRoot).PSDrive.Name); $installDrive = $((Get-Item $InstallRoot).PSDrive.Name);
Write-Output "${installDrive}:";
$free = Get-CimInstance -Class win32_logicaldisk | where Deviceid -eq "${installDrive}:" $free = Get-CimInstance -Class win32_logicaldisk | where Deviceid -eq "${installDrive}:"
if ($free.Freespace / 1MB -le 100 ) { if ($free.Freespace / 1MB -le 100 ) {
Say "There is not enough disk space on drive ${installDrive}:" Say "There is not enough disk space on drive ${installDrive}:"
exit 0 exit 0
} }
$ZipPath = [System.IO.Path]::GetTempFileName() $ZipPath = [System.IO.Path]::combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
Say-Verbose "Zip path: $ZipPath" Say-Verbose "Zip path: $ZipPath"
Say "Downloading link: $DownloadLink" Say "Downloading link: $DownloadLink"
try { try {
@ -486,7 +493,7 @@ try {
catch { catch {
Say "Cannot download: $DownloadLink" Say "Cannot download: $DownloadLink"
$DownloadLink = $LegacyDownloadLink $DownloadLink = $LegacyDownloadLink
$ZipPath = [System.IO.Path]::GetTempFileName() $ZipPath = [System.IO.Path]::combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName())
Say-Verbose "Legacy zip path: $ZipPath" Say-Verbose "Legacy zip path: $ZipPath"
Say "Downloading legacy link: $DownloadLink" Say "Downloading legacy link: $DownloadLink"
DownloadFile -Uri $DownloadLink -OutPath $ZipPath DownloadFile -Uri $DownloadLink -OutPath $ZipPath

View file

@ -55,6 +55,9 @@ say_verbose() {
fi fi
} }
# This platform list is finite - if the SDK/Runtime has supported Linux distribution-specific assets,
# then and only then should the Linux distribution appear in this list.
# Adding a Linux distribution to this list does not imply distribution-specific support.
get_os_download_name_from_platform() { get_os_download_name_from_platform() {
eval $invocation eval $invocation
@ -84,6 +87,10 @@ get_os_download_name_from_platform() {
echo "opensuse.42.1" echo "opensuse.42.1"
return 0 return 0
;; ;;
"rhel.6"*)
echo "rhel.6"
return 0
;;
"rhel.7"*) "rhel.7"*)
echo "rhel" echo "rhel"
return 0 return 0
@ -115,8 +122,14 @@ get_current_os_name() {
if [ "$uname" = "Darwin" ]; then if [ "$uname" = "Darwin" ]; then
echo "osx" echo "osx"
return 0 return 0
else elif [ "$uname" = "Linux" ]; then
if [ "$uname" = "Linux" ]; then local distro_specific_osname
distro_specific_osname=$(get_distro_specific_os_name) || return 1
if [ "$distro_specific_osname" = "rhel.6" ]; then
echo $distro_specific_osname
return 0
else
echo "linux" echo "linux"
return 0 return 0
fi fi
@ -144,6 +157,12 @@ get_distro_specific_os_name() {
echo "$os" echo "$os"
return 0 return 0
fi fi
elif [ -e /etc/redhat-release ]; then
local redhatRelease=$(</etc/redhat-release)
if [[ $redhatRelease == "CentOS release 6."* || $redhatRelease == "Red Hat Enterprise Linux Server release 6."* ]]; then
echo "rhel.6"
return 0
fi
fi fi
fi fi
@ -191,9 +210,13 @@ check_pre_reqs() {
LDCONFIG_COMMAND="ldconfig" LDCONFIG_COMMAND="ldconfig"
fi fi
[ -z "$($LDCONFIG_COMMAND -p | grep libunwind)" ] && say_err "Unable to locate libunwind. Install libunwind to continue" && failing=true local librarypath=${LD_LIBRARY_PATH:-}
[ -z "$($LDCONFIG_COMMAND -p | grep libssl)" ] && say_err "Unable to locate libssl. Install libssl to continue" && failing=true LDCONFIG_COMMAND="$LDCONFIG_COMMAND -NXv ${LD_LIBRARY_PATH//:/ }"
[ -z "$($LDCONFIG_COMMAND -p | grep libicu)" ] && say_err "Unable to locate libicu. Install libicu to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND | grep libunwind)" ] && say_err "Unable to locate libunwind. Install libunwind to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND | grep libssl)" ] && say_err "Unable to locate libssl. Install libssl to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND | grep libicu)" ] && say_err "Unable to locate libicu. Install libicu to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND | grep -F libcurl.so)" ] && say_err "Unable to locate libcurl. Install libcurl to continue" && failing=true
fi fi
if [ "$failing" = true ]; then if [ "$failing" = true ]; then
@ -333,6 +356,7 @@ is_dotnet_package_installed() {
# azure_feed - $1 # azure_feed - $1
# channel - $2 # channel - $2
# normalized_architecture - $3 # normalized_architecture - $3
# coherent - $4
get_latest_version_info() { get_latest_version_info() {
eval $invocation eval $invocation
@ -541,7 +565,7 @@ extract_dotnet_package() {
local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/' local folders_with_version_regex='^.*/[0-9]+\.[0-9]+[^/]+/'
find $temp_out_path -type f | grep -Eo $folders_with_version_regex | copy_files_or_dirs_from_list $temp_out_path $out_path false find $temp_out_path -type f | grep -Eo $folders_with_version_regex | copy_files_or_dirs_from_list $temp_out_path $out_path false
find $temp_out_path -type f | grep -Ev $folders_with_version_regex | copy_files_or_dirs_from_list $temp_out_path $out_path true find $temp_out_path -type f | grep -Ev $folders_with_version_regex | copy_files_or_dirs_from_list $temp_out_path $out_path $override_non_versioned_files
rm -rf $temp_out_path rm -rf $temp_out_path
@ -600,7 +624,7 @@ downloadwget() {
local failed=false local failed=false
if [ -z "$out_path" ]; then if [ -z "$out_path" ]; then
wget -q --tries 10 $remote_path || failed=true wget -q --tries 10 -O - $remote_path || failed=true
else else
wget -v --tries 10 -O $out_path $remote_path || failed=true wget -v --tries 10 -O $out_path $remote_path || failed=true
fi fi
@ -654,7 +678,9 @@ install_dotnet() {
say_verbose "Zip path: $zip_path" say_verbose "Zip path: $zip_path"
say "Downloading link: $download_link" say "Downloading link: $download_link"
download "$download_link" $zip_path || download_failed=true # Failures are normal in the non-legacy case for ultimately legacy downloads.
# Do not output to stderr, since output to stderr is considered an error.
download "$download_link" $zip_path 2>&1 || download_failed=true
# if the download fails, download the legacy_download_link # if the download fails, download the legacy_download_link
if [ "$download_failed" = true ] && [ "$valid_legacy_download_link" = true ]; then if [ "$download_failed" = true ] && [ "$valid_legacy_download_link" = true ]; then
@ -687,6 +713,7 @@ uncached_feed="https://dotnetcli.blob.core.windows.net/dotnet"
verbose=false verbose=false
shared_runtime=false shared_runtime=false
runtime_id="" runtime_id=""
override_non_versioned_files=true
while [ $# -ne 0 ] while [ $# -ne 0 ]
do do
@ -732,6 +759,10 @@ do
shift shift
runtime_id="$1" runtime_id="$1"
;; ;;
--skip-non-versioned-files|-[Ss]kip[Nn]on[Vv]ersioned[Ff]iles)
shift
override_non_versioned_files=false
;;
-?|--?|-h|--help|-[Hh]elp) -?|--?|-h|--help|-[Hh]elp)
script_name="$(basename $0)" script_name="$(basename $0)"
echo ".NET Tools Installer" echo ".NET Tools Installer"
@ -764,6 +795,8 @@ do
echo " --arch,-Architecture,-Arch" echo " --arch,-Architecture,-Arch"
echo " --shared-runtime Installs just the shared runtime bits, not the entire SDK." echo " --shared-runtime Installs just the shared runtime bits, not the entire SDK."
echo " -SharedRuntime" echo " -SharedRuntime"
echo " --skip-non-versioned-files Skips non-versioned files if they already exist, such as the dotnet executable."
echo " -SkipNonVersionedFiles"
echo " --dry-run,-DryRun Do not perform installation. Display download link." echo " --dry-run,-DryRun Do not perform installation. Display download link."
echo " --no-path, -NoPath Do not set PATH for the current process." echo " --no-path, -NoPath Do not set PATH for the current process."
echo " --verbose,-Verbose Display diagnostics information." echo " --verbose,-Verbose Display diagnostics information."