First draft changes for install script for the SDK and Runtime.

This commit is contained in:
John Beisner 2017-05-22 12:53:52 -07:00
parent 3037fdd688
commit 3db157aba6
2 changed files with 146 additions and 91 deletions

View file

@ -10,18 +10,14 @@
Installs dotnet cli. If dotnet installation already exists in the given directory 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. it will update it only if the requested version differs from the one already installed.
.PARAMETER Channel .PARAMETER Channel
Default: preview Default: master
Channel is the way of reasoning about stability and quality of dotnet. This parameter takes one of the values: Download from the Channel specified
- 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
.PARAMETER Version .PARAMETER Version
Default: latest Default: latest
Represents a build version on specific channel. Possible values: 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 - latest - most latest build on specific channel
- lkg - last known good version on specific channel - 3-part version in a format A.B.C - represents specific version of build
Note: LKG work is in progress. Once the work is finished, this will become new default examples: 2.0.0-preview2-006120; 1.1.0
.PARAMETER InstallDir .PARAMETER InstallDir
Default: %LocalAppData%\Microsoft\dotnet Default: %LocalAppData%\Microsoft\dotnet
Path to where to install dotnet. Note that binaries will be placed directly in a given directory. Path to where to install dotnet. Note that binaries will be placed directly in a given directory.
@ -46,7 +42,11 @@
Displays diagnostics information. Displays diagnostics information.
.PARAMETER AzureFeed .PARAMETER AzureFeed
Default: https://dotnetcli.azureedge.net/dotnet 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 .PARAMETER ProxyAddress
If set, the installer will use the proxy when making web requests If set, the installer will use the proxy when making web requests
.PARAMETER ProxyUseDefaultCredentials .PARAMETER ProxyUseDefaultCredentials
@ -55,7 +55,7 @@
#> #>
[cmdletbinding()] [cmdletbinding()]
param( param(
[string]$Channel="rel-1.0.0", [string]$Channel="master",
[string]$Version="Latest", [string]$Version="Latest",
[string]$InstallDir="<auto>", [string]$InstallDir="<auto>",
[string]$Architecture="<auto>", [string]$Architecture="<auto>",
@ -149,8 +149,8 @@ function GetHTTPResponse([Uri] $Uri)
$HttpClient = New-Object System.Net.Http.HttpClient $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 # 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. # 10 minutes allows it to work over much slower connections.
$HttpClient.Timeout = New-TimeSpan -Minutes 5 $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)))
{ {
@ -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 Say-Invocation $MyInvocation
$VersionFileUrl = $null $VersionFileUrl = $null
if ($SharedRuntime) { if ($SharedRuntime) {
$VersionFileUrl = "$UncachedFeed/$AzureChannel/dnvm/latest.sharedfx.win.$CLIArchitecture.version" $VersionFileUrl = "$UncachedFeed/Runtime/$Channel/latest.version"
} }
else { else {
$VersionFileUrl = "$UncachedFeed/Sdk/$AzureChannel/latest.version" $VersionFileUrl = "$UncachedFeed/Sdk/$Channel/latest.version"
} }
$Response = GetHTTPResponse -Uri $VersionFileUrl $Response = GetHTTPResponse -Uri $VersionFileUrl
@ -189,7 +189,7 @@ function Get-Latest-Version-Info([string]$AzureFeed, [string]$AzureChannel, [str
switch ($Response.Content.Headers.ContentType) { switch ($Response.Content.Headers.ContentType) {
{ ($_ -eq "application/octet-stream") } { $VersionText = [Text.Encoding]::UTF8.GetString($StringContent) } { ($_ -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." } 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 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 function Get-Specific-Version-From-Version([string]$AzureFeed, [string]$Channel, [string]$CLIArchitecture, [string]$Version) {
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) {
Say-Invocation $MyInvocation Say-Invocation $MyInvocation
switch ($Version.ToLower()) { switch ($Version.ToLower()) {
{ $_ -eq "latest" } { { $_ -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 return $LatestVersionInfo.Version
} }
{ $_ -eq "lkg" } { throw "``-Version LKG`` not supported yet." }
default { return $Version } 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 Say-Invocation $MyInvocation
$ret = @() $ret = @()
if ($SharedRuntime) { if ($SharedRuntime) {
$PayloadURL = "$AzureFeed/$AzureChannel/Binaries/$SpecificVersion/dotnet-win-$CLIArchitecture.$SpecificVersion.zip" $PayloadURL = "$AzureFeed/Runtime/$SpecificVersion/dotnet-sharedframework-win-$CLIArchitecture.$SpecificVersion.zip"
} }
else { else {
$PayloadURL = "$AzureFeed/Sdk/$SpecificVersion/dotnet-dev-win-$CLIArchitecture.$SpecificVersion.zip" $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 $CLIArchitecture = Get-CLIArchitecture-From-Architecture $Architecture
$SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -AzureChannel $AzureChannel -CLIArchitecture $CLIArchitecture -Version $Version $SpecificVersion = Get-Specific-Version-From-Version -AzureFeed $AzureFeed -Channel $Channel -CLIArchitecture $CLIArchitecture -Version $Version
$DownloadLinks = Get-Download-Links -AzureFeed $AzureFeed -AzureChannel $AzureChannel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture $DownloadLinks = Get-Download-Links -AzureFeed $AzureFeed -Channel $Channel -SpecificVersion $SpecificVersion -CLIArchitecture $CLIArchitecture
if ($DryRun) { if ($DryRun) {
Say "Payload URLs:" Say "Payload URLs:"

View file

@ -111,6 +111,22 @@ get_os_download_name_from_platform() {
get_current_os_name() { get_current_os_name() {
eval $invocation 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) local uname=$(uname)
if [ "$uname" = "Darwin" ]; then if [ "$uname" = "Darwin" ]; then
echo "osx" echo "osx"
@ -140,12 +156,19 @@ machine_has() {
return $? return $?
} }
check_min_reqs() { check_min_reqs() {
if ! machine_has "curl"; then local hasMinimum=false
say_err "curl is required to download dotnet. Install curl to proceed." 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 return 1
fi fi
return 0 return 0
} }
@ -307,23 +330,20 @@ is_dotnet_package_installed() {
# args: # args:
# azure_feed - $1 # azure_feed - $1
# azure_channel - $2 # channel - $2
# normalized_architecture - $3 # normalized_architecture - $3
get_latest_version_info() { get_latest_version_info() {
eval $invocation eval $invocation
local azure_feed=$1 local azure_feed=$1
local azure_channel=$2 local channel=$2
local normalized_architecture=$3 local normalized_architecture=$3
local osname
osname=$(get_current_os_name) || return 1
local version_file_url=null local version_file_url=null
if [ "$shared_runtime" = true ]; then 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 else
version_file_url="$uncached_feed/Sdk/$azure_channel/latest.version" version_file_url="$uncached_feed/Sdk/$channel/latest.version"
fi fi
say_verbose "get_latest_version_info: latest url: $version_file_url" say_verbose "get_latest_version_info: latest url: $version_file_url"
@ -331,51 +351,27 @@ get_latest_version_info() {
return $? 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: # args:
# azure_feed - $1 # azure_feed - $1
# azure_channel - $2 # channel - $2
# normalized_architecture - $3 # normalized_architecture - $3
# version - $4 # version - $4
get_specific_version_from_version() { get_specific_version_from_version() {
eval $invocation eval $invocation
local azure_feed=$1 local azure_feed=$1
local azure_channel=$2 local channel=$2
local normalized_architecture=$3 local normalized_architecture=$3
local version=$(to_lowercase $4) local version=$(to_lowercase $4)
case $version in case $version in
latest) latest)
local version_info 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" say_verbose "get_specific_version_from_version: version_info=$version_info"
echo "$version_info" | get_version_from_version_info echo "$version_info" | get_version_from_version_info
return 0 return 0
;; ;;
lkg)
say_err "``--version LKG`` not supported yet."
return 1
;;
*) *)
echo $version echo $version
return 0 return 0
@ -385,14 +381,14 @@ get_specific_version_from_version() {
# args: # args:
# azure_feed - $1 # azure_feed - $1
# azure_channel - $2 # channel - $2
# normalized_architecture - $3 # normalized_architecture - $3
# specific_version - $4 # specific_version - $4
construct_download_link() { construct_download_link() {
eval $invocation eval $invocation
local azure_feed=$1 local azure_feed=$1
local azure_channel=$2 local channel=$2
local normalized_architecture=$3 local normalized_architecture=$3
local specific_version=${4//[$'\t\r\n']} local specific_version=${4//[$'\t\r\n']}
@ -401,7 +397,7 @@ construct_download_link() {
local download_link=null local download_link=null
if [ "$shared_runtime" = true ]; then 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 else
download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$osname-$normalized_architecture.$specific_version.tar.gz" download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$osname-$normalized_architecture.$specific_version.tar.gz"
fi fi
@ -410,6 +406,33 @@ construct_download_link() {
return 0 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() { get_user_install_path() {
eval $invocation eval $invocation
@ -525,37 +548,65 @@ download() {
local out_path=${2:-} local out_path=${2:-}
local failed=false local failed=false
if [ -z "$out_path" ]; then if machine_has "curl"; then
curl --fail -s $remote_path || failed=true downloadcurl $remote_path $out_path || failed=true
else elif machine_has "wget"; then
curl --fail -s -o $out_path $remote_path || failed=true downloadwget $remote_path $out_path || failed=true
fi fi
if [ "$failed" = true ]; then if [ "$failed" = true ]; then
say_err "Download failed" say_err "Download failed"
return 1 return 1
fi 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() { calculate_vars() {
eval $invocation eval $invocation
azure_channel=$(get_azure_channel_from_channel "$channel")
say_verbose "azure_channel=$azure_channel"
normalized_architecture=$(get_normalized_architecture_from_architecture "$architecture") normalized_architecture=$(get_normalized_architecture_from_architecture "$architecture")
say_verbose "normalized_architecture=$normalized_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" say_verbose "specific_version=$specific_version"
if [ -z "$specific_version" ]; then if [ -z "$specific_version" ]; then
say_err "Could not get version information." say_err "Could not get version information."
return 1 return 1
fi 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" 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) install_root=$(resolve_installation_path $install_dir)
say_verbose "install_root=$install_root" say_verbose "install_root=$install_root"
} }
@ -574,6 +625,14 @@ install_dotnet() {
say "Downloading $download_link" say "Downloading $download_link"
download "$download_link" $zip_path 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_verbose "Downloaded file exists and readable? $(if [ -r $zip_path ]; then echo "yes"; else echo "no"; fi)"
say "Extracting zip" say "Extracting zip"
@ -586,7 +645,7 @@ local_version_file_relative_path="/.version"
bin_folder_relative_path="" bin_folder_relative_path=""
temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX" temporary_file_template="${TMPDIR:-/tmp}/dotnet.XXXXXXXXX"
channel="rel-1.0.0" channel="master"
version="Latest" version="Latest"
install_dir="<auto>" install_dir="<auto>"
architecture="<auto>" architecture="<auto>"
@ -638,6 +697,10 @@ do
shift shift
azure_feed="$1" azure_feed="$1"
;; ;;
--uncached-feed|-[Uu]ncached[Ff]eed)
shift
uncached_feed="$1"
;;
--runtime-id|-[Rr]untime[Ii]d) --runtime-id|-[Rr]untime[Ii]d)
shift shift
runtime_id="$1" runtime_id="$1"
@ -653,7 +716,7 @@ do
echo "Options:" echo "Options:"
echo " -c,--channel <CHANNEL> Download from the CHANNEL specified (default: $channel)." echo " -c,--channel <CHANNEL> Download from the CHANNEL specified (default: $channel)."
echo " -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 " -Version"
echo " -i,--install-dir <DIR> Install under specified location (see Install Location below)" echo " -i,--install-dir <DIR> Install under specified location (see Install Location below)"
echo " -InstallDir" echo " -InstallDir"
@ -665,7 +728,8 @@ do
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."
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 " --runtime-id Installs the .NET Tools for the given platform (use linux-x64 for portable linux)."
echo " -RuntimeId" echo " -RuntimeId"
echo " -?,--?,-h,--help,-Help Shows this help message" echo " -?,--?,-h,--help,-Help Shows this help message"
@ -690,6 +754,10 @@ check_min_reqs
calculate_vars calculate_vars
if [ "$dry_run" = true ]; then if [ "$dry_run" = true ]; then
say "Payload URL: $download_link" 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" say "Repeatable invocation: ./$(basename $0) --version $specific_version --channel $channel --install-dir $install_dir"
exit 0 exit 0
fi fi