Merge pull request #6664 from johnbeisner/InstallScripts

Linux distro update for dotnet-install.sh; et al.
This commit is contained in:
jbeisner 2017-05-23 17:28:29 -07:00 committed by GitHub
commit 911236d964
2 changed files with 167 additions and 98 deletions

View file

@ -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: release/1.0.0
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="release/1.0.0",
[string]$Version="Latest",
[string]$InstallDir="<auto>",
[string]$Architecture="<auto>",
@ -160,8 +160,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)))
{
@ -184,15 +184,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) {
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
@ -201,6 +201,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; charset=UTF-8") } { $VersionText = $StringContent }
default { throw "``$Response.Content.Headers.ContentType`` is an unknown .version file content type." }
}
@ -209,38 +210,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]$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
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-win-$CLIArchitecture.$SpecificVersion.zip"
}
else {
$PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-dev-win-$CLIArchitecture.$SpecificVersion.zip"
@ -405,10 +394,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 -Version $Version
$DownloadLinks = Get-Download-Links -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
if ($DryRun) {
Say "Payload URLs:"

View file

@ -111,6 +111,24 @@ get_os_download_name_from_platform() {
get_current_os_name() {
eval $invocation
local uname=$(uname)
if [ "$uname" = "Darwin" ]; then
echo "osx"
return 0
else
if [ "$uname" = "Linux" ]; then
echo "linux"
return 0
fi
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 +158,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
elif 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
}
@ -168,7 +193,6 @@ check_pre_reqs() {
[ -z "$($LDCONFIG_COMMAND -p | grep libunwind)" ] && say_err "Unable to locate libunwind. Install libunwind to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND -p | grep libssl)" ] && say_err "Unable to locate libssl. Install libssl to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND -p | grep libcurl)" ] && say_err "Unable to locate libcurl. Install libcurl to continue" && failing=true
[ -z "$($LDCONFIG_COMMAND -p | grep libicu)" ] && say_err "Unable to locate libicu. Install libicu to continue" && failing=true
fi
@ -252,12 +276,12 @@ get_normalized_architecture_from_architecture() {
return 0
;;
x86)
say_err "Architecture ``x86`` currently not supported"
say_err "Architecture \`x86\` currently not supported"
return 1
;;
esac
say_err "Architecture ``$architecture`` not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues"
say_err "Architecture \`$architecture\` not supported. If you think this is a bug, please report it at https://github.com/dotnet/cli/issues"
return 1
}
@ -307,23 +331,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 +352,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 +382,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-$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 +407,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-$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,49 +544,90 @@ 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 machine_has "curl"; then
downloadcurl $remote_path $out_path || failed=true
elif machine_has "wget"; then
downloadwget $remote_path $out_path || failed=true
else
failed=true
fi
if [ "$failed" = true ]; then
say_verbose "Download failed: $remote_path"
return 1
fi
return 0
}
downloadcurl() {
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
curl --retry 10 -sSL -f --create-dirs $remote_path || failed=true
else
curl --fail -s -o $out_path $remote_path || failed=true
curl --retry 10 -sSL -f --create-dirs -o $out_path $remote_path || failed=true
fi
if [ "$failed" = true ]; then
say_err "Download failed"
say_verbose "Curl download failed"
return 1
fi
return 0
}
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
if [ "$failed" = true ]; then
say_verbose "Wget download failed"
return 1
fi
return 0
}
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"
fi
install_root=$(resolve_installation_path $install_dir)
say_verbose "install_root=$install_root"
}
install_dotnet() {
eval $invocation
local download_failed=false
if is_dotnet_package_installed $install_root "sdk" $specific_version; then
say ".NET SDK version $specific_version is already installed."
return 0
@ -571,10 +636,18 @@ install_dotnet() {
mkdir -p $install_root
zip_path=$(mktemp $temporary_file_template)
say_verbose "Zip path: $zip_path"
say "Downloading $download_link"
download "$download_link" $zip_path
say_verbose "Downloaded file exists and readable? $(if [ -r $zip_path ]; then echo "yes"; else echo "no"; fi)"
say "Downloading link: $download_link"
download "$download_link" $zip_path || download_failed=true
# if the download fails, download the alt_download_link [Linux only]
if [ "$(uname)" = "Linux" ] && [ "$download_failed" = true ]; then
say "Cannot download: $download_link"
zip_path=$(mktemp $temporary_file_template)
say_verbose "Alternate zip path: $zip_path"
say "Downloading alternate link: $alt_download_link"
download "$alt_download_link" $zip_path
fi
say "Extracting zip"
extract_dotnet_package $zip_path $install_root
@ -586,7 +659,7 @@ local_version_file_relative_path="/.version"
bin_folder_relative_path=""
temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX"
channel="rel-1.0.0"
channel="release/1.0.0"
version="Latest"
install_dir="<auto>"
architecture="<auto>"
@ -638,6 +711,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 +730,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, or \`latest\`. Defaults to \`latest\`."
echo " -Version"
echo " -i,--install-dir <DIR> Install under specified location (see Install Location below)"
echo " -InstallDir"
@ -665,7 +742,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 +768,9 @@ 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"
fi
say "Repeatable invocation: ./$(basename $0) --version $specific_version --channel $channel --install-dir $install_dir"
exit 0
fi
@ -699,7 +780,7 @@ install_dotnet
bin_path=$(get_absolute_path $(combine_paths $install_root $bin_folder_relative_path))
if [ "$no_path" = false ]; then
say "Adding to current process PATH: ``$bin_path``. Note: This change will be visible only when sourcing script."
say "Adding to current process PATH: \`$bin_path\`. Note: This change will be visible only when sourcing script."
export PATH=$bin_path:$PATH
else
say "Binaries of dotnet can be found in $bin_path"