⬆️ dnvm.ps1, dnvm.cmd, dnvm.sh

Source: AspNet/kvm@1aaa9faa82
This commit is contained in:
ASP.NET Push Bot 2015-07-29 11:19:22 -07:00 committed by unknown
parent 23b0f6a2e4
commit 4f0d14c1d2
2 changed files with 107 additions and 49 deletions

View File

@ -67,7 +67,7 @@ function _WriteOut {
### Constants ### Constants
$ProductVersion="1.0.0" $ProductVersion="1.0.0"
$BuildVersion="beta7-10404" $BuildVersion="beta7-10405"
$Authors="Microsoft Open Technologies, Inc." $Authors="Microsoft Open Technologies, Inc."
# If the Version hasn't been replaced... # 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 { function Find-Latest {
param( param(
$runtimeInfo, $runtimeInfo,
@ -521,23 +531,32 @@ function Find-Latest {
$RuntimeId = $runtimeInfo.RuntimeId $RuntimeId = $runtimeInfo.RuntimeId
_WriteDebug "Latest RuntimeId: $RuntimeId" _WriteDebug "Latest RuntimeId: $RuntimeId"
$url = "$Feed/GetUpdates()?packageIds=%27$RuntimeId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false" $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! # NOTE: DO NOT use Invoke-WebRequest. It requires PowerShell 4.0!
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
Apply-Proxy $wc -Proxy:$Proxy Apply-Proxy $wc -Proxy:$Proxy
_WriteDebug "Downloading $url ..." _WriteDebug "Downloading $Url ..."
try { try {
[xml]$xml = $wc.DownloadString($url) [xml]$xml = $wc.DownloadString($Url)
} catch { } catch {
$Script:ExitCode = $ExitCodes.NoRuntimesOnFeed $Script:ExitCode = $ExitCodes.NoRuntimesOnFeed
throw "Unable to find any runtime packages on the feed!" 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 $version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
if($version) { if($version) {
_WriteDebug "Found latest version: $version" $downloadUrl = (Select-Xml "//d:content/@src" -Namespace @{d='http://www.w3.org/2005/Atom'} $xml).Node.value
$version _WriteDebug "Found $version at $downloadUrl"
@{ Version = $version; DownloadUrl = $downloadUrl }
} else { } else {
throw "There are no runtimes matching the name $RuntimeId on feed $feed." throw "There are no runtimes matching the name $RuntimeId on feed $feed."
} }
@ -571,20 +590,22 @@ function Get-PackageOS() {
$runtimeFullName -replace "$RuntimePackageName-[^-]*-([^-]*)-[^.]*.*", '$1' $runtimeFullName -replace "$RuntimePackageName-[^-]*-([^-]*)-[^.]*.*", '$1'
} }
function Download-Package( function Download-Package() {
$runtimeInfo, param(
[string]$DestinationFile, $runtimeInfo,
[Parameter(Mandatory=$true)] [Parameter(Mandatory=$true)]
[string]$Feed, [string]$DownloadUrl,
[string]$Proxy) { [string]$DestinationFile,
[Parameter(Mandatory=$true)]
[string]$Feed,
[string]$Proxy
)
$url = "$Feed/package/" + ($runtimeInfo.RuntimeId) + "/" + $runtimeInfo.Version
_WriteOut "Downloading $($runtimeInfo.RuntimeName) from $feed" _WriteOut "Downloading $($runtimeInfo.RuntimeName) from $feed"
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
try { try {
Apply-Proxy $wc -Proxy:$Proxy Apply-Proxy $wc -Proxy:$Proxy
_WriteDebug "Downloading $url ..." _WriteDebug "Downloading $DownloadUrl ..."
Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action { Register-ObjectEvent $wc DownloadProgressChanged -SourceIdentifier WebClient.ProgressChanged -action {
$Global:downloadData = $eventArgs $Global:downloadData = $eventArgs
@ -595,14 +616,14 @@ function Download-Package(
$Global:downloadCompleted = $true $Global:downloadCompleted = $true
} | Out-Null } | Out-Null
$wc.DownloadFileAsync($url, $DestinationFile) $wc.DownloadFileAsync($DownloadUrl, $DestinationFile)
while(-not $Global:downloadCompleted){ while(-not $Global:downloadCompleted){
$percent = $Global:downloadData.ProgressPercentage $percent = $Global:downloadData.ProgressPercentage
$totalBytes = $Global:downloadData.TotalBytesToReceive $totalBytes = $Global:downloadData.TotalBytesToReceive
$receivedBytes = $Global:downloadData.BytesReceived $receivedBytes = $Global:downloadData.BytesReceived
If ($percent -ne $null) { 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") ` -Status ("Downloaded $($Global:downloadData.BytesReceived) of $($Global:downloadData.TotalBytesToReceive) bytes") `
-PercentComplete $percent -Id 2 -ParentId 1 -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 { finally {
Remove-Variable downloadData -Scope "Global" Remove-Variable downloadData -Scope "Global"
@ -1255,14 +1276,22 @@ function dnvm-install {
if([String]::IsNullOrEmpty($Architecture)) { if([String]::IsNullOrEmpty($Architecture)) {
$OS = Get-PackageOS $BaseName $OS = Get-PackageOS $BaseName
} }
} else {
$Version = $VersionNuPkgOrAlias
} }
} }
$runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version $runtimeInfo = GetRuntimeInfo $Architecture $Runtime $OS $Version
if ($VersionNuPkgOrAlias -eq "latest") { if (!$IsNuPkg) {
Write-Progress -Activity "Installing runtime" -Status "Determining latest runtime" -Id 1 if ($VersionNuPkgOrAlias -eq "latest") {
$Version = Find-Latest -runtimeInfo:$runtimeInfo -Feed:$selectedFeed 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. #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 Write-Progress -Activity "Installing runtime" -Status "Downloading runtime" -Id 1
_WriteDebug "Downloading version $($runtimeInfo.Version) to $DownloadFile" _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 Write-Progress -Activity "Installing runtime" -Status "Unpacking runtime" -Id 1

83
dnvm.sh
View File

@ -2,7 +2,7 @@
# Source this file from your .bash-profile or script to use # Source this file from your .bash-profile or script to use
# "Constants" # "Constants"
_DNVM_BUILDNUMBER="beta7-10404" _DNVM_BUILDNUMBER="beta7-10405"
_DNVM_AUTHORS="Microsoft Open Technologies, Inc." _DNVM_AUTHORS="Microsoft Open Technologies, Inc."
_DNVM_RUNTIME_PACKAGE_NAME="dnx" _DNVM_RUNTIME_PACKAGE_NAME="dnx"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment" _DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@ -94,6 +94,15 @@ __dnvm_runtime_bitness_defaults()
fi 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/.*<content.*src="\([^"]*\).*/\1/')"
echo $version $downloadUrl
}
__dnvm_find_latest() { __dnvm_find_latest() {
local platform=$1 local platform=$1
local arch=$2 local arch=$2
@ -113,11 +122,27 @@ __dnvm_find_latest() {
fi fi
local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$packageId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false" local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$packageId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
xml="$(curl $url 2>/dev/null)" __dnvm_query_feed $url
echo $xml | grep \<[a-zA-Z]:Version\>* >> /dev/null || return 1 return $?
version="$(echo $xml | sed 's/.*<[a-zA-Z]:Version>\([^<]*\).*/\1/')" }
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() { __dnvm_strip_path() {
@ -183,12 +208,12 @@ __dnvm_update_self() {
__dnvm_download() { __dnvm_download() {
local runtimeFullName="$1" local runtimeFullName="$1"
local runtimeFolder="$2" local downloadUrl="$2"
local force="$3" local runtimeFolder="$3"
local force="$4"
local pkgName=$(__dnvm_package_name "$runtimeFullName") local pkgName=$(__dnvm_package_name "$runtimeFullName")
local pkgVersion=$(__dnvm_package_version "$runtimeFullName") local pkgVersion=$(__dnvm_package_version "$runtimeFullName")
local url="$DNX_ACTIVE_FEED/package/$pkgName/$pkgVersion"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg" local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -n "$force" ]; then if [ -n "$force" ]; then
@ -209,9 +234,9 @@ __dnvm_download() {
mkdir -p "$runtimeFolder" > /dev/null 2>&1 mkdir -p "$runtimeFolder" > /dev/null 2>&1
echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED" 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 if [[ $httpResult == "404" ]]; then
printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}" 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; 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 fi
if [[ "$versionOrAlias" == "latest" ]]; then if [[ "$versionOrAlias" != *.nupkg ]]; then
echo "Determining latest version" if [[ "$versionOrAlias" == "latest" ]]; then
versionOrAlias=$(__dnvm_find_latest "$runtime" "$arch" "$os") echo "Determining latest version"
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1 read versionOrAlias downloadUrl < <(__dnvm_find_latest "$runtime" "$arch" "$os")
printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}" [[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1
fi printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}"
else
if [[ "$versionOrAlias" == *.nupkg ]]; then 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 runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName") local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName" local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName"
@ -537,15 +575,6 @@ dnvm()
fi fi
$_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" -r "$runtimeClr" $_DNVM_COMMAND_NAME use "$runtimeVersion" "$persistent" -r "$runtimeClr"
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$runtimeVersion" [[ -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 fi
;; ;;