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

Source: AspNet/kvm@99d0fa33c8
This commit is contained in:
ASP.NET Push Bot 2015-04-03 14:30:29 -07:00 committed by unknown
parent 925aa16a3b
commit e652ec7fbf
2 changed files with 139 additions and 46 deletions

View File

@ -66,7 +66,7 @@ function _WriteOut {
### Constants
$ProductVersion="1.0.0"
$BuildVersion="beta5-10357"
$BuildVersion="beta5-10358"
$Authors="Microsoft Open Technologies, Inc."
# If the Version hasn't been replaced...
@ -97,6 +97,8 @@ Set-Variable -Option Constant "HomeEnvVar" "DNX_HOME"
Set-Variable -Option Constant "RuntimeShortFriendlyName" "DNX"
Set-Variable -Option Constant "DNVMUpgradeUrl" "https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.ps1"
Set-Variable -Option Constant "AsciiArt" @"
___ _ ___ ____ ___
/ _ \/ |/ / | / / |/ /
@ -651,6 +653,24 @@ function Is-Elevated() {
### Commands
<#
.SYNOPSIS
Updates DNVM to the latest version.
.PARAMETER Proxy
Use the given address as a proxy when accessing remote server
#>
function dnvm-update-self {
param(
[Parameter(Mandatory=$false)]
[string]$Proxy)
_WriteOut "Updating $CommandName from $DNVMUpgradeUrl"
$wc = New-Object System.Net.WebClient
Apply-Proxy $wc -Proxy:$Proxy
$dnvmFile = Join-Path $PSScriptRoot "dnvm.ps1"
$wc.DownloadFile($DNVMUpgradeUrl, $dnvmFile)
}
<#
.SYNOPSIS
Displays a list of commands, and help for specific commands

163
dnvm.sh
View File

@ -2,7 +2,7 @@
# Source this file from your .bash-profile or script to use
# "Constants"
_DNVM_BUILDNUMBER="beta5-10357"
_DNVM_BUILDNUMBER="beta5-10358"
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
@ -11,9 +11,26 @@ _DNVM_RUNTIME_FOLDER_NAME=".dnx"
_DNVM_COMMAND_NAME="dnvm"
_DNVM_VERSION_MANAGER_NAME=".NET Version Manager"
_DNVM_DEFAULT_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"
[ "$_DNVM_BUILDNUMBER" = "{{*" ] && _DNVM_BUILDNUMBER="HEAD"
if [ "$NO_COLOR" != "1" ]; then
# ANSI Colors
RCol='\e[0m' # Text Reset
# Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds
Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m';
Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m';
Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m';
Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m';
Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m';
Pur='\e[0;35m'; BPur='\e[1;35m'; UPur='\e[4;35m'; IPur='\e[0;95m'; BIPur='\e[1;95m'; On_Pur='\e[45m'; On_IPur='\e[0;105m';
Cya='\e[0;36m'; BCya='\e[1;36m'; UCya='\e[4;36m'; ICya='\e[0;96m'; BICya='\e[1;96m'; On_Cya='\e[46m'; On_ICya='\e[0;106m';
Whi='\e[0;37m'; BWhi='\e[1;37m'; UWhi='\e[4;37m'; IWhi='\e[0;97m'; BIWhi='\e[1;97m'; On_Whi='\e[47m'; On_IWhi='\e[0;107m';
fi
[[ "$_DNVM_BUILDNUMBER" = {{* ]] && _DNVM_BUILDNUMBER="HEAD"
__dnvm_has() {
type "$1" > /dev/null 2>&1
@ -30,6 +47,7 @@ fi
_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"
@ -39,7 +57,7 @@ __dnvm_find_latest() {
local platform="mono"
if ! __dnvm_has "curl"; then
echo "$_DNVM_COMMAND_NAME needs curl to proceed." >&2;
printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2;
return 1
fi
@ -77,33 +95,57 @@ __dnvm_package_runtime() {
echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-\([^.-]*\).*/\1/"
}
__dnvm_update_self() {
local dnvmFileLocation="$_DNVM_DNVM_DIR/dnvm.sh"
if [ ! -e $dnvmFileLocation ]; then
local formattedDnvmFileLocation=`(echo $dnvmFileLocation | sed s=$HOME=~=g)`
local formattedDnvmHome=`(echo $_DNVM_DNVM_DIR | sed s=$HOME=~=g)`
printf "%b\n" "${Red}$formattedDnvmFileLocation doesn't exist. This command assumes you have installed dnvm in the usual location and are trying to update it. If you want to use update-self then dnvm.sh should be sourced from $formattedDnvmHome ${RCol}"
return 1
fi
printf "%b\n" "${Cya}Downloading dnvm.sh from $_DNVM_UPDATE_LOCATION ${RCol}"
local httpResult=$(curl -L -D - "$_DNVM_UPDATE_LOCATION" -o "$dnvmFileLocation" -# | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
[[ $httpResult == "404" ]] &&printf "%b\n" "${Red}404. Unable to download DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching DNVM from $_DNVM_UPDATE_LOCATION ${RCol}" && return 1
source "$dnvmFileLocation"
}
__dnvm_download() {
local runtimeFullName="$1"
local runtimeFolder="$2"
local force="$3"
local pkgName=$(__dnvm_package_name "$runtimeFullName")
local pkgVersion=$(__dnvm_package_version "$runtimeFullName")
local url="$DNX_FEED/package/$pkgName/$pkgVersion"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed."
return 0
if [ -n "$force" ]; then
printf "%b\n" "${Yel}Forcing download by deleting $runtimeFolder directory ${RCol}"
rm -rf "$runtimeFolder"
fi
echo "Downloading $runtimeFullName from $DNX_FEED"
if [ -e "$runtimeFolder" ]; then
printf "%b\n" "${Gre}$runtimeFullName already installed. ${RCol}"
return 0
fi
if ! __dnvm_has "curl"; then
echo "$_DNVM_COMMAND_NAME needs curl to proceed." >&2;
printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2;
return 1
fi
mkdir -p "$runtimeFolder" > /dev/null 2>&1
local httpResult=$(curl -L -D - "$url" -o "$runtimeFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
echo "Downloading $runtimeFullName from $DNX_FEED"
echo "Download: $url"
[[ $httpResult == "404" ]] && echo "$runtimeFullName was not found in repository $DNX_FEED" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $runtimeFullName from $DNX_FEED" && return 1
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
__dnvm_unpack $runtimeFile $runtimeFolder
return $?
@ -163,47 +205,65 @@ __dnvm_locate_runtime_bin_from_full_name() {
[ -e "$_DNVM_USER_PACKAGES/$runtimeFullName/bin" ] && echo "$_DNVM_USER_PACKAGES/$runtimeFullName/bin" && return
}
__echo_art() {
printf "%b" "${Cya}"
echo " ___ _ ___ ____ ___"
echo " / _ \/ |/ / | / / |/ /"
echo " / // / /| |/ / /|_/ / "
echo " /____/_/|_/ |___/_/ /_/ "
printf "%b" "${RCol}"
}
__dnvm_help() {
__echo_art
echo ""
echo "$_DNVM_VERSION_MANAGER_NAME - Version 1.0.0-$_DNVM_BUILDNUMBER"
[ "$_DNVM_AUTHORS" != "{{*" ] && echo "By $_DNVM_AUTHORS"
[[ "$_DNVM_AUTHORS" != {{* ]] && echo "By $_DNVM_AUTHORS"
echo ""
echo "USAGE: $_DNVM_COMMAND_NAME <command> [options]"
printf "%b\n" "${Cya}USAGE:${Yel} $_DNVM_COMMAND_NAME <command> [options] ${RCol} \n"
echo ""
echo "$_DNVM_COMMAND_NAME upgrade"
echo "install latest $_DNVM_RUNTIME_SHORT_NAME from feed"
echo "add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo "set installed version as default"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] ${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 ""
echo "$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p -persistent]"
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 "add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p|-persistent] [-f|-force] ${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 ""
echo "$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p -persistent]"
echo "<semver>|<alias>|<package> add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line "
echo "none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line"
echo "-p -persistent set selected version as default"
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo ""
echo "$_DNVM_COMMAND_NAME list"
echo "list $_DNVM_RUNTIME_SHORT_NAME versions installed "
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p -persistent] ${RCol}"
echo " <semver>|<alias>|<package> add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line "
echo " none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line"
echo " -p|-persistent set selected version as default"
echo ""
echo "$_DNVM_COMMAND_NAME alias"
echo "list $_DNVM_RUNTIME_SHORT_NAME aliases which have been defined"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list ${RCol}"
echo " list $_DNVM_RUNTIME_SHORT_NAME versions installed "
echo ""
echo "$_DNVM_COMMAND_NAME alias <alias>"
echo "display value of the specified alias"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}"
echo " list $_DNVM_RUNTIME_SHORT_NAME aliases which have been defined"
echo ""
echo "$_DNVM_COMMAND_NAME alias <alias> <semver>|<alias>|<package>"
echo "<alias> the name of the alias to set"
echo "<semver>|<alias>|<package> the $_DNVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias <alias> ${RCol}"
echo " display value of the specified alias"
echo ""
echo "$_DNVM_COMMAND_NAME unalias <alias>"
echo "remove the specified alias"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias <alias> <semver>|<alias>|<package> ${RCol}"
echo " <alias> the name of the alias to set"
echo " <semver>|<alias>|<package> the $_DNVM_RUNTIME_SHORT_NAME version to set the alias to. Alternatively use the version of the specified alias"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME unalias <alias> ${RCol}"
echo " remove the specified alias"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME [help|-h|-help|--help] ${RCol}"
echo " displays this help text."
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME update-self ${RCol}"
echo " updates dnvm itself."
}
dnvm()
@ -214,13 +274,17 @@ dnvm()
fi
case $1 in
"help" )
"help"|"-h"|"-help"|"--help" )
__dnvm_help
;;
"update-self" )
__dnvm_update_self
;;
"upgrade" )
[ $# -ne 1 ] && __dnvm_help && return
$_DNVM_COMMAND_NAME install latest -p
shift
$_DNVM_COMMAND_NAME install latest -p $1
;;
"install" )
@ -229,6 +293,7 @@ dnvm()
local persistent=
local versionOrAlias=
local alias=
local force=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
@ -236,18 +301,26 @@ dnvm()
elif [[ $1 == "-a" || $1 == "-alias" ]]; then
local alias=$2
shift
elif [[ $1 == "-f" || $1 == "-force" ]]; then
local force="-f"
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1
local versionOrAlias=$1
fi
shift
done
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
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
echo "Latest version is $versionOrAlias"
printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}"
fi
if [[ "$versionOrAlias" == *.nupkg ]]; then
local runtimeFullName=$(basename $versionOrAlias | sed "s/\(.*\)\.nupkg/\1/")
local runtimeVersion=$(__dnvm_package_version "$runtimeFullName")
@ -267,7 +340,7 @@ dnvm()
else
local runtimeFullName="$(__dnvm_requested_version_or_alias $versionOrAlias)"
local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName"
__dnvm_download "$runtimeFullName" "$runtimeFolder"
__dnvm_download "$runtimeFullName" "$runtimeFolder" "$force"
[[ $? == 1 ]] && return 1
$_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent"
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias"