Update to latest `dnvm`

- beta6-10394 to beta8-15518
  - grabbed from aspnet/Home but left default feed URIs alone
  - includes important fixes such as `dnvm use alias -r coreclr` support
This commit is contained in:
Doug Bunting 2015-09-24 15:29:59 -07:00
parent 7c39334783
commit 345c59826c
2 changed files with 896 additions and 306 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,8 @@
# Source this file from your .bash-profile or script to use
# "Constants"
_DNVM_BUILDNUMBER="beta6-10394"
_DNVM_AUTHORS=".NET Foundation"
_DNVM_BUILDNUMBER="beta8-15518"
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
_DNVM_RUNTIME_SHORT_NAME="DNX"
@ -14,7 +14,6 @@ _DNVM_VERSION_MANAGER_NAME=".NET Version Manager"
_DNVM_DEFAULT_FEED="https://www.myget.org/F/aspnetcidev/api/v2"
_DNVM_DEFAULT_UNSTABLE_FEED="https://www.myget.org/F/aspnetcidev/api/v2"
_DNVM_UPDATE_LOCATION="https://raw.githubusercontent.com/aspnet/Home/dev/dnvm.sh"
_DNVM_HOME_VAR_NAME="DNX_HOME"
if [ "$NO_COLOR" != "1" ]; then
# ANSI Colors
@ -47,7 +46,19 @@ if [ -z "$DNX_USER_HOME" ]; then
eval DNX_USER_HOME="~/$_DNVM_RUNTIME_FOLDER_NAME"
fi
if [ -z "$DNX_GLOBAL_HOME" ]; then
eval DNX_GLOBAL_HOME="/usr/local/lib/dnx"
fi
if [ -z "$DNX_HOME" ]; then
# Set to the user home value
eval DNX_HOME="$DNX_USER_HOME:$DNX_GLOBAL_HOME"
elif [[ $DNX_HOME != *"$DNX_GLOBAL_HOME"* ]]; then
eval DNX_HOME="$DNX_HOME:$DNX_GLOBAL_HOME"
fi
_DNVM_USER_PACKAGES="$DNX_USER_HOME/runtimes"
_DNVM_GLOBAL_PACKAGES="$DNX_GLOBAL_HOME/runtimes"
_DNVM_ALIAS_DIR="$DNX_USER_HOME/alias"
_DNVM_DNVM_DIR="$DNX_USER_HOME/dnvm"
@ -63,35 +74,86 @@ __dnvm_current_os()
fi
}
__dnvm_os_runtime_defaults()
{
local os=$1
if [[ $os == "win" ]]; then
echo "clr"
elif [[ $os == "linux" ]]; then
echo "mono"
elif [[ $os == "darwin" ]]; then
echo "mono"
else
echo "unknown os"
fi
}
__dnvm_runtime_bitness_defaults()
{
local runtime=$1
if [[ $runtime == "clr" ]]; then
echo "x86"
elif [[ $runtime == "coreclr" ]]; then
echo "x64"
else
echo "unknown runtime"
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() {
local platform=$1
local arch=$2
if [ -z $platform ]; then
local platform="mono"
fi
local os=$3
if ! __dnvm_has "curl"; then
printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2;
return 1
fi
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-$(__dnvm_current_os)-$arch"
local packageId="$_DNVM_RUNTIME_PACKAGE_NAME-$platform-$os-$arch"
fi
local url="$DNX_ACTIVE_FEED/GetUpdates()?packageIds=%27$packageId%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/')"
echo $version
__dnvm_query_feed $url
return $?
}
__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() {
echo "$1" | sed -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g"
echo "$1" | sed -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_USER_PACKAGES/[^/]*$2[^:]*##g" | sed -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*:##g" -e "s#:$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g" -e "s#$_DNVM_GLOBAL_PACKAGES/[^/]*$2[^:]*##g"
}
__dnvm_prepend_path() {
@ -125,12 +187,26 @@ __dnvm_package_arch() {
fi
}
__dnvm_package_os() {
local runtimeFullName="$1"
if [[ "$runtimeFullName" =~ "mono" ]]; then
echo "linux/osx"
else
echo "$runtimeFullName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-[^-.]*-\([^.-]*\).*/\1/"
fi
}
__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}"
local bashSourceLocation=${BASH_SOURCE}
local scriptLocation=$bashSourceLocation
if [ -z "${bashSourceLocation}" ]; then
local scriptLocation=${(%):-%x}
fi
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. dnvm is currently sourced from $scriptLocation ${RCol}"
return 1
fi
printf "%b\n" "${Cya}Downloading dnvm.sh from $_DNVM_UPDATE_LOCATION ${RCol}"
@ -142,14 +218,32 @@ __dnvm_update_self() {
source "$dnvmFileLocation"
}
__dnvm_promptSudo() {
local acceptSudo="$1"
local answer=
if [ "$acceptSudo" == "0" ]; then
echo "In order to install dnx globally, dnvm will have to temporarily run as root."
read -p "You may be prompted for your password via 'sudo' during this process. Is this Ok? (y/N) " answer
else
answer="y"
fi
if echo $answer | grep -iq "^y" ; then
return 1
else
return 0
fi
}
__dnvm_download() {
local runtimeFullName="$1"
local runtimeFolder="$2"
local force="$3"
local downloadUrl="$2"
local runtimeFolder="$3"
local force="$4"
local acceptSudo="$5"
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
@ -161,18 +255,26 @@ __dnvm_download() {
printf "%b\n" "${Gre}$runtimeFullName already installed. ${RCol}"
return 0
fi
if ! __dnvm_has "curl"; then
printf "%b\n" "${Red}$_DNVM_COMMAND_NAME needs curl to proceed. ${RCol}" >&2;
return 1
fi
local useSudo=
mkdir -p "$runtimeFolder" > /dev/null 2>&1
if [ ! -d $runtimeFolder ]; then
if ! __dnvm_promptSudo $acceptSudo ; then
useSudo=sudo
sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1
else
return 1
fi
fi
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=$($useSudo 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}"
@ -181,13 +283,14 @@ __dnvm_download() {
fi
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "${Red}HTTP Error $httpResult fetching $runtimeFullName from $DNX_ACTIVE_FEED ${RCol}" && return 1
__dnvm_unpack $runtimeFile $runtimeFolder
__dnvm_unpack $runtimeFile $runtimeFolder $useSudo
return $?
}
__dnvm_unpack() {
local runtimeFile="$1"
local runtimeFolder="$2"
local useSudo=$3
echo "Installing to $runtimeFolder"
@ -196,28 +299,32 @@ __dnvm_unpack() {
return 1
fi
unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1
$useSudo unzip $runtimeFile -d $runtimeFolder > /dev/null 2>&1
[ -e "$runtimeFolder/[Content_Types].xml" ] && rm "$runtimeFolder/[Content_Types].xml"
[ -e "$runtimeFolder/[Content_Types].xml" ] && $useSudo rm "$runtimeFolder/[Content_Types].xml"
[ -e "$runtimeFolder/_rels/" ] && rm -rf "$runtimeFolder/_rels/"
[ -e "$runtimeFolder/_rels/" ] && $useSudo rm -rf "$runtimeFolder/_rels/"
[ -e "$runtimeFolder/package/" ] && rm -rf "$runtimeFolder/_package/"
[ -e "$runtimeFolder/package/" ] && $useSudo rm -rf "$runtimeFolder/_package/"
[ -e "$runtimeFile" ] && rm -f "$runtimeFile"
#Set shell commands as executable
find "$runtimeFolder/bin/" -type f \
-exec sh -c "head -c 20 {} | grep '/usr/bin/env bash\|/bin/bash' > /dev/null" \; -print | xargs chmod 775
[ -e "$runtimeFile" ] && $useSudo rm -f "$runtimeFile"
#Set dnx to be executable
chmod 775 "$runtimeFolder/bin/dnx"
if [[ -s "$runtimeFolder/bin/dnx" ]]; then
$useSudo chmod 775 "$runtimeFolder/bin/dnx"
fi
#Set dnu to be executable
if [[ -s "$runtimeFolder/bin/dnu" ]]; then
$useSudo chmod 775 "$runtimeFolder/bin/dnu"
fi
}
__dnvm_requested_version_or_alias() {
local versionOrAlias="$1"
local runtime="$2"
local arch="$3"
local os="$4"
local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$versionOrAlias")
# If the name specified is an existing package, just use it as is
@ -226,22 +333,30 @@ __dnvm_requested_version_or_alias() {
else
if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then
local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias")
echo "$runtimeFullName"
else
local pkgVersion=$versionOrAlias
if [[ -z $runtime || "$runtime" == "mono" ]]; then
echo "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$pkgVersion"
elif [[ "$runtime" == "coreclr" ]]; then
local pkgArchitecture="x64"
local pkgSystem=$(__dnvm_current_os)
if [ "$arch" != "" ]; then
local pkgArchitecture="$arch"
fi
echo "$_DNVM_RUNTIME_PACKAGE_NAME-coreclr-$pkgSystem-$pkgArchitecture.$pkgVersion"
if [[ ! -n "$runtime" && ! -n "$arch" ]]; then
echo "$runtimeFullName"
return
fi
local pkgVersion=$(__dnvm_package_version "$runtimeFullName")
fi
if [[ ! -n "$pkgVersion" ]]; then
local pkgVersion=$versionOrAlias
fi
local pkgArchitecture="x64"
local pkgSystem=$os
if [[ -z $runtime || "$runtime" == "mono" ]]; then
echo "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$pkgVersion"
else
if [ "$arch" != "" ]; then
local pkgArchitecture="$arch"
fi
if [ "$os" == "" ]; then
local pkgSystem=$(__dnvm_current_os)
fi
echo "$_DNVM_RUNTIME_PACKAGE_NAME-$runtime-$pkgSystem-$pkgArchitecture.$pkgVersion"
fi
fi
}
@ -249,7 +364,11 @@ __dnvm_requested_version_or_alias() {
# This will be more relevant if we support global installs
__dnvm_locate_runtime_bin_from_full_name() {
local runtimeFullName=$1
[ -e "$_DNVM_USER_PACKAGES/$runtimeFullName/bin" ] && echo "$_DNVM_USER_PACKAGES/$runtimeFullName/bin" && return
for v in `echo $DNX_HOME | tr ":" "\n"`; do
if [ -e "$v/runtimes/$runtimeFullName/bin" ]; then
echo "$v/runtimes/$runtimeFullName/bin" && return
fi
done
}
__echo_art() {
@ -273,41 +392,50 @@ __dnvm_description() {
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_version() {
echo "1.0.0-$_DNVM_BUILDNUMBER"
}
__dnvm_help() {
__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}"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME upgrade [-f|-force] [-u|-unstable] [-g|-global] [-y]${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 " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed"
echo " -r|runtime The runtime flavor to install [clr or coreclr] (default: clr)"
echo " -g|global Installs the latest $_DNVM_RUNTIME_SHORT_NAME in the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DNX_GLOBAL_HOME)"
echo " -y Assume Yes to all queries and do not prompt"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-a|-alias <alias>] [-p|-persistent] [-f|-force] [-u|-unstable] ${RCol}"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME install <semver>|<alias>|<nupkg>|latest [-r <runtime>] [-OS <OS>] [-a|-alias <alias>] [-p|-persistent] [-f|-force] [-u|-unstable] [-g|-global] [-y]${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 " -OS the operating system that the runtime targets (default:$(__dnvm_current_os)"
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 " -u|unstable use unstable feed. Installs the $_DNVM_RUNTIME_SHORT_NAME from the unstable feed"
echo " -r|runtime The runtime flavor to install [mono or coreclr] (default: mono)"
echo " -g|global Installs to the configured global $_DNVM_RUNTIME_SHORT_NAME file location (default: /usr/local/lib/dnx current: $DNX_GLOBAL_HOME)"
echo " -y Assume Yes to all queries and do not prompt"
echo ""
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
echo ""
@ -332,7 +460,9 @@ __dnvm_help() {
echo " runs the specified command in the context of the specified version of the runtime without affecting the current PATH"
echo " example: $_DNVM_COMMAND_NAME exec 1.0.0-beta4 $_DNVM_PACKAGE_MANAGER_NAME build"
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list ${RCol}"
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME list [-detailed]${RCol}"
echo " -detailed display more detailed information on each runtime"
echo ""
echo " list $_DNVM_RUNTIME_SHORT_NAME versions installed "
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME alias ${RCol}"
@ -351,6 +481,9 @@ __dnvm_help() {
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 [version|-v|-version|--version] ${RCol}"
echo " print the dnvm version."
echo ""
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME update-self ${RCol}"
echo " updates dnvm itself."
}
@ -370,6 +503,10 @@ dnvm()
__dnvm_help
;;
"version"|"-v"|"-version"|"--version" )
__dnvm_version
;;
"update-self" )
__dnvm_update_self
;;
@ -387,8 +524,11 @@ dnvm()
local alias=
local force=
local unstable=
local runtime="mono"
local arch="x64"
local os=
local runtime=
local arch=
local global=0
local acceptSudo=0
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
@ -403,20 +543,21 @@ dnvm()
elif [[ $1 == "-r" || $1 == "-runtime" ]]; then
local runtime=$2
shift
elif [[ $1 == "-OS" ]]; then
local os=$2
shift
elif [[ $1 == "-y" ]]; then
local acceptSudo=1
elif [[ $1 == "-arch" ]]; then
local arch=$2
shift
if [[ $arch != "x86" && $arch != "x64" ]]; then
printf "%b\n" "${Red}Architecture must be x86 or x64.${RCol}"
printf "%b\n" "${Red}Architecture must be x86 or x64.${RCol}"
return 1
fi
if [[ $arch == "x86" && $runtime == "coreclr" ]]; then
printf "%b\n" "${Red}Core CLR doesn't currently have a 32 bit build. You must use x64.${RCol}"
return 1
fi
elif [[ $1 == "-g" || $1 == "-global" ]]; then
local global=1
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1
local versionOrAlias=$1
@ -424,6 +565,11 @@ dnvm()
shift
done
if [[ $arch == "x86" && $runtime == "coreclr" && $os != "win" ]]; then
printf "%b\n" "${Red}Core CLR doesn't currently have a 32 bit build. You must use x64.${RCol}"
return 1
fi
if [ -z $unstable ]; then
DNX_ACTIVE_FEED="$DNX_FEED"
if [ -z "$DNX_ACTIVE_FEED" ]; then
@ -440,21 +586,66 @@ dnvm()
fi
fi
if [[ -z $os ]]; then
os=$(__dnvm_current_os)
fi
if [[ $os == "osx" ]]; then
os="darwin"
fi
if [[ -z $runtime ]]; then
runtime=$(__dnvm_os_runtime_defaults "$os")
fi
if [[ -z $arch ]]; then
arch=$(__dnvm_runtime_bitness_defaults "$runtime")
fi
if [[ $runtime == "mono" ]] && ! __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 "$runtime" "$arch")
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $DNX_ACTIVE_FEED" && return 1
printf "%b\n" "Latest version is ${Cya}$versionOrAlias ${RCol}"
local runtimeDir=$_DNVM_USER_PACKAGES
if [ $global == 1 ]; then
runtimeDir=$_DNVM_GLOBAL_PACKAGES
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="$runtimeDir/$runtimeFullName"
local exist=0
for folder in `echo $DNX_HOME | tr ":" "\n"`; do
if [ -e "$folder/runtimes/$runtimeFullName" ]; then
echo "$runtimeFullName already installed in $folder"
exist=1
fi
done
if [[ $exist != 1 ]]; then
__dnvm_download "$runtimeFullName" "$downloadUrl" "$runtimeFolder" "$force" "$acceptSudo"
fi
[[ $? == 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"
local runtimeFolder="$runtimeDir/$runtimeFullName"
local runtimeFile="$runtimeFolder/$runtimeFullName.nupkg"
local runtimeClr=$(__dnvm_package_runtime "$runtimeFullName")
@ -466,20 +657,22 @@ dnvm()
if [ -e "$runtimeFolder" ]; then
echo "$runtimeFullName already installed"
else
local useSudo=
mkdir -p "$runtimeFolder" > /dev/null 2>&1
if [ ! -d $runtimeFolder ]; then
if ! __dnvm_promptSudo $acceptSudo ; then
useSudo=sudo
sudo mkdir -p "$runtimeFolder" > /dev/null 2>&1 || return 1
else
return 1
fi
fi
cp -a "$versionOrAlias" "$runtimeFile"
__dnvm_unpack "$runtimeFile" "$runtimeFolder"
__dnvm_unpack "$runtimeFile" "$runtimeFolder" $useSudo
[[ $? == 1 ]] && return 1
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")
local runtimeFolder="$_DNVM_USER_PACKAGES/$runtimeFullName"
__dnvm_download "$runtimeFullName" "$runtimeFolder" "$force"
[[ $? == 1 ]] && return 1
$_DNVM_COMMAND_NAME use "$versionOrAlias" "$persistent" "-runtime" "$runtime" "-arch" "$arch"
[[ -n $alias ]] && $_DNVM_COMMAND_NAME alias "$alias" "$versionOrAlias"
fi
;;
@ -491,9 +684,9 @@ dnvm()
local arch=
local runtime=
local versionOrAlias=
shift
if [ $cmd == "use" ]; then
local versionOrAlias=
while [ $# -ne 0 ]
do
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
@ -513,8 +706,20 @@ dnvm()
shift
done
else
local versionOrAlias=$1
shift
while [ $# -ne 0 ]
do
if [[ $1 == "-a" || $1 == "-arch" ]]; then
local arch=$2
shift
elif [[ $1 == "-r" || $1 == "-runtime" ]]; then
local runtime=$2
shift
elif [[ -n $1 ]]; then
[[ -n $versionOrAlias ]] && break
local versionOrAlias=$1
fi
shift
done
fi
if [[ $cmd == "use" && $versionOrAlias == "none" ]]; then
@ -529,7 +734,7 @@ dnvm()
return 0
fi
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch")
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$(__dnvm_current_os)")
local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$runtimeFullName")
if [[ -z $runtimeBin ]]; then
@ -542,18 +747,20 @@ dnvm()
local hostpath="$runtimeBin/dnx"
if [[ -e $hostpath ]]; then
$hostpath $@
return $?
else
echo "Cannot find $_DNVM_RUNTIME_SHORT_NAME in $runtimeBin. It may have been corrupted. Use '$_DNVM_COMMAND_NAME install $versionOrAlias -f' to attempt to reinstall it"
fi
;;
"exec")
"exec")
(
PATH=$(__dnvm_strip_path "$PATH" "/bin")
PATH=$(__dnvm_prepend_path "$PATH" "$runtimeBin")
$@
)
return $?
;;
"use")
"use")
echo "Adding" $runtimeBin "to process PATH"
PATH=$(__dnvm_strip_path "$PATH" "/bin")
@ -591,7 +798,7 @@ dnvm()
local name="$1"
if [[ $# == 1 ]]; then
[[ ! -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return
[[ ! -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && echo "There is no alias called '$name'" && return 1
cat "$_DNVM_ALIAS_DIR/$name.alias"
echo ""
return
@ -608,18 +815,21 @@ dnvm()
elif [[ $1 == "-r" || $1 == "-runtime" ]]; then
local runtime=$2
shift
elif [[ $1 == "-OS" ]]; then
local os=$2
shift
fi
shift
done
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch")
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch" "$os")
[[ ! -d "$_DNVM_USER_PACKAGES/$runtimeFullName" ]] && echo "$runtimeFullName is not an installed $_DNVM_RUNTIME_SHORT_NAME version" && return 1
([[ ! -d "$_DNVM_USER_PACKAGES/$runtimeFullName" ]] && [[ ! -d "$_DNVM_GLOBAL_PACKAGES/$runtimeFullName" ]]) && echo "$runtimeFullName is not an installed $_DNVM_RUNTIME_SHORT_NAME version" && return 1
local action="Setting"
[[ -e "$_DNVM_ALIAS_DIR/$name.alias" ]] && action="Updating"
echo "$action alias '$name' to '$runtimeFullName'"
echo "$runtimeFullName" > "$_DNVM_ALIAS_DIR/$name.alias"
echo "$runtimeFullName" >| "$_DNVM_ALIAS_DIR/$name.alias"
;;
"unalias" )
@ -638,10 +848,20 @@ dnvm()
[[ ! -d $_DNVM_USER_PACKAGES ]] && echo "$_DNVM_RUNTIME_FRIENDLY_NAME is not installed." && return 1
local searchGlob="$_DNVM_RUNTIME_PACKAGE_NAME-*"
if [ $# == 2 ]; then
local versionOrAlias=$2
local searchGlob=$(__dnvm_requested_version_or_alias "$versionOrAlias")
fi
local runtimes=""
for location in `echo $DNX_HOME | tr ":" "\n"`; do
location+="/runtimes"
if [ -d "$location" ]; then
local oruntimes="$(find $location -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;)"
for v in `echo $oruntimes | tr "\n" " "`; do
runtimes+="$v:$location"$'\n'
done
fi
done
[[ -z $runtimes ]] && echo 'No runtimes installed. You can run `dnvm install latest` or `dnvm upgrade` to install a runtime.' && return
echo ""
# Separate empty array declaration from initialization
@ -654,39 +874,79 @@ dnvm()
local format="%-20s %s\n"
if [ -d "$_DNVM_ALIAS_DIR" ]; then
for __dnvm_file in $(find "$_DNVM_ALIAS_DIR" -name *.alias); do
arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/$(cat $__dnvm_file)"
if [ ! -d "$_DNVM_USER_PACKAGES/$(cat $__dnvm_file)" ] && [ ! -d "$_DNVM_GLOBAL_PACKAGES/$(cat $__dnvm_file)" ]; then
arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/missing/$(cat $__dnvm_file)"
runtimes="$runtimes $(cat $__dnvm_file)"
else
arr[$i]="$(basename $__dnvm_file | sed 's/\.alias//')/$(cat $__dnvm_file)"
fi
let i+=1
done
fi
local formatString="%-6s %-20s %-7s %-4s %-20s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Arch" "Location" "Alias"
printf "$formatString" "------" "-------" "-------" "----" "--------" "-----"
if [[ $2 == "-detailed" ]]; then
# Calculate widest alias
local widestAlias=5
for f in `echo $runtimes`; do
local pkgName=$(__dnvm_package_name "$f")
local pkgVersion=$(__dnvm_package_version "$f")
local alias=""
local delim=""
for i in "${arr[@]}"; do
if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then
alias+="$delim${i%%/*}"
delim=", "
if [[ "${i%/*}" =~ \/missing$ ]]; then
alias+=" (missing)"
fi
fi
done
if [ "${#alias}" -gt "$widestAlias" ]; then
widestAlias=${#alias}
fi
done
local formatString="%-6s %-20s %-7s %-12s %-15s %-${widestAlias}s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Architecture" "OperatingSystem" "Alias" "Location"
printf "$formatString" "------" "-------" "-------" "------------" "---------------" "-----" "--------"
else
local formatString="%-6s %-20s %-7s %-12s %-15s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Architecture" "OperatingSystem" "Alias"
printf "$formatString" "------" "-------" "-------" "------------" "---------------" "-----"
fi
local formattedHome=`(echo $_DNVM_USER_PACKAGES | sed s=$HOME=~=g)`
for f in $(find $_DNVM_USER_PACKAGES -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;); do
for f in `echo -e "$runtimes" | sort -t. -k2 -k3 -k4 -k1`; do
local location=`echo $f | sed 's/.*\([:]\)//'`
f=`echo $f | sed 's/\([:]\).*//'`
local formattedHome=`(echo $location | sed s=$HOME=~=g)`
local active=""
[[ $PATH == *"$_DNVM_USER_PACKAGES/$f/bin"* ]] && local active=" *"
[[ $PATH == *"$location/$f/bin"* ]] && local active=" *"
local pkgRuntime=$(__dnvm_package_runtime "$f")
local pkgName=$(__dnvm_package_name "$f")
local pkgVersion=$(__dnvm_package_version "$f")
local pkgArch=$(__dnvm_package_arch "$f")
local pkgOs=$(__dnvm_package_os "$f")
local alias=""
local delim=""
for i in "${arr[@]}"; do
if [[ ${i#*/} == "$pkgName.$pkgVersion" ]]; then
alias+="$delim${i%/*}"
if [[ ${i##*/} == "$pkgName.$pkgVersion" ]]; then
alias+="$delim${i%%/*}"
delim=", "
if [[ "${i%/*}" =~ \/missing$ ]]; then
alias+=" (missing)"
formattedHome=""
fi
fi
done
printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$formattedHome" "$alias"
[[ $# == 2 ]] && echo "" && return 0
if [[ $2 == "-detailed" ]]; then
printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$pkgOs" "$alias" "$formattedHome"
else
printf "$formatString" "$active" "$pkgVersion" "$pkgRuntime" "$pkgArch" "$pkgOs" "$alias"
fi
done
echo ""
[[ $# == 2 ]] && echo "$versionOrAlias not found" && return 1
;;
*)
@ -697,5 +957,8 @@ dnvm()
return 0
}
# Add the home location's bin directory to the path if it doesn't exist
[[ ":$PATH:" != *":$DNX_USER_HOME/bin:"* ]] && export PATH="$DNX_USER_HOME/bin:$PATH"
# Generate the command function using the constant defined above.
$_DNVM_COMMAND_NAME list default >/dev/null && $_DNVM_COMMAND_NAME use default >/dev/null || true
$_DNVM_COMMAND_NAME alias default >/dev/null && $_DNVM_COMMAND_NAME use default >/dev/null || true