diff --git a/scripts/obtain/dotnet-install.ps1 b/scripts/obtain/dotnet-install.ps1 index c2f5e6d15..737928e49 100644 --- a/scripts/obtain/dotnet-install.ps1 +++ b/scripts/obtain/dotnet-install.ps1 @@ -10,18 +10,14 @@ Installs dotnet cli. If dotnet installation already exists in the given directory it will update it only if the requested version differs from the one already installed. .PARAMETER Channel - Default: preview - Channel is the way of reasoning about stability and quality of dotnet. This parameter takes one of the values: - - future - Possibly unstable, frequently changing, may contain new finished and unfinished features - - preview - Pre-release stable with known issues and feature gaps - - production - Most stable releases + Default: master + Download from the Channel specified .PARAMETER Version Default: latest Represents a build version on specific channel. Possible values: - - 4-part version in a format A.B.C.D - represents specific version of build - latest - most latest build on specific channel - - lkg - last known good version on specific channel - Note: LKG work is in progress. Once the work is finished, this will become new default + - 3-part version in a format A.B.C - represents specific version of build + examples: 2.0.0-preview2-006120; 1.1.0 .PARAMETER InstallDir Default: %LocalAppData%\Microsoft\dotnet Path to where to install dotnet. Note that binaries will be placed directly in a given directory. @@ -46,7 +42,11 @@ Displays diagnostics information. .PARAMETER AzureFeed Default: https://dotnetcli.azureedge.net/dotnet - This parameter should not be usually changed by user. It allows to change URL for the Azure feed used by this installer. + This parameter typically is not changed by the user. + It allows to change URL for the Azure feed used by this installer. +.PARAMETER UncachedFeed + This parameter typically is not changed by the user. + It allows to change URL for the Uncached feed used by this installer. .PARAMETER ProxyAddress If set, the installer will use the proxy when making web requests .PARAMETER ProxyUseDefaultCredentials @@ -55,7 +55,7 @@ #> [cmdletbinding()] param( - [string]$Channel="rel-1.0.0", + [string]$Channel="master", [string]$Version="Latest", [string]$InstallDir="<auto>", [string]$Architecture="<auto>", @@ -149,8 +149,8 @@ function GetHTTPResponse([Uri] $Uri) $HttpClient = New-Object System.Net.Http.HttpClient } # Default timeout for HttpClient is 100s. For a 50 MB download this assumes 500 KB/s average, any less will time out - # 5 minutes allows it to work over much slower connections. - $HttpClient.Timeout = New-TimeSpan -Minutes 5 + # 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))) { @@ -173,15 +173,15 @@ function GetHTTPResponse([Uri] $Uri) } -function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [string]$CLIArchitecture) { +function Get-Latest-Version-Info([string]$AzureFeed, [string]$Channel, [string]$CLIArchitecture) { Say-Invocation $MyInvocation $VersionFileUrl = $null if ($SharedRuntime) { - $VersionFileUrl = "$UncachedFeed/$AzureChannel/dnvm/latest.sharedfx.win.$CLIArchitecture.version" + $VersionFileUrl = "$UncachedFeed/Runtime/$Channel/latest.version" } else { - $VersionFileUrl = "$UncachedFeed/Sdk/$AzureChannel/latest.version" + $VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.version" } $Response = GetHTTPResponse -Uri $VersionFileUrl @@ -189,7 +189,7 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [str switch ($Response.Content.Headers.ContentType) { { ($_ -eq "application/octet-stream") } { $VersionText = [Text.Encoding]::UTF8.GetString($StringContent) } - { ($_ -eq "text/plain") } { $VersionText = $StringContent } + { ($_ -eq "text/plain") } { ($_ -eq "text/plain; charset=UTF-8") } { $VersionText = $StringContent } default { throw "``$Response.Content.Headers.ContentType`` is an unknown .version file content type." } } @@ -198,38 +198,26 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [str return $VersionInfo } -# TODO: AzureChannel and Channel should be unified -function Get-Azure-Channel-From-Channel([string]$Channel) { - Say-Invocation $MyInvocation - # For compatibility with build scripts accept also directly Azure channels names - switch ($Channel.ToLower()) { - { ($_ -eq "future") -or ($_ -eq "dev") } { return "dev" } - { $_ -eq "production" } { throw "Production channel does not exist yet" } - default { return $_ } - } -} - -function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$AzureChannel, [string]$CLIArchitecture, [string]$Version) { +function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel, [string]$CLIArchitecture, [string]$Version) { Say-Invocation $MyInvocation switch ($Version.ToLower()) { { $_ -eq "latest" } { - $LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture + $LatestVersionInfo = Get-Latest-Version-Info -AzureFeed $AzureFeed -Channel $Channel -CLIArchitecture $CLIArchitecture return $LatestVersionInfo.Version } - { $_ -eq "lkg" } { throw "``-Version LKG`` not supported yet." } default { return $Version } } } -function Get-Download-Links([string]$AzureFeed, [string]$AzureChannel, [string]$SpecificVersion, [string]$CLIArchitecture) { +function Get-Download-Links([string]$AzureFeed, [string]$Channel, [string]$SpecificVersion, [string]$CLIArchitecture) { Say-Invocation $MyInvocation $ret = @() if ($SharedRuntime) { - $PayloadURL = "$AzureFeed/$AzureChannel/Binaries/$SpecificVersion/dotnet-win-$CLIArchitecture.$SpecificVersion.zip" + $PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-sharedframework-win-$CLIArchitecture.$SpecificVersion.zip" } else { $PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-dev-win-$CLIArchitecture.$SpecificVersion.zip" @@ -394,10 +382,9 @@ function Prepend-Sdk-InstallRoot-To-Path([string]$InstallRoot, [string]$BinFolde } } -$AzureChannel = Get-Azure-Channel-From-Channel -Channel $Channel $CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture -$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture -Version $Version -$DownloadLinks = Get-Download-Links -AzureFeed $AzureFeed -AzureChannel $AzureChannel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture +$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -CLIArchitecture $CLIArchitecture -Version $Version +$DownloadLinks = Get-Download-Links -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture if ($DryRun) { Say "Payload URLs:" diff --git a/scripts/obtain/dotnet-install.sh b/scripts/obtain/dotnet-install.sh index ecb28613b..337662e6b 100755 --- a/scripts/obtain/dotnet-install.sh +++ b/scripts/obtain/dotnet-install.sh @@ -111,6 +111,22 @@ get_os_download_name_from_platform() { get_current_os_name() { eval $invocation + local uname=$(uname) + if [ "$uname" = "Darwin" ]; then + echo "osx" + return 0 + else [ "$uname" = "Linux" ]; then + echo "linux" + return 0 + fi + + say_err "OS name could not be detected: $ID.$VERSION_ID" + return 1 +} + +get_distro_specific_os_name() { + eval $invocation + local uname=$(uname) if [ "$uname" = "Darwin" ]; then echo "osx" @@ -140,12 +156,19 @@ machine_has() { return $? } + check_min_reqs() { - if ! machine_has "curl"; then - say_err "curl is required to download dotnet. Install curl to proceed." + local hasMinimum=false + if machine_has "curl"; then + hasMinimum=true; + fi + if machine_has "wget"; then + hasMinimum=true; + fi + if [ "$hasMinimum" = "false" ]; then + say_err "curl (recommended) or wget are required to download dotnet. Install missing prerequisite to proceed." return 1 fi - return 0 } @@ -307,23 +330,20 @@ is_dotnet_package_installed() { # args: # azure_feed - $1 -# azure_channel - $2 +# channel - $2 # normalized_architecture - $3 get_latest_version_info() { eval $invocation local azure_feed=$1 - local azure_channel=$2 + local channel=$2 local normalized_architecture=$3 - - local osname - osname=$(get_current_os_name) || return 1 local version_file_url=null if [ "$shared_runtime" = true ]; then - version_file_url="$uncached_feed/$azure_channel/dnvm/latest.sharedfx.$osname.$normalized_architecture.version" + version_file_url="$uncached_feed/Runtime/$channel/latest.version" else - version_file_url="$uncached_feed/Sdk/$azure_channel/latest.version" + version_file_url="$uncached_feed/Sdk/$channel/latest.version" fi say_verbose "get_latest_version_info: latest url: $version_file_url" @@ -331,51 +351,27 @@ get_latest_version_info() { return $? } -# args: -# channel - $1 -get_azure_channel_from_channel() { - eval $invocation - - local channel=$(to_lowercase $1) - case $channel in - future|dev) - echo "dev" - return 0 - ;; - production) - say_err "Production channel does not exist yet" - return 1 - esac - - echo $channel - return 0 -} - # args: # azure_feed - $1 -# azure_channel - $2 +# channel - $2 # normalized_architecture - $3 # version - $4 get_specific_version_from_version() { eval $invocation local azure_feed=$1 - local azure_channel=$2 + local channel=$2 local normalized_architecture=$3 local version=$(to_lowercase $4) case $version in latest) local version_info - version_info="$(get_latest_version_info $azure_feed $azure_channel $normalized_architecture)" || return 1 + version_info="$(get_latest_version_info $azure_feed $channel $normalized_architecture)" || return 1 say_verbose "get_specific_version_from_version: version_info=$version_info" echo "$version_info" | get_version_from_version_info return 0 ;; - lkg) - say_err "``--version LKG`` not supported yet." - return 1 - ;; *) echo $version return 0 @@ -385,23 +381,23 @@ get_specific_version_from_version() { # args: # azure_feed - $1 -# azure_channel - $2 +# channel - $2 # normalized_architecture - $3 # specific_version - $4 construct_download_link() { eval $invocation local azure_feed=$1 - local azure_channel=$2 + local channel=$2 local normalized_architecture=$3 local specific_version=${4//[$'\t\r\n']} local osname osname=$(get_current_os_name) || return 1 - + local download_link=null if [ "$shared_runtime" = true ]; then - download_link="$azure_feed/$azure_channel/Binaries/$specific_version/dotnet-$osname-$normalized_architecture.$specific_version.tar.gz" + download_link="$azure_feed/Runtime/$specific_version/dotnet-sharedframework-$osname-$normalized_architecture.$specific_version.tar.gz" else download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$osname-$normalized_architecture.$specific_version.tar.gz" fi @@ -410,6 +406,33 @@ construct_download_link() { return 0 } +# args: +# azure_feed - $1 +# channel - $2 +# normalized_architecture - $3 +# specific_version - $4 +construct_alt_download_link() { + eval $invocation + + local azure_feed=$1 + local channel=$2 + local normalized_architecture=$3 + local specific_version=${4//[$'\t\r\n']} + + local distro_specific_osname + distro_specific_osname=$(get_distro_specific_os_name) || return 1 + + local alt_download_link=null + if [ "$shared_runtime" = true ]; then + alt_download_link="$azure_feed/Runtime/$specific_version/dotnet-sharedframework-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz" + else + alt_download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$distro_specific_osname-$normalized_architecture.$specific_version.tar.gz" + fi + + echo "$alt_download_link" + return 0 +} + get_user_install_path() { eval $invocation @@ -520,42 +543,70 @@ extract_dotnet_package() { # [out_path] - $2 - stdout if not provided download() { eval $invocation - + local remote_path=$1 local out_path=${2:-} local failed=false - if [ -z "$out_path" ]; then - curl --fail -s $remote_path || failed=true - else - curl --fail -s -o $out_path $remote_path || failed=true + if machine_has "curl"; then + downloadcurl $remote_path $out_path || failed=true + elif machine_has "wget"; then + downloadwget $remote_path $out_path || failed=true fi - if [ "$failed" = true ]; then say_err "Download failed" return 1 fi } +downloadcurl() { + eval $invocation + local remote_path=$1 + local out_path=${2:-} + + local failed=false + if [ -z "$out_path" ]; then + curl --retry 10 -sSL --create-dirs $remote_path || failed=true + else + curl --retry 10 -sSL --create-dirs -o $out_path $remote_path || failed=true + fi +} + +downloadwget() { + eval $invocation + local remote_path=$1 + local out_path=${2:-} + + local failed=false + if [ -z "$out_path" ]; then + wget -q --tries 10 $remote_path || failed=true + else + wget -v --tries 10 -O $out_path $remote_path || failed=true + fi +} + calculate_vars() { eval $invocation - azure_channel=$(get_azure_channel_from_channel "$channel") - say_verbose "azure_channel=$azure_channel" - normalized_architecture=$(get_normalized_architecture_from_architecture "$architecture") say_verbose "normalized_architecture=$normalized_architecture" - specific_version=$(get_specific_version_from_version $azure_feed $azure_channel $normalized_architecture $version) + specific_version=$(get_specific_version_from_version $azure_feed $channel $normalized_architecture $version) say_verbose "specific_version=$specific_version" if [ -z "$specific_version" ]; then say_err "Could not get version information." return 1 fi - download_link=$(construct_download_link $azure_feed $azure_channel $normalized_architecture $specific_version) + download_link=$(construct_download_link $azure_feed $channel $normalized_architecture $specific_version) say_verbose "download_link=$download_link" - + + if [ "$uname" = "Linux" ]; then + alt_download_link=$(construct_alt_download_link $azure_feed $channel $normalized_architecture $specific_version) + say_verbose "alt_download_link=$alt_download_link" + return 0 + fi + install_root=$(resolve_installation_path $install_dir) say_verbose "install_root=$install_root" } @@ -574,6 +625,14 @@ install_dotnet() { say "Downloading $download_link" download "$download_link" $zip_path + + # if the download fails, download the alt_download_link + if [ "$uname" = "Linux" ] && [ -r $zip_path ]; then + say "Downloading $alt_download_link" + download "$alt_download_link" $zip_path + return 0 + fi + say_verbose "Downloaded file exists and readable? $(if [ -r $zip_path ]; then echo "yes"; else echo "no"; fi)" say "Extracting zip" @@ -586,7 +645,7 @@ local_version_file_relative_path="/.version" bin_folder_relative_path="" temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX" -channel="rel-1.0.0" +channel="master" version="Latest" install_dir="<auto>" architecture="<auto>" @@ -638,6 +697,10 @@ do shift azure_feed="$1" ;; + --uncached-feed|-[Uu]ncached[Ff]eed) + shift + uncached_feed="$1" + ;; --runtime-id|-[Rr]untime[Ii]d) shift runtime_id="$1" @@ -653,7 +716,7 @@ do echo "Options:" echo " -c,--channel <CHANNEL> Download from the CHANNEL specified (default: $channel)." echo " -Channel" - echo " -v,--version <VERSION> Use specific version, ``latest`` or ``lkg``. Defaults to ``latest``." + echo " -v,--version <VERSION> Use specific version, ``latest``. Defaults to ``latest``." echo " -Version" echo " -i,--install-dir <DIR> Install under specified location (see Install Location below)" echo " -InstallDir" @@ -665,7 +728,8 @@ do 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." - echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed" + echo " --azure-feed,-AzureFeed Azure feed location. Defaults to $azure_feed, This parameter typically is not changed by the user." + echo " --uncached-feed,-UncachedFeed Uncached feed location. This parameter typically is not changed by the user." echo " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)." echo " -RuntimeId" echo " -?,--?,-h,--help,-Help Shows this help message" @@ -690,6 +754,10 @@ check_min_reqs calculate_vars if [ "$dry_run" = true ]; then say "Payload URL: $download_link" + if [ "$uname" = "Linux" ]; then + say "Alternate payload URL: $alt_download_link" + return 0 + fi say "Repeatable invocation: ./$(basename $0) --version $specific_version --channel $channel --install-dir $install_dir" exit 0 fi