Skip to content

Commit

Permalink
Updated kvm build
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfowl committed Sep 30, 2014
1 parent 9d505f5 commit dfea4ee
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 39 deletions.
2 changes: 1 addition & 1 deletion kvm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ $scriptPath = $myInvocation.MyCommand.Definition

function Kvm-Help {
@"
K Runtime Environment Version Manager - Build 10015
K Runtime Environment Version Manager - Build 10017
USAGE: kvm <command> [options]
Expand Down
57 changes: 19 additions & 38 deletions kvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@ if [ -z "$KRE_USER_HOME" ]; then
fi

KRE_USER_PACKAGES="$KRE_USER_HOME/packages"
KRE_MONO45=
KRE_X86=
KRE_X64=
if [ -z "$KRE_FEED" ]; then
KRE_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
fi

_kvm_find_latest() {
local platform="mono45"
local architecture="x86"
local platform="Mono"

if ! _kvm_has "curl"; then
echo 'KVM Needs curl to proceed.' >&2;
return 1
fi

local url="$KRE_FEED/GetUpdates()?packageIds=%27KRE-$platform-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
local url="$KRE_FEED/GetUpdates()?packageIds=%27KRE-$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/')"
Expand Down Expand Up @@ -61,7 +57,7 @@ _kvm_package_name() {

_kvm_package_runtime() {
local kreFullName="$1"
echo "$kreFullName" | sed "s/KRE-\([^-]*\).*/\1/"
echo "$kreFullName" | sed "s/KRE-\([^.-]*\).*/\1/"
}

_kvm_download() {
Expand Down Expand Up @@ -93,6 +89,7 @@ _kvm_download() {
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $kreFullName from $KRE_FEED" && return 1

_kvm_unpack $kreFile $kreFolder
return $?
}

_kvm_unpack() {
Expand All @@ -119,38 +116,20 @@ _kvm_unpack() {
-exec sh -c "head -c 11 {} | grep '/bin/bash' > /dev/null" \; -print | xargs chmod 775
}

# This is not currently required. Placeholder for the case when we have multiple platforms (ie if we bundle mono)
_kvm_requested_platform() {
local default=$1
[[ -z $KRE_MONO45 ]] && echo "mono45" && return
echo $default
}

# This is not currently required. Placeholder for the case where we have multiple architectures (ie if we bundle mono)
_kvm_requested_architecture() {
local default=$1

[[ -n $KRE_X86 && -n $KRE_X64 ]] && echo "This command cannot accept both -x86 and -x64" && return 1
[[ -z $KRE_X86 ]] && echo "x86" && return
[[ -z $KRE_X64 ]] && echo "x64" && return
echo $default
}

_kvm_requested_version_or_alias() {
local versionOrAlias="$1"

if [ -e "$KRE_USER_HOME/alias/$versionOrAlias.alias" ]; then
local kreFullName=$(cat "$KRE_USER_HOME/alias/$versionOrAlias.alias")
local pkgName=$(echo $kreFullName | sed "s/\([^.]*\).*/\1/")
local pkgVersion=$(echo $kreFullName | sed "s/[^.]*.\(.*\)/\1/")
local pkgPlatform=$(_kvm_requested_platform $(echo "$pkgName" | sed "s/KRE-\([^-]*\).*/\1/"))
local pkgArchitecture=$(_kvm_requested_architecture $(echo "$pkgName" | sed "s/.*-.*-\([^-]*\).*/\1/"))
local pkgPlatform=$(echo "$pkgName" | sed "s/KRE-\([^.-]*\).*/\1/")
else
local pkgVersion=$versionOrAlias
local pkgPlatform=$(_kvm_requested_platform "mono45")
local pkgArchitecture=$(_kvm_requested_architecture "x86")
local pkgPlatform="Mono"
fi
echo "KRE-$pkgPlatform-$pkgArchitecture.$pkgVersion"

echo "KRE-$pkgPlatform.$pkgVersion"
}

# This will be more relevant if we support global installs
Expand All @@ -169,7 +148,7 @@ kvm()
case $1 in
"help" )
echo ""
echo "K Runtime Environment Version Manager - Build 10015"
echo "K Runtime Environment Version Manager - Build 10017"
echo ""
echo "USAGE: kvm <command> [options]"
echo ""
Expand Down Expand Up @@ -235,7 +214,7 @@ kvm()
done
if [[ "$versionOrAlias" == "latest" ]]; then
echo "Determining latest version"
versionOrAlias=$(_kvm_find_latest mono45 x86)
versionOrAlias=$(_kvm_find_latest)
[[ $? == 1 ]] && echo "Error: Could not find latest version from feed $KRE_FEED" && return 1
echo "Latest version is $versionOrAlias"
fi
Expand All @@ -251,14 +230,15 @@ kvm()
mkdir "$kreFolder" > /dev/null 2>&1
cp -a "$versionOrAlias" "$kreFile"
_kvm_unpack "$kreFile" "$kreFolder"
[[ $? == 1 ]] && return 1
fi
kvm use "$kreVersion" "$persistent"
[[ -n $alias ]] && kvm alias "$alias" "$kreVersion"
else
local kreFullName="$(_kvm_requested_version_or_alias $versionOrAlias)"
local kreFolder="$KRE_USER_PACKAGES/$kreFullName"
_kvm_download "$kreFullName" "$kreFolder"
[[ $? == 1 ]] && return
[[ $? == 1 ]] && return 1
kvm use "$versionOrAlias" "$persistent"
[[ -n $alias ]] && kvm alias "$alias" "$versionOrAlias"
fi
Expand Down Expand Up @@ -379,9 +359,9 @@ kvm()
let i+=1
done

local formatString="%-6s %-20s %-7s %-12s %-20s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Architecture" "Location" "Alias"
printf "$formatString" "------" "-------" "-------" "------------" "--------" "-----"
local formatString="%-6s %-20s %-7s %-20s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Location" "Alias"
printf "$formatString" "------" "-------" "-------" "--------" "-----"

local formattedHome=`(echo $KRE_USER_PACKAGES | sed s=$HOME=~=g)`
for f in $(find $KRE_USER_PACKAGES/* -name "$searchGlob" -type d -prune -exec basename {} \;); do
Expand All @@ -393,14 +373,15 @@ kvm()
local alias=""
local delim=""
for i in "${arr[@]}"; do
temp="KRE-$pkgName-x86.$pkgVersion"
if [[ ${i#*/} == $temp ]]; then
temp="KRE-$pkgName.$pkgVersion"
temp2="KRE-$pkgName-x86.$pkgVersion"
if [[ ${i#*/} == $temp || ${i#*/} == $temp2 ]]; then
alias+="$delim${i%/*}"
delim=", "
fi
done

printf "$formatString" "$active" "$pkgVersion" "$pkgName" "x86" "$formattedHome" "$alias"
printf "$formatString" "$active" "$pkgVersion" "$pkgName" "$formattedHome" "$alias"
[[ $# == 2 ]] && echo "" && return 0
done

Expand Down

0 comments on commit dfea4ee

Please sign in to comment.