From 0722cce59027167ceabd6bf54d7fcd8b71fef1d0 Mon Sep 17 00:00:00 2001 From: John Beisner Date: Fri, 22 Sep 2017 11:25:15 -0700 Subject: [PATCH] Update the installation scripts in release/2.0.0 branch. --- scripts/obtain/dotnet-install.ps1 | 81 +++++++++++++++++-------------- scripts/obtain/dotnet-install.sh | 49 ++++++++++++++++--- 2 files changed, 85 insertions(+), 45 deletions(-) diff --git a/scripts/obtain/dotnet-install.ps1 b/scripts/obtain/dotnet-install.ps1 index 427995b86..89e6e74d8 100644 --- a/scripts/obtain/dotnet-install.ps1 +++ b/scripts/obtain/dotnet-install.ps1 @@ -58,6 +58,9 @@ .PARAMETER ProxyUseDefaultCredentials Default: false 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()] param( @@ -71,7 +74,8 @@ param( [string]$AzureFeed="https://dotnetcli.azureedge.net/dotnet", [string]$UncachedFeed="https://dotnetcli.blob.core.windows.net/dotnet", [string]$ProxyAddress, - [switch]$ProxyUseDefaultCredentials + [switch]$ProxyUseDefaultCredentials, + [switch]$SkipNonVersionedFiles ) Set-StrictMode -Version Latest @@ -82,10 +86,10 @@ $BinFolderRelativePath="" # example path with regex: shared/1.0.0-beta-12345/somepath $VersionRegEx="/\d+\.\d+[^/]+/" -$OverrideNonVersionedFiles=$true +$OverrideNonVersionedFiles = !$SkipNonVersionedFiles function Say($str) { - Write-Output "dotnet-install: $str" + Write-Host "dotnet-install: $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. Load-Assembly -Assembly System.Net.Http - if(-not $ProxyAddress) - { - # Despite no proxy being explicitly specified, we may still be behind a default proxy - $DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy; - if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))){ - $ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString - $ProxyUseDefaultCredentials = $true + if(-not $ProxyAddress) { + try { + # Despite no proxy being explicitly specified, we may still be behind a default proxy + $DefaultProxy = [System.Net.WebRequest]::DefaultWebProxy; + if($DefaultProxy -and (-not $DefaultProxy.IsBypassed($Uri))) { + $ProxyAddress = $DefaultProxy.GetProxy($Uri).OriginalString + $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.Proxy = New-Object System.Net.WebProxy -Property @{Address=$ProxyAddress;UseDefaultCredentials=$ProxyUseDefaultCredentials} $HttpClient = New-Object System.Net.Http.HttpClient -ArgumentList $HttpClientHandler - } + } else { $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. $HttpClient.Timeout = New-TimeSpan -Minutes 10 $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." - if ($Response -ne $null) - { + if ($Response -ne $null) { $ErrorMsg += " $Response" } @@ -208,7 +216,7 @@ function GetHTTPResponse([Uri] $Uri) $HttpClient.Dispose() } } - }) + }) } @@ -227,7 +235,7 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [bool]$Co $VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.version" } } - + $Response = GetHTTPResponse -Uri $VersionFileUrl $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 - + if ($SharedRuntime) { $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 } -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 - + if ($SharedRuntime) { $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 Say-Verbose "Local version file: $VersionFile" - + if (Test-Path $VersionFile) { $VersionText = cat $VersionFile 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) { Say-Invocation $MyInvocation - + $DotnetPackagePath = Join-Path -Path $InstallRoot -ChildPath $RelativePathToPackage | Join-Path -ChildPath $SpecificVersion Say-Verbose "Is-Dotnet-Package-Installed: Path to a package: $DotnetPackagePath" return Test-Path $DotnetPackagePath -PathType Container @@ -346,13 +354,13 @@ function Get-Path-Prefix-With-Version($path) { if ($match.Success) { return $entry.FullName.Substring(0, $match.Index + $match.Length) } - + return $null } function Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package([System.IO.Compression.ZipArchive]$Zip, [string]$OutPath) { Say-Invocation $MyInvocation - + $ret = @() foreach ($entry in $Zip.Entries) { $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 - + $values = ($ret | foreach { "$_" }) -join ";" Say-Verbose "Directories to unpack: $values" - + return $ret } @@ -392,9 +400,9 @@ function Extract-Dotnet-Package([string]$ZipPath, [string]$OutPath) { Set-Variable -Name Zip try { $Zip = [System.IO.Compression.ZipFile]::OpenRead($ZipPath) - + $DirectoriesToUnpack = Get-List-Of-Directories-And-Versions-To-Unpack-From-Dotnet-Package -Zip $Zip -OutPath $OutPath - + foreach ($entry in $Zip.Entries) { $PathWithVersion = Get-Path-Prefix-With-Version $entry.FullName 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 $SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -Version $Version -$DownloadLink = Get-Download-Link -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture -$LegacyDownloadLink = Get-LegacyDownload-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 -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture if ($DryRun) { Say "Payload URLs:" Say "Primary - $DownloadLink" Say "Legacy - $LegacyDownloadLink" - Say "Repeatable invocation: .\$($MyInvocation.MyCommand) -Version $SpecificVersion -Channel $Channel -Architecture $CLIArchitecture -InstallDir $InstallDir" + Say "Repeatable invocation: .\$($MyInvocation.Line)" exit 0 } @@ -470,14 +478,13 @@ if ($IsSdkInstalled) { New-Item -ItemType Directory -Force -Path $InstallRoot | Out-Null $installDrive = $((Get-Item $InstallRoot).PSDrive.Name); -Write-Output "${installDrive}:"; $free = Get-CimInstance -Class win32_logicaldisk | where Deviceid -eq "${installDrive}:" if ($free.Freespace / 1MB -le 100 ) { Say "There is not enough disk space on drive ${installDrive}:" 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 "Downloading link: $DownloadLink" try { @@ -486,7 +493,7 @@ try { catch { Say "Cannot download: $DownloadLink" $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 "Downloading legacy link: $DownloadLink" DownloadFile -Uri $DownloadLink -OutPath $ZipPath diff --git a/scripts/obtain/dotnet-install.sh b/scripts/obtain/dotnet-install.sh index 451525269..d27e0d48d 100755 --- a/scripts/obtain/dotnet-install.sh +++ b/scripts/obtain/dotnet-install.sh @@ -55,6 +55,9 @@ say_verbose() { 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() { eval $invocation @@ -84,6 +87,10 @@ get_os_download_name_from_platform() { echo "opensuse.42.1" return 0 ;; + "rhel.6"*) + echo "rhel.6" + return 0 + ;; "rhel.7"*) echo "rhel" return 0 @@ -115,8 +122,14 @@ get_current_os_name() { if [ "$uname" = "Darwin" ]; then echo "osx" return 0 - else - if [ "$uname" = "Linux" ]; then + elif [ "$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" return 0 fi @@ -144,6 +157,12 @@ get_distro_specific_os_name() { echo "$os" return 0 fi + elif [ -e /etc/redhat-release ]; then + local redhatRelease=$(&1 || download_failed=true # if the download fails, download the legacy_download_link 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 shared_runtime=false runtime_id="" +override_non_versioned_files=true while [ $# -ne 0 ] do @@ -732,6 +759,10 @@ do shift 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) script_name="$(basename $0)" echo ".NET Tools Installer" @@ -764,6 +795,8 @@ do echo " --arch,-Architecture,-Arch" echo " --shared-runtime Installs just the shared runtime bits, not the entire SDK." 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 " --no-path, -NoPath Do not set PATH for the current process." echo " --verbose,-Verbose Display diagnostics information."