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

Source: AspNet/kvm@9c54d02bea
This commit is contained in:
ASP.NET Push Bot 2015-04-20 14:12:43 -07:00 committed by unknown
parent 578f5428ba
commit e9dbf24790
2 changed files with 140 additions and 37 deletions

View File

@ -67,7 +67,7 @@ function _WriteOut {
### Constants
$ProductVersion="1.0.0"
$BuildVersion="beta5-10365"
$BuildVersion="beta5-10367"
$Authors="Microsoft Open Technologies, Inc."
# If the Version hasn't been replaced...
@ -84,7 +84,8 @@ Set-Variable -Option Constant "CommandFriendlyName" ".NET Version Manager"
Set-Variable -Option Constant "DefaultUserDirectoryName" ".dnx"
Set-Variable -Option Constant "OldUserDirectoryNames" @(".kre", ".k")
Set-Variable -Option Constant "RuntimePackageName" "dnx"
Set-Variable -Option Constant "DefaultFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
Set-Variable -Option Constant "DefaultFeed" "https://www.nuget.org/api/v2"
Set-Variable -Option Constant "DefaultUnstableFeed" "https://www.myget.org/F/aspnetvnext/api/v2"
Set-Variable -Option Constant "CrossGenCommand" "k-crossgen"
Set-Variable -Option Constant "CommandPrefix" "dnvm-"
Set-Variable -Option Constant "DefaultArchitecture" "x86"
@ -128,6 +129,8 @@ if(!$ColorScheme) {
"Help_Optional"=[ConsoleColor]::Gray
"Help_Command"=[ConsoleColor]::DarkYellow
"Help_Executable"=[ConsoleColor]::DarkYellow
"Feed_Name"=[ConsoleColor]::Cyan
"Warning" = [ConsoleColor]::Yellow
}
}
@ -147,6 +150,7 @@ $DeprecatedCommands = @("unalias")
$RuntimeHomes = $env:DNX_HOME
$UserHome = $env:DNX_USER_HOME
$ActiveFeed = $env:DNX_FEED
$ActiveUnstableFeed = $env:DNX_UNSTABLE_FEED
# Default Exit Code
$Script:ExitCode = $ExitCodes.Success
@ -169,10 +173,6 @@ if($CmdPathFile) {
_WriteDebug "Using CMD PATH file: $CmdPathFile"
}
if(!$ActiveFeed) {
$ActiveFeed = $DefaultFeed
}
# Determine where runtimes can exist (RuntimeHomes)
if(!$RuntimeHomes) {
# Set up a default value for the runtime home
@ -275,13 +275,34 @@ function Write-Usage {
if(!$Authors.StartsWith("{{")) {
_WriteOut "By $Authors"
}
_WriteOut
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Header "usage:"
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Executable " $CommandName"
_WriteOut -NoNewLine -ForegroundColor $ColorScheme.Help_Command " <command>"
_WriteOut -ForegroundColor $ColorScheme.Help_Argument " [<arguments...>]"
}
function Write-Feeds {
_WriteOut
_WriteOut -ForegroundColor $ColorScheme.Help_Header "Current feed settings:"
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Default Stable: "
_WriteOut "$DefaultFeed"
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Default Unstable: "
_WriteOut "$DefaultUnstableFeed"
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Current Stable Override: "
if($ActiveFeed) {
_WriteOut "$ActiveFeed"
} else {
_WriteOut "<none>"
}
_WriteOut -NoNewline -ForegroundColor $ColorScheme.Feed_Name "Current Unstable Override: "
if($ActiveUnstableFeed) {
_WriteOut "$ActiveUnstableFeed"
} else {
_WriteOut "<none>"
}
}
function Get-RuntimeAlias {
if($Aliases -eq $null) {
_WriteDebug "Scanning for aliases in $AliasesDir"
@ -440,16 +461,15 @@ function Find-Latest {
param(
[string]$runtime = "",
[string]$architecture = "",
[Parameter(Mandatory=$true)]
[string]$Feed,
[string]$Proxy
)
if(!$Feed) { $Feed = $ActiveFeed }
_WriteOut "Determining latest version"
$RuntimeId = Get-RuntimeId -Architecture:"$architecture" -Runtime:"$runtime"
$url = "$Feed/GetUpdates()?packageIds=%27$RuntimeId%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
# NOTE: DO NOT use Invoke-WebRequest. It requires PowerShell 4.0!
$wc = New-Object System.Net.WebClient
@ -464,9 +484,11 @@ function Find-Latest {
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
if (![String]::IsNullOrWhiteSpace($version)) {
if($version) {
_WriteDebug "Found latest version: $version"
$version
} else {
throw "There are no runtimes matching the name $RuntimeId on feed $feed."
}
}
@ -496,11 +518,10 @@ function Download-Package(
[string]$Architecture,
[string]$Runtime,
[string]$DestinationFile,
[Parameter(Mandatory=$true)]
[string]$Feed,
[string]$Proxy) {
if(!$Feed) { $Feed = $ActiveFeed }
$url = "$Feed/package/" + (Get-RuntimeId $Architecture $Runtime) + "/" + $Version
_WriteOut "Downloading $runtimeFullName from $feed"
@ -531,8 +552,12 @@ function Download-Package(
}
}
if($Global:downloadData.Error){
throw "Unable to download package: {0}" -f $Global:downloadData.Error.Message
if($Global:downloadData.Error) {
if($Global:downloadData.Error.Response.StatusCode -eq [System.Net.HttpStatusCode]::NotFound){
throw "The server returned a 404 (NotFound). This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $RuntimeShortFriendlyName of the right name format or some other error caused a 404 on the server."
} else {
throw "Unable to download package: {0}" -f $Global:downloadData.Error.Message
}
}
Write-Progress -Activity ("Downloading $RuntimeShortFriendlyName from $url") -Id 2 -ParentId 1 -Completed
@ -803,6 +828,7 @@ function dnvm-help {
}
} else {
Write-Usage
Write-Feeds
_WriteOut
_WriteOut -ForegroundColor $ColorScheme.Help_Header "commands: "
Get-Command "$CommandPrefix*" |
@ -928,6 +954,8 @@ function dnvm-unalias {
Skip generation of native images
.PARAMETER Ngen
For CLR flavor only. Generate native images for runtime libraries on Desktop CLR to improve startup time. This option requires elevated privilege and will be automatically turned on if the script is running in administrative mode. To opt-out in administrative mode, use -NoNative switch.
.PARAMETER Unstable
Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.
#>
function dnvm-upgrade {
param(
@ -956,9 +984,12 @@ function dnvm-upgrade {
[switch]$NoNative,
[Parameter(Mandatory=$false)]
[switch]$Ngen)
[switch]$Ngen,
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Persistent:$true
[Parameter(Mandatory=$false)]
[switch]$Unstable)
dnvm-install "latest" -Alias:$Alias -Architecture:$Architecture -Runtime:$Runtime -Force:$Force -Proxy:$Proxy -NoNative:$NoNative -Ngen:$Ngen -Unstable:$Unstable -Persistent:$true
}
<#
@ -984,9 +1015,10 @@ function dnvm-upgrade {
For CLR flavor only. Generate native images for runtime libraries on Desktop CLR to improve startup time. This option requires elevated privilege and will be automatically turned on if the script is running in administrative mode. To opt-out in administrative mode, use -NoNative switch.
.PARAMETER Persistent
Make the installed runtime useable across all processes run by the current user
.PARAMETER Unstable
Upgrade from our unstable dev feed. This will give you the latest development version of the runtime.
.DESCRIPTION
A proxy can also be specified by using the 'http_proxy' environment variable
#>
function dnvm-install {
param(
@ -1021,7 +1053,28 @@ function dnvm-install {
[switch]$Ngen,
[Parameter(Mandatory=$false)]
[switch]$Persistent)
[switch]$Persistent,
[Parameter(Mandatory=$false)]
[switch]$Unstable)
$selectedFeed = ""
if($Unstable) {
$selectedFeed = $ActiveUnstableFeed
if(!$selectedFeed) {
$selectedFeed = $DefaultUnstableFeed
} else {
_WriteOut -ForegroundColor $ColorScheme.Warning "Default unstable feed ($DefaultUnstableFeed) is being overridden by the value of the DNX_UNSTABLE_FEED environment variable ($ActiveUnstableFeed)"
}
} else {
$selectedFeed = $ActiveFeed
if(!$selectedFeed) {
$selectedFeed = $DefaultFeed
} else {
_WriteOut -ForegroundColor $ColorScheme.Warning "Default stable feed ($DefaultFeed) is being overridden by the value of the DNX_FEED environment variable ($ActiveFeed)"
}
}
if(!$VersionNuPkgOrAlias) {
_WriteOut "A version, nupkg path, or the string 'latest' must be provided."
@ -1032,7 +1085,7 @@ function dnvm-install {
if ($VersionNuPkgOrAlias -eq "latest") {
Write-Progress -Activity "Installing runtime" "Determining latest runtime" -Id 1
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture
$VersionNuPkgOrAlias = Find-Latest $Runtime $Architecture -Feed:$selectedFeed
}
$IsNuPkg = $VersionNuPkgOrAlias.EndsWith(".nupkg")
@ -1088,7 +1141,8 @@ function dnvm-install {
# Download the package
Write-Progress -Activity "Installing runtime" "Downloading runtime" -Id 1
_WriteDebug "Downloading version $VersionNuPkgOrAlias to $DownloadFile"
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy
Download-Package $PackageVersion $Architecture $Runtime $DownloadFile -Proxy:$Proxy -Feed:$selectedFeed
}
Write-Progress -Activity "Installing runtime" "Unpacking runtime" -Id 1
@ -1382,7 +1436,7 @@ try {
$Script:ExitCode = $ExitCodes.UnknownCommand
}
} catch {
Write-Error $_
throw
if(!$Script:ExitCode) { $Script:ExitCode = $ExitCodes.OtherError }
}

81
dnvm.sh
View File

@ -2,7 +2,7 @@
# Source this file from your .bash-profile or script to use
# "Constants"
_DNVM_BUILDNUMBER="beta5-10365"
_DNVM_BUILDNUMBER="beta5-10367"
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@ -11,7 +11,8 @@ _DNVM_RUNTIME_FOLDER_NAME=".dnx"
_DNVM_COMMAND_NAME="dnvm"
_DNVM_PACKAGE_MANAGER_NAME="dnu"
_DNVM_VERSION_MANAGER_NAME=".NET Version Manager"
_DNVM_DEFAULT_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
_DNVM_DEFAULT_FEED="https://nuget.org/api/v2"
_DNVM_DEFAULT_UNSTABLE_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
_DNVM_UPDATE_LOCATION="https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh"
_DNVM_HOME_VAR_NAME="DNX_HOME"
@ -50,9 +51,7 @@ _DNVM_USER_PACKAGES="$DNX_USER_HOME/runtimes"
_DNVM_ALIAS_DIR="$DNX_USER_HOME/alias"
_DNVM_DNVM_DIR="$DNX_USER_HOME/dnvm"
if [ -z "$DNX_FEED" ]; then
DNX_FEED="$_DNVM_DEFAULT_FEED"
fi
DNX_ACTIVE_FEED=""
__dnvm_current_os()
{
@ -72,7 +71,7 @@ __dnvm_find_latest() {
return 1
fi
local url="$DNX_FEED/GetUpdates()?packageIds=%27$_DNVM_RUNTIME_PACKAGE_NAME-$platform%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$_DNVM_RUNTIME_PACKAGE_NAME-$platform%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
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/')"
@ -138,7 +137,7 @@ __dnvm_download() {
local pkgName=$(__dnvm_package_name "$runtimeFullName")
local pkgVersion=$(__dnvm_package_version "$runtimeFullName")
local url="$DNX_FEED/package/$pkgName/$pkgVersion"
local url="$DNX_ACTIVE_FEED/package/$pkgName/$pkgVersion"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -n "$force" ]; then
@ -158,13 +157,17 @@ __dnvm_download() {
mkdir -p "$runtimeFolder" > /dev/null 2>&1
echo "Downloading $runtimeFullName from $DNX_FEED"
echo "Downloading $runtimeFullName from $DNX_ACTIVE_FEED"
echo "Download: $url"
local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
[[ $httpResult == "404" ]] &&printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_FEED ${RCol}" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_FEED ${RCol}" && return 1
if [[ $httpResult == "404" ]]; then
printf "%b\n" "${Red}$runtimeFullName was not found in repository $DNX_ACTIVE_FEED ${RCol}"
printf "%b\n" "${Cya}This is most likely caused by the feed not having the version that you typed. Check that you typed the right version and try again. Other possible causes are the feed doesn't have a $DNVM_RUNTIME_SHORT_NAME of the right name format or some other error caused a 404 on the server.${RCol}"
return 1
fi
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_ACTIVE_FEED ${RCol}" && return 1
__dnvm_unpack $runtimeFile $runtimeFolder
return $?
@ -246,27 +249,51 @@ __echo_art() {
printf "%b" "${RCol}"
}
__dnvm_help() {
__dnvm_description() {
__echo_art
echo ""
echo "$_DNVM_VERSION_MANAGER_NAME - Version 1.0.0-$_DNVM_BUILDNUMBER"
[[ "$_DNVM_AUTHORS" != {{* ]] && echo "By $_DNVM_AUTHORS"
echo ""
printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME <command> [options] ${RCol} \n"
echo "DNVM can be used to download versions of the $_DNVM_RUNTIME_FRIENDLY_NAME and manage which version you are using."
echo "You can control the URL of the stable and unstable channel by setting the DNX_FEED and DNX_UNSTABLE_FEED variables."
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] ${RCol}"
printf "%b\n" "${Yel}Current feed settings:${RCol}"
printf "%b\n" "${Cya}Default Stable:${Yel} $_DNVM_DEFAULT_FEED"
printf "%b\n" "${Cya}Default Unstable:${Yel} $_DNVM_DEFAULT_UNSTABLE_FEED"
local dnxStableOverride="<none>"
[[ -n $DNX_FEED ]] && dnxStableOverride="$DNX_FEED"
printf "%b\n" "${Cya}Current Stable Override:${Yel} $dnxStableOverride"
local dnxUnstableOverride="<none>"
[[ -n $DNX_UNSTABLE_FEED ]] && dnxUnstableOverride="$DNX_UNSTABLE_FEED"
printf "%b\n" "${Cya}Current Unstable Override:${Yel} $dnxUnstableOverride${RCol}"
echo ""
}
__dnvm_help() {
UNSTABLE___dnvm_description
printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME <command> [options] ${RCol}"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] [-u|-unstable] ${RCol}"
echo " install latest $_DNVM_RUNTIME_SHORT_NAME from feed"
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo " set installed version as default"
echo " -f|forces force upgrade. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed"
echo " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable unstable feed"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p|-persistent] [-f|-force] ${RCol}"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p|-persistent] [-f|-force] [-u|-unstable] ${RCol}"
echo " <semver>|<alias> install requested $_DNVM_RUNTIME_SHORT_NAME from feed"
echo " <nupkg> install requested $_DNVM_RUNTIME_SHORT_NAME from local package on filesystem"
echo " latest install latest version of $_DNVM_RUNTIME_SHORT_NAME from feed"
echo " -a|-alias <alias> set alias <alias> for requested $_DNVM_RUNTIME_SHORT_NAME on install"
echo " -p|-persistent set installed version as default"
echo " -f|force force install. Overwrite existing version of $_DNVM_RUNTIME_SHORT_NAME if already installed"
echo " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable unstable feed"
echo ""
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo ""
@ -317,7 +344,10 @@ __dnvm_help() {
dnvm()
{
if [ $# -lt 1 ]; then
__dnvm_help
__dnvm_description
printf "%b\n" "Use ${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol} to display help text."
echo ""
return
fi
@ -342,6 +372,7 @@ dnvm()
local versionOrAlias=
local alias=
local force=
local unstable=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
@ -351,6 +382,8 @@ dnvm()
shift
elif [[ $1 == "-f" || $1 == "-force" ]]; then
local force="-f"
elif [[ $1 == "-u" || $1 == "-unstable" ]]; then
local unstable="-u"
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1
local versionOrAlias=$1
@ -358,6 +391,22 @@ dnvm()
shift
done
if [ -z $unstable ]; then
DNX_ACTIVE_FEED="$DNX_FEED"
if [ -z "$DNX_ACTIVE_FEED" ]; then
DNX_ACTIVE_FEED="$_DNVM_DEFAULT_FEED"
else
printf "%b\n" "${Yel}Default stable feed ($_DNVM_DEFAULT_FEED) is being overridden by the value of the DNX_FEED variable ($DNX_FEED). ${RCol}"
fi
else
DNX_ACTIVE_FEED="$DNX_UNSTABLE_FEED"
if [ -z "$DNX_ACTIVE_FEED" ]; then
DNX_ACTIVE_FEED="$_DNVM_DEFAULT_UNSTABLE_FEED"
else
printf "%b\n" "${Yel}Default unstable feed ($_DNVM_DEFAULT_UNSTABLE_FEED) is being overridden by the value of the DNX_UNSTABLE_FEED variable ($DNX_UNSTABLE_FEED). ${RCol}"
fi
fi
if ! __dnvm_has "mono"; then
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
@ -365,7 +414,7 @@ dnvm()
if [[ "$versionOrAlias" == "latest" ]]; then
echo "Determining latest version"
versionOrAlias=$(__dnvm_find_latest)
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_FEED" && return 1
[[ $? == 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