Skip to content

Commit 4f0d14c

Browse files
ASP.NET Push Botunknown
authored andcommitted
⬆️ dnvm.ps1, dnvm.cmd, dnvm.sh
Source: aspnet/dnvm@1aaa9fa
1 parent 23b0f6a commit 4f0d14c

File tree

2 files changed

+107
-49
lines changed

2 files changed

+107
-49
lines changed

dnvm.ps1

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function _WriteOut {
6767

6868
### Constants
6969
$ProductVersion="1.0.0"
70-
$BuildVersion="beta7-10404"
70+
$BuildVersion="beta7-10405"
7171
$Authors="Microsoft Open Technologies, Inc."
7272

7373
# If the Version hasn't been replaced...
@@ -509,6 +509,16 @@ param(
509509
}
510510
}
511511

512+
function Find-Package {
513+
param(
514+
$runtimeInfo,
515+
[string]$Feed,
516+
[string]$Proxy
517+
)
518+
$url = "$Feed/Packages()?`$filter=Id eq '$($runtimeInfo.RuntimeId)' and Version eq '$($runtimeInfo.Version)'"
519+
Invoke-NuGetWebRequest $runtimeInfo.RuntimeId $url $Proxy
520+
}
521+
512522
function Find-Latest {
513523
param(
514524
$runtimeInfo,
@@ -521,23 +531,32 @@ function Find-Latest {
521531
$RuntimeId = $runtimeInfo.RuntimeId
522532
_WriteDebug "Latest RuntimeId: $RuntimeId"
523533
$url = "$Feed/GetUpdates()?packageIds=%27$RuntimeId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
534+
Invoke-NuGetWebRequest $RuntimeId $url $Proxy
535+
}
536+
537+
function Invoke-NuGetWebRequest {
538+
param (
539+
[string]$RuntimeId,
540+
[string]$Url,
541+
[string]$Proxy
542+
)
524543
# NOTE: DO NOT use Invoke-WebRequest. It requires PowerShell 4.0!
525544

526545
$wc = New-Object System.Net.WebClient
527546
Apply-Proxy $wc -Proxy:$Proxy
528-
_WriteDebug "Downloading $url ..."
547+
_WriteDebug "Downloading $Url ..."
529548
try {
530-
[xml]$xml = $wc.DownloadString($url)
549+
[xml]$xml = $wc.DownloadString($Url)
531550
} catch {
532551
$Script:ExitCode = $ExitCodes.NoRuntimesOnFeed
533552
throw "Unable to find any runtime packages on the feed!"
534553
}
535554

536555
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
537-
538556
if($version) {
539-
_WriteDebug "Found latest version: $version"
540-
$version
557+
$downloadUrl = (Select-Xml "//d:content/@src" -Namespace @{d='http://www.w3.org/2005/Atom'} $xml).Node.value
558+
_WriteDebug "Found $version at $downloadUrl"
559+
@{ Version = $version; DownloadUrl = $downloadUrl }
541560
} else {
542561
throw "There are no runtimes matching the name $RuntimeId on feed $feed."
543562
}
@@ -571,20 +590,22 @@ function Get-PackageOS() {
571590
$runtimeFullName -replace "$RuntimePackageName-[^-]*-([^-]*)-[^.]*.*", '$1'
572591
}
573592

574-
function Download-Package(
575-
$runtimeInfo,
576-
[string]$DestinationFile,
577-
[Parameter(Mandatory=$true)]
578-
[string]$Feed,
579-
[string]$Proxy) {
580-
593+
function Download-Package() {
594+
param(
595+
$runtimeInfo,
596+
[Parameter(Mandatory=$true)]
597+
[string]$DownloadUrl,
598+
[string]$DestinationFile,
599+
[Parameter(Mandatory=$true)]
600+
[string]$Feed,
601+
[string]$Proxy
602+
)
581603

582-
$url = "$Feed/package/" + ($runtimeInfo.RuntimeId) + "/" + $runtimeInfo.Version
583604
_WriteOut "Downloading $($runtimeInfo.RuntimeName) from $feed"
584605
$wc = New-Object System.Net.WebClient
585606
try {
586607
Apply-Proxy $wc -Proxy:$Proxy
587-
_WriteDebug "Downloading $url ..."
608+
_WriteDebug "Downloading $DownloadUrl ..."
588609

589610
Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action {
590611
$Global:downloadData = $eventArgs
@@ -595,14 +616,14 @@ function Download-Package(
595616
$Global:downloadCompleted = $true
596617
} | Out-Null
597618

598-
$wc.DownloadFileAsync($url, $DestinationFile)
619+
$wc.DownloadFileAsync($DownloadUrl, $DestinationFile)
599620

600621
while(-not $Global:downloadCompleted){
601622
$percent = $Global:downloadData.ProgressPercentage
602623
$totalBytes = $Global:downloadData.TotalBytesToReceive
603624
$receivedBytes = $Global:downloadData.BytesReceived
604625
If ($percent -ne $null) {
605-
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") `
626+
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $DownloadUrl") `
606627
-Status ("Downloaded $($Global:downloadData.BytesReceived) of $($Global:downloadData.TotalBytesToReceive) bytes") `
607628
-PercentComplete $percent -Id 2 -ParentId 1
608629
}
@@ -616,7 +637,7 @@ function Download-Package(
616637
}
617638
}
618639

619-
Write-Progress -Status "Done" -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
640+
Write-Progress -Status "Done" -Activity ("Downloading $RuntimeShortFriendlyName from $DownloadUrl") -Id 2 -ParentId 1 -Completed
620641
}
621642
finally {
622643
Remove-Variable downloadData -Scope "Global"
@@ -1255,14 +1276,22 @@ function dnvm-install {
12551276
if([String]::IsNullOrEmpty($Architecture)) {
12561277
$OS = Get-PackageOS $BaseName
12571278
}
1279+
} else {
1280+
$Version = $VersionNuPkgOrAlias
12581281
}
12591282
}
12601283

12611284
$runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version
12621285

1263-
if ($VersionNuPkgOrAlias -eq "latest") {
1264-
Write-Progress -Activity "Installing runtime" -Status "Determining latest runtime" -Id 1
1265-
$Version = Find-Latest -runtimeInfo:$runtimeInfo -Feed:$selectedFeed
1286+
if (!$IsNuPkg) {
1287+
if ($VersionNuPkgOrAlias -eq "latest") {
1288+
Write-Progress -Activity "Installing runtime" -Status "Determining latest runtime" -Id 1
1289+
$findPackageResult = Find-Latest -runtimeInfo:$runtimeInfo -Feed:$selectedFeed
1290+
}
1291+
else {
1292+
$findPackageResult = Find-Package -runtimeInfo:$runtimeInfo -Feed:$selectedFeed
1293+
}
1294+
$Version = $findPackageResult.Version
12661295
}
12671296

12681297
#If the version is still empty at this point then VersionOrNupkgOrAlias is an actual version.
@@ -1317,7 +1346,7 @@ function dnvm-install {
13171346
Write-Progress -Activity "Installing runtime" -Status "Downloading runtime" -Id 1
13181347
_WriteDebug "Downloading version $($runtimeInfo.Version) to $DownloadFile"
13191348

1320-
Download-Package -RuntimeInfo:$runtimeInfo -DestinationFile:$DownloadFile -Proxy:$Proxy -Feed:$selectedFeed
1349+
Download-Package -RuntimeInfo:$runtimeInfo -DownloadUrl:$findPackageResult.DownloadUrl -DestinationFile:$DownloadFile -Proxy:$Proxy -Feed:$selectedFeed
13211350
}
13221351

13231352
Write-Progress -Activity "Installing runtime" -Status "Unpacking runtime" -Id 1

dnvm.sh

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Source this file from your .bash-profile or script to use
33

44
# "Constants"
5-
_DNVM_BUILDNUMBER="beta7-10404"
5+
_DNVM_BUILDNUMBER="beta7-10405"
66
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
77
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
88
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@@ -94,6 +94,15 @@ __dnvm_runtime_bitness_defaults()
9494
fi
9595
}
9696

97+
__dnvm_query_feed() {
98+
local url=$1
99+
xml="$(curl $url 2>/dev/null)"
100+
echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1
101+
version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')"
102+
downloadUrl="$(echo $xml | sed 's/.*<content.*src="\([^"]*\).*/\1/')"
103+
echo $version $downloadUrl
104+
}
105+
97106
__dnvm_find_latest() {
98107
local platform=$1
99108
local arch=$2
@@ -113,11 +122,27 @@ __dnvm_find_latest() {
113122
fi
114123

115124
local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$packageId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
116-
xml="$(curl $url 2>/dev/null)"
117-
echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1
118-
version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')"
125+
__dnvm_query_feed $url
126+
return $?
127+
}
128+
129+
__dnvm_find_package() {
130+
local platform=$1
131+
local arch=$2
132+
local os=$3
133+
local version=$4
134+
135+
if [[ $platform == "mono" ]]; then
136+
#dnx-mono
137+
local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform"
138+
else
139+
#dnx-coreclr-linux-x64
140+
local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch"
141+
fi
119142

120-
echo $version
143+
local url="$DNX_ACTIVE_FEED/Packages()?\$filter=Id%20eq%27$packageId%27%20and%20Version%20eq%20%27$version%27"
144+
__dnvm_query_feed $url
145+
return $?
121146
}
122147

123148
__dnvm_strip_path() {
@@ -183,12 +208,12 @@ __dnvm_update_self() {
183208

184209
__dnvm_download() {
185210
local runtimeFullName="$1"
186-
local runtimeFolder="$2"
187-
local force="$3"
211+
local downloadUrl="$2"
212+
local runtimeFolder="$3"
213+
local force="$4"
188214

189215
local pkgName=$(__dnvm_package_name "$runtimeFullName")
190216
local pkgVersion=$(__dnvm_package_version "$runtimeFullName")
191-
local url="$DNX_ACTIVE_FEED/package/$pkgName/$pkgVersion"
192217
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
193218

194219
if [ -n "$force" ]; then
@@ -209,9 +234,9 @@ __dnvm_download() {
209234
mkdir -p "$runtimeFolder" > /dev/null 2>&1
210235

211236
echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED"
212-
echo "Download: $url"
237+
echo "Download: $downloadUrl"
213238

214-
local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
239+
local httpResult=$(curl -L -D - "$downloadUrl" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
215240

216241
if [[ $httpResult == "404" ]]; then
217242
printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}"
@@ -508,14 +533,27 @@ dnvm()
508533
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;
509534
fi
510535

511-
if [[ "$versionOrAlias" == "latest" ]]; then
512-
echo "Determining latest version"
513-
versionOrAlias=$(__dnvm_find_latest "$runtime" "$arch" "$os")
514-
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1
515-
printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}"
516-
fi
517-
518-
if [[ "$versionOrAlias" == *.nupkg ]]; then
536+
if [[ "$versionOrAlias" != *.nupkg ]]; then
537+
if [[ "$versionOrAlias" == "latest" ]]; then
538+
echo "Determining latest version"
539+
read versionOrAlias downloadUrl < <(__dnvm_find_latest "$runtime" "$arch" "$os")
540+
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1
541+
printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}"
542+
else
543+
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os")
544+
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
545+
read versionOrAlias downloadUrl < <(__dnvm_find_package "$runtime" "$arch" "$os" "$runtimeVersion")
546+
[[ $? == 1 ]] && echo "Error: Could not find version $runtimeVersion in feed $DNX_ACTIVE_FEED" && return 1
547+
fi
548+
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os")
549+
local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName"
550+
__dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$force"
551+
[[ $? == 1 ]] && return 1
552+
if [[ "$os" == $(__dnvm_current_os) ]]; then
553+
$_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch"
554+
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias"
555+
fi
556+
else
519557
local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
520558
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
521559
local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName"
@@ -537,15 +575,6 @@ dnvm()
537575
fi
538576
$_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" -r "$runtimeClr"
539577
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion"
540-
else
541-
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os")
542-
local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName"
543-
__dnvm_download "$runtimeFullName" "$runtimeFolder" "$force"
544-
[[ $? == 1 ]] && return 1
545-
if [[ "$os" == $(__dnvm_current_os) ]]; then
546-
$_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch"
547-
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias"
548-
fi
549578
fi
550579
;;
551580

0 commit comments

Comments
 (0)