diff --git a/dnvm.ps1 b/dnvm.ps1 index 9cad8e576e..53b1381d82 100644 --- a/dnvm.ps1 +++ b/dnvm.ps1 @@ -67,7 +67,7 @@ function _WriteOut { ### Constants $ProductVersion="1.0.0" -$BuildVersion="beta7-10404" +$BuildVersion="beta7-10405" $Authors="Microsoft Open Technologies, Inc." # If the Version hasn't been replaced... @@ -509,6 +509,16 @@ param( } } +function Find-Package { + param( + $runtimeInfo, + [string]$Feed, + [string]$Proxy + ) + $url = "$Feed/Packages()?`$filter=Id eq '$($runtimeInfo.RuntimeId)' and Version eq '$($runtimeInfo.Version)'" + Invoke-NuGetWebRequest $runtimeInfo.RuntimeId $url $Proxy +} + function Find-Latest { param( $runtimeInfo, @@ -521,23 +531,32 @@ function Find-Latest { $RuntimeId = $runtimeInfo.RuntimeId _WriteDebug "Latest RuntimeId: $RuntimeId" $url = "$Feed/GetUpdates()?packageIds=%27$RuntimeId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false" + Invoke-NuGetWebRequest $RuntimeId $url $Proxy +} + +function Invoke-NuGetWebRequest { + param ( + [string]$RuntimeId, + [string]$Url, + [string]$Proxy + ) # NOTE: DO NOT use Invoke-WebRequest. It requires PowerShell 4.0! $wc = New-Object System.Net.WebClient Apply-Proxy $wc -Proxy:$Proxy - _WriteDebug "Downloading $url ..." + _WriteDebug "Downloading $Url ..." try { - [xml]$xml = $wc.DownloadString($url) + [xml]$xml = $wc.DownloadString($Url) } catch { $Script:ExitCode = $ExitCodes.NoRuntimesOnFeed throw "Unable to find any runtime packages on the feed!" } $version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml - if($version) { - _WriteDebug "Found latest version: $version" - $version + $downloadUrl = (Select-Xml "//d:content/@src" -Namespace @{d='http://www.w3.org/2005/Atom'} $xml).Node.value + _WriteDebug "Found $version at $downloadUrl" + @{ Version = $version; DownloadUrl = $downloadUrl } } else { throw "There are no runtimes matching the name $RuntimeId on feed $feed." } @@ -571,20 +590,22 @@ function Get-PackageOS() { $runtimeFullName -replace "$RuntimePackageName-[^-]*-([^-]*)-[^.]*.*", '$1' } -function Download-Package( - $runtimeInfo, - [string]$DestinationFile, - [Parameter(Mandatory=$true)] - [string]$Feed, - [string]$Proxy) { - +function Download-Package() { + param( + $runtimeInfo, + [Parameter(Mandatory=$true)] + [string]$DownloadUrl, + [string]$DestinationFile, + [Parameter(Mandatory=$true)] + [string]$Feed, + [string]$Proxy + ) - $url = "$Feed/package/" + ($runtimeInfo.RuntimeId) + "/" + $runtimeInfo.Version _WriteOut "Downloading $($runtimeInfo.RuntimeName) from $feed" $wc = New-Object System.Net.WebClient try { Apply-Proxy $wc -Proxy:$Proxy - _WriteDebug "Downloading $url ..." + _WriteDebug "Downloading $DownloadUrl ..." Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action { $Global:downloadData = $eventArgs @@ -595,14 +616,14 @@ function Download-Package( $Global:downloadCompleted = $true } | Out-Null - $wc.DownloadFileAsync($url, $DestinationFile) + $wc.DownloadFileAsync($DownloadUrl, $DestinationFile) while(-not $Global:downloadCompleted){ $percent = $Global:downloadData.ProgressPercentage $totalBytes = $Global:downloadData.TotalBytesToReceive $receivedBytes = $Global:downloadData.BytesReceived If ($percent -ne $null) { - Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") ` + Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $DownloadUrl") ` -Status ("Downloaded $($Global:downloadData.BytesReceived) of $($Global:downloadData.TotalBytesToReceive) bytes") ` -PercentComplete $percent -Id 2 -ParentId 1 } @@ -616,7 +637,7 @@ function Download-Package( } } - Write-Progress -Status "Done" -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed + Write-Progress -Status "Done" -Activity ("Downloading $RuntimeShortFriendlyName from $DownloadUrl") -Id 2 -ParentId 1 -Completed } finally { Remove-Variable downloadData -Scope "Global" @@ -1255,14 +1276,22 @@ function dnvm-install { if([String]::IsNullOrEmpty($Architecture)) { $OS = Get-PackageOS $BaseName } + } else { + $Version = $VersionNuPkgOrAlias } } $runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version - if ($VersionNuPkgOrAlias -eq "latest") { - Write-Progress -Activity "Installing runtime" -Status "Determining latest runtime" -Id 1 - $Version = Find-Latest -runtimeInfo:$runtimeInfo -Feed:$selectedFeed + if (!$IsNuPkg) { + if ($VersionNuPkgOrAlias -eq "latest") { + Write-Progress -Activity "Installing runtime" -Status "Determining latest runtime" -Id 1 + $findPackageResult = Find-Latest -runtimeInfo:$runtimeInfo -Feed:$selectedFeed + } + else { + $findPackageResult = Find-Package -runtimeInfo:$runtimeInfo -Feed:$selectedFeed + } + $Version = $findPackageResult.Version } #If the version is still empty at this point then VersionOrNupkgOrAlias is an actual version. @@ -1317,7 +1346,7 @@ function dnvm-install { Write-Progress -Activity "Installing runtime" -Status "Downloading runtime" -Id 1 _WriteDebug "Downloading version $($runtimeInfo.Version) to $DownloadFile" - Download-Package -RuntimeInfo:$runtimeInfo -DestinationFile:$DownloadFile -Proxy:$Proxy -Feed:$selectedFeed + Download-Package -RuntimeInfo:$runtimeInfo -DownloadUrl:$findPackageResult.DownloadUrl -DestinationFile:$DownloadFile -Proxy:$Proxy -Feed:$selectedFeed } Write-Progress -Activity "Installing runtime" -Status "Unpacking runtime" -Id 1 diff --git a/dnvm.sh b/dnvm.sh index bc58ce02f8..c258a194dd 100644 --- a/dnvm.sh +++ b/dnvm.sh @@ -2,7 +2,7 @@ # Source this file from your .bash-profile or script to use # "Constants" -_DNVM_BUILDNUMBER="beta7-10404" +_DNVM_BUILDNUMBER="beta7-10405" _DNVM_AUTHORS="Microsoft Open Technologies, Inc." _DNVM_RUNTIME_PACKAGE_NAME="dnx" _DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment" @@ -94,6 +94,15 @@ __dnvm_runtime_bitness_defaults() fi } +__dnvm_query_feed() { + local url=$1 + xml="$(curl $url 2>/dev/null)" + echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1 + version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')" + downloadUrl="$(echo $xml | sed 's/.** >> /dev/null || return 1 - version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')" + __dnvm_query_feed $url + return $? +} - echo $version +__dnvm_find_package() { + local platform=$1 + local arch=$2 + local os=$3 + local version=$4 + + if [[ $platform == "mono" ]]; then + #dnx-mono + local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform" + else + #dnx-coreclr-linux-x64 + local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch" + fi + + local url="$DNX_ACTIVE_FEED/Packages()?\$filter=Id%20eq%27$packageId%27%20and%20Version%20eq%20%27$version%27" + __dnvm_query_feed $url + return $? } __dnvm_strip_path() { @@ -183,12 +208,12 @@ __dnvm_update_self() { __dnvm_download() { local runtimeFullName="$1" - local runtimeFolder="$2" - local force="$3" + local downloadUrl="$2" + local runtimeFolder="$3" + local force="$4" local pkgName=$(__dnvm_package_name "$runtimeFullName") local pkgVersion=$(__dnvm_package_version "$runtimeFullName") - local url="$DNX_ACTIVE_FEED/package/$pkgName/$pkgVersion" local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg" if [ -n "$force" ]; then @@ -209,9 +234,9 @@ __dnvm_download() { mkdir -p "$runtimeFolder" > /dev/null 2>&1 echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED" - echo "Download: $url" + echo "Download: $downloadUrl" - local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") + local httpResult=$(curl -L -D - "$downloadUrl" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") if [[ $httpResult == "404" ]]; then printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}" @@ -508,14 +533,27 @@ dnvm() printf "%b\n" "${Yel}It appears you don't have Mono available. Remember to get Mono before trying to run $DNVM_RUNTIME_SHORT_NAME application. ${RCol}" >&2; fi - if [[ "$versionOrAlias" == "latest" ]]; then - echo "Determining latest version" - versionOrAlias=$(__dnvm_find_latest "$runtime" "$arch" "$os") - [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1 - printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}" - fi - - if [[ "$versionOrAlias" == *.nupkg ]]; then + if [[ "$versionOrAlias" != *.nupkg ]]; then + if [[ "$versionOrAlias" == "latest" ]]; then + echo "Determining latest version" + read versionOrAlias downloadUrl < <(__dnvm_find_latest "$runtime" "$arch" "$os") + [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1 + printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}" + else + local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os") + local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") + read versionOrAlias downloadUrl < <(__dnvm_find_package "$runtime" "$arch" "$os" "$runtimeVersion") + [[ $? == 1 ]] && echo "Error: Could not find version $runtimeVersion in feed $DNX_ACTIVE_FEED" && return 1 + fi + local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os") + local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName" + __dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$force" + [[ $? == 1 ]] && return 1 + if [[ "$os" == $(__dnvm_current_os) ]]; then + $_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch" + [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias" + fi + else local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/") local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName" @@ -537,15 +575,6 @@ dnvm() fi $_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" -r "$runtimeClr" [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion" - else - local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os") - local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName" - __dnvm_download "$runtimeFullName" "$runtimeFolder" "$force" - [[ $? == 1 ]] && return 1 - if [[ "$os" == $(__dnvm_current_os) ]]; then - $_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch" - [[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias" - fi fi ;;