Merge pull request #1367 from dotnet/prkrishn/dotnet-install

* Add support for specifying a version in obtain/install
This commit is contained in:
Andrew Stanton-Nurse 2016-02-11 11:23:26 -08:00
commit 9cda2703f3
2 changed files with 46 additions and 22 deletions

View file

@ -3,15 +3,21 @@
# Licensed under the MIT license. See LICENSE file in the project root for full license information. # Licensed under the MIT license. See LICENSE file in the project root for full license information.
# #
param([string]$Channel="dev") param(
[string]$Channel="dev",
[string]$version="Latest"
)
$ErrorActionPreference="Stop" $ErrorActionPreference="Stop"
$ProgressPreference="SilentlyContinue" $ProgressPreference="SilentlyContinue"
$fileVersion = $Version
if ($fileVersion -eq "Latest") {
$fileVersion = "latest"
}
$Feed="https://dotnetcli.blob.core.windows.net/dotnet" $Feed="https://dotnetcli.blob.core.windows.net/dotnet"
$DotNetFileName="dotnet-win-x64.latest.zip" $DotNetFileName="dotnet-win-x64.$fileVersion.zip"
$DotNetUrl="$Feed/$Channel/Binaries/Latest" $DotNetUrl="$Feed/$Channel/Binaries/$Version"
function say($str) function say($str)
{ {
@ -34,21 +40,29 @@ if (Test-Path $LocalFile)
$LocalVersion = $LocalData[1].Trim() $LocalVersion = $LocalData[1].Trim()
if ($LocalVersion -and $LocalHash) if ($LocalVersion -and $LocalHash)
{ {
$RemoteResponse = Invoke-WebRequest -UseBasicParsing "$Feed/$Channel/dnvm/latest.win.version" if ($Version -eq "Latest")
$RemoteData = @([Text.Encoding]::UTF8.GetString($RemoteResponse.Content).Split([char[]]@(), [StringSplitOptions]::RemoveEmptyEntries));
$RemoteHash = $RemoteData[0].Trim()
$RemoteVersion = $RemoteData[1].Trim()
if (!$RemoteVersion -or !$RemoteHash) {
throw "Invalid response from feed"
}
say "Latest version: $RemoteVersion"
say "Local Version: $LocalVersion"
if($LocalHash -eq $RemoteHash)
{ {
say "You already have the latest version" $RemoteResponse = Invoke-WebRequest -UseBasicParsing "$Feed/$Channel/dnvm/latest.win.version"
$RemoteData = @([Text.Encoding]::UTF8.GetString($RemoteResponse.Content).Split([char[]]@(), [StringSplitOptions]::RemoveEmptyEntries));
$RemoteHash = $RemoteData[0].Trim()
$RemoteVersion = $RemoteData[1].Trim()
if (!$RemoteVersion -or !$RemoteHash) {
throw "Invalid response from feed"
}
say "Latest version: $RemoteVersion"
say "Local Version: $LocalVersion"
if($LocalHash -eq $RemoteHash)
{
say "You already have the latest version"
exit 0
}
}
elseif ($LocalVersion -eq $Version)
{
say "$Version is already installed."
exit 0 exit 0
} }
} }

View file

@ -1,5 +1,3 @@
#!/usr/bin/env sh
#
# Copyright (c) .NET Foundation and contributors. All rights reserved. # Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information. # Licensed under the MIT license. See LICENSE file in the project root for full license information.
# #
@ -162,10 +160,17 @@ install_dotnet()
say_err "Ending install due to missing pre-reqs" say_err "Ending install due to missing pre-reqs"
return 1; return 1;
fi fi
if [ "$VERSION" == "Latest" ]; then
local fileVersion=latest
else
local fileVersion=$VERSION
fi
local os=$(current_os) local os=$(current_os)
local installLocation="$PREFIX/share/dotnet" local installLocation="$PREFIX/share/dotnet"
local dotnet_url="https://dotnetcli.blob.core.windows.net/dotnet/$CHANNEL/Binaries/Latest" local dotnet_url="https://dotnetcli.blob.core.windows.net/dotnet/$CHANNEL/Binaries/$VERSION"
local dotnet_filename="dotnet-$os-x64.latest.tar.gz" local dotnet_filename="dotnet-$os-x64.$fileVersion.tar.gz"
if [ "$RELINK" = "0" ]; then if [ "$RELINK" = "0" ]; then
if [ "$FORCE" = "0" ]; then if [ "$FORCE" = "0" ]; then
@ -246,6 +251,10 @@ do
shift shift
CHANNEL=$1 CHANNEL=$1
;; ;;
-v|--version)
shift
VERSION=$1
;;
-d|--destination) -d|--destination)
shift shift
DOTNET_INSTALL_DIR=$1 DOTNET_INSTALL_DIR=$1
@ -288,5 +297,6 @@ elif [ -z "$PREFIX" ]; then
fi fi
[ -z "$CHANNEL" ] && CHANNEL="dev" [ -z "$CHANNEL" ] && CHANNEL="dev"
[ -z "$VERSION" ] && VERSION="Latest"
install_dotnet install_dotnet