Updating Kvm in home/dev

This commit is contained in:
Praburaj 2015-01-06 10:23:35 -08:00
parent 0ae0435e98
commit 8e4c1393a7
2 changed files with 321 additions and 191 deletions

441
kvm.ps1
View File

@ -1,36 +1,50 @@
param( param(
[parameter(Position=0)] [parameter(Position=0)]
[string] $command, [string] $Command,
[string] $proxy, [string] $Proxy,
[switch] $verbosity = $false, [switch] $Verbosity = $false,
[alias("g")][switch] $global = $false, [alias("g")][switch] $Global = $false,
[alias("p")][switch] $persistent = $false, [alias("p")][switch] $Persistent = $false,
[alias("f")][switch] $force = $false, [alias("f")][switch] $Force = $false,
[alias("r")][string] $runtime, [alias("r")][string] $Runtime,
[switch] $x86 = $false, [alias("arch")][string] $Architecture,
[switch] $amd64 = $false, [switch] $X86 = $false,
[switch] $Amd64 = $false,
#deprecated #deprecated
[switch] $x64 = $false, [switch] $X64 = $false,
#deprecated #deprecated
[switch] $svr50 = $false, [switch] $Svr50 = $false,
#deprecated #deprecated
[switch] $svrc50 = $false, [switch] $Svrc50 = $false,
[alias("w")][switch] $wait = $false, [alias("w")][switch] $Wait = $false,
[alias("a")] [alias("a")]
[string] $alias = $null, [string] $Alias = $null,
[switch] $NoNative = $false,
[parameter(Position=1, ValueFromRemainingArguments=$true)] [parameter(Position=1, ValueFromRemainingArguments=$true)]
[string[]]$args=@() [string[]]$Args=@(),
[switch] $Quiet,
[string] $OutputVariable,
[switch] $AssumeElevated
) )
$selectedArch=$null; $selectedArch=$null;
$defaultArch="x86" $defaultArch="x86"
$selectedRuntime=$null $selectedRuntime=$null
$defaultRuntime="CLR" $defaultRuntime="CLR"
$userKrePath = $env:USERPROFILE + "\.kre"
# Get or calculate userKrePath
$userKrePath = $env:USER_KRE_PATH
if(!$userKrePath) { $userKrePath = $env:USERPROFILE + "\.kre" }
$userKrePackages = $userKrePath + "\packages" $userKrePackages = $userKrePath + "\packages"
$globalKrePath = $env:ProgramFiles + "\KRE"
# Get or calculate globalKrePath
$globalKrePath = $env:GLOBAL_KRE_PATH
if(!$globalKrePath) { $globalKrePath = $env:ProgramFiles + "\KRE" }
$globalKrePackages = $globalKrePath + "\packages" $globalKrePackages = $globalKrePath + "\packages"
$feed = $env:KRE_NUGET_API_URL $feed = $env:KRE_FEED
# In some environments, like Azure Websites, the Write-* cmdlets don't work
$useHostOutputMethods = $true
function String-IsEmptyOrWhitespace([string]$str) { function String-IsEmptyOrWhitespace([string]$str) {
return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0 return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0
@ -41,37 +55,41 @@ if (!$feed)
$feed = "https://www.myget.org/F/aspnetvnext/api/v2"; $feed = "https://www.myget.org/F/aspnetvnext/api/v2";
} }
$feed = $feed.TrimEnd("/")
$scriptPath = $myInvocation.MyCommand.Definition $scriptPath = $myInvocation.MyCommand.Definition
function Kvm-Help { function Kvm-Help {
@" @"
K Runtime Environment Version Manager - Build 10017 K Runtime Environment Version Manager - Build 10058
USAGE: kvm <command> [options] USAGE: kvm <command> [options]
kvm upgrade [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-g|-global] [-f|-force] [-proxy <ADDRESS>] kvm upgrade [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-g|-Global] [-f|-Force] [-Proxy <ADDRESS>] [-NoNative]
install latest KRE from feed install latest KRE from feed
set 'default' alias to installed version set 'default' alias to installed version
add KRE bin to user PATH environment variable add KRE bin to user PATH environment variable
-g|-global install to machine-wide location -g|-Global install to machine-wide location
-f|-force upgrade even if latest is already installed -f|-Force upgrade even if latest is already installed
-proxy <ADDRESS> use given address as proxy when accessing remote server -Proxy <ADDRESS> use given address as proxy when accessing remote server
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
kvm install <semver>|<alias>|<nupkg>|latest [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-a|-alias <alias>] [-g|-global] [-f|-force] kvm install <semver>|<alias>|<nupkg>|latest [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-a|-Alias <alias>] [-g|-Global] [-f|-Force] [-NoNative]
<semver>|<alias> install requested KRE from feed <semver>|<alias> install requested KRE from feed
<nupkg> install requested KRE from package on local filesystem <nupkg> install requested KRE from package on local filesystem
latest install latest KRE from feed latest install latest KRE from feed
add KRE bin to path of current command line add KRE bin to path of current command line
-p|-persistent add KRE bin to PATH environment variables persistently -p|-Persistent add KRE bin to PATH environment variables persistently
-a|-alias <alias> set alias <alias> for requested KRE on install -a|-Alias <alias> set alias <alias> for requested KRE on install
-g|-global install to machine-wide location -g|-Global install to machine-wide location
-f|-force install even if specified version is already installed -f|-Force install even if specified version is already installed
-NoNative Do not generate native images (Effective only for CoreCLR flavors)
kvm use <semver>|<alias>|none [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-p|-persistent] [-g|-global] kvm use <semver>|<alias>|<package>|none [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR] [-p|-Persistent] [-g|-Global]
<semver>|<alias> add KRE bin to path of current command line <semver>|<alias>|<package> add KRE bin to path of current command line
none remove KRE bin from path of current command line none remove KRE bin from path of current command line
-p|-persistent add KRE bin to PATH environment variables persistently -p|-Persistent add KRE bin to PATH environment variables persistently
-g|-global combined with -p to change machine PATH instead of user PATH -g|-Global combined with -p to change machine PATH instead of user PATH
kvm list kvm list
list KRE versions installed list KRE versions installed
@ -82,14 +100,14 @@ kvm alias
kvm alias <alias> kvm alias <alias>
display value of the specified alias display value of the specified alias
kvm alias <alias> <semver>|<alias> [-x86][-amd64] [-r|-runtime CLR|CoreCLR] kvm alias <alias> <semver>|<alias>|<package> [-X86][-Amd64] [-r|-Runtime CLR|CoreCLR]
<alias> The name of the alias to set <alias> the name of the alias to set
<semver>|<alias> The KRE version to set the alias to. Alternatively use the version of the specified alias <semver>|<alias>|<package> the KRE version to set the alias to. Alternatively use the version of the specified alias
kvm unalias <alias> kvm unalias <alias>
remove the specified alias remove the specified alias
"@ -replace "`n","`r`n" | Write-Host "@ -replace "`n","`r`n" | Console-Write
} }
function Kvm-Global-Setup { function Kvm-Global-Setup {
@ -99,76 +117,66 @@ function Kvm-Global-Setup {
{ {
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -wait" $arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Write-Host "Adding $kvmBinPath to process PATH" Console-Write "Adding $kvmBinPath to process PATH"
Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath)) Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath))
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME" Console-Write "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
$envKreHome = $env:KRE_HOME $envKreHome = $env:KRE_HOME
$envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre") $envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
$envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath) $envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath)
$env:KRE_HOME = $envKreHome $env:KRE_HOME = $envKreHome
Write-Host "Setup complete" Console-Write "Setup complete"
break break
} }
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath) $scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
Write-Host "Copying file $kvmBinPath\kvm.ps1" Console-Write "Copying file $kvmBinPath\kvm.ps1"
md $kvmBinPath -Force | Out-Null md $kvmBinPath -Force | Out-Null
copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1" copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1"
Write-Host "Copying file $kvmBinPath\kvm.cmd" Console-Write "Copying file $kvmBinPath\kvm.cmd"
copy "$scriptFolder\kvm.cmd" "$kvmBinPath\kvm.cmd" copy "$scriptFolder\kvm.cmd" "$kvmBinPath\kvm.cmd"
Write-Host "Adding $kvmBinPath to process PATH" Console-Write "Adding $kvmBinPath to process PATH"
Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath)) Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath))
Write-Host "Adding $kvmBinPath to user PATH" Console-Write "Adding $kvmBinPath to user PATH"
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$userPath = Change-Path $userPath $kvmBinPath ($kvmBinPath) $userPath = Change-Path $userPath $kvmBinPath ($kvmBinPath)
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User) [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME" Console-Write "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
$envKreHome = $env:KRE_HOME $envKreHome = $env:KRE_HOME
$envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre") $envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
$envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath) $envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath)
$env:KRE_HOME = $envKreHome $env:KRE_HOME = $envKreHome
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to machine KRE_HOME" Console-Write "Adding $globalKrePath;%USERPROFILE%\.kre to machine KRE_HOME"
$machineKreHome = [Environment]::GetEnvironmentVariable("KRE_HOME", [System.EnvironmentVariableTarget]::Machine) $machineKreHome = [Environment]::GetEnvironmentVariable("KRE_HOME", [System.EnvironmentVariableTarget]::Machine)
$machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre") $machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
$machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath) $machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath)
[Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine)
} }
function Kvm-Global-Upgrade {
$persistent = $true
$alias="default"
$versionOrAlias = Kvm-Find-Latest $selectedRuntime $selectedArch
If (Needs-Elevation) {
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
Kvm-Set-Global-Process-Path $versionOrAlias
break
}
Kvm-Install $versionOrAlias $true
}
function Kvm-Upgrade { function Kvm-Upgrade {
$persistent = $true param(
$alias="default" [boolean] $isGlobal
Kvm-Install "latest" $false )
$Persistent = $true
$Alias="default"
Kvm-Install "latest" $isGlobal
} }
function Add-Proxy-If-Specified { function Add-Proxy-If-Specified {
param( param(
[System.Net.WebClient] $wc [System.Net.WebClient] $wc
) )
if (!$proxy) { if (!$Proxy) {
$proxy = $env:http_proxy $Proxy = $env:http_proxy
} }
if ($proxy) { if ($Proxy) {
$wp = New-Object System.Net.WebProxy($proxy) $wp = New-Object System.Net.WebProxy($Proxy)
$pb = New-Object UriBuilder($proxy) $pb = New-Object UriBuilder($Proxy)
if (!$pb.UserName) { if (!$pb.UserName) {
$wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials $wp.Credentials = [System.Net.CredentialCache]::DefaultCredentials
} else { } else {
@ -183,12 +191,11 @@ param(
[string] $platform, [string] $platform,
[string] $architecture [string] $architecture
) )
Write-Host "Determining latest version" Console-Write "Determining latest version"
$url = "$feed/GetUpdates()?packageIds=%27KRE-$platform-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false" $url = "$feed/GetUpdates()?packageIds=%27KRE-$platform-$architecture%27&versions=%270.0%27&includePrerelease=true&includeAllVersions=false"
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
Add-Proxy-If-Specified($wc) Add-Proxy-If-Specified($wc)
[xml]$xml = $wc.DownloadString($url) [xml]$xml = $wc.DownloadString($url)
@ -213,16 +220,16 @@ param(
$kreFile = Join-Path $kreFolder "$kreFullName.nupkg" $kreFile = Join-Path $kreFolder "$kreFullName.nupkg"
If (Test-Path $kreFolder) { If (Test-Path $kreFolder) {
if($force) if($Force)
{ {
rm $kreFolder -Recurse -Force rm $kreFolder -Recurse -Force
} else { } else {
Write-Host "$kreFullName already installed." Console-Write "$kreFullName already installed."
return; return;
} }
} }
Write-Host "Downloading" $kreFullName "from $feed" Console-Write "Downloading $kreFullName from $feed"
#Downloading to temp location #Downloading to temp location
$kreTempDownload = Join-Path $packagesFolder "temp" $kreTempDownload = Join-Path $packagesFolder "temp"
@ -235,14 +242,13 @@ param(
} }
$wc = New-Object System.Net.WebClient $wc = New-Object System.Net.WebClient
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
Add-Proxy-If-Specified($wc) Add-Proxy-If-Specified($wc)
$wc.DownloadFile($url, $tempKreFile) $wc.DownloadFile($url, $tempKreFile)
Do-Kvm-Unpack $tempKreFile $kreTempDownload Do-Kvm-Unpack $tempKreFile $kreTempDownload
md $kreFolder -Force | Out-Null md $kreFolder -Force | Out-Null
Write-Host "Installing to $kreFolder" Console-Write "Installing to $kreFolder"
mv "$kreTempDownload\*" $kreFolder mv "$kreTempDownload\*" $kreFolder
Remove-Item "$kreTempDownload" -Force | Out-Null Remove-Item "$kreTempDownload" -Force | Out-Null
} }
@ -252,20 +258,27 @@ param(
[string] $kreFile, [string] $kreFile,
[string] $kreFolder [string] $kreFolder
) )
Write-Host "Unpacking to" $kreFolder Console-Write "Unpacking to $kreFolder"
try {
#Shell will not recognize nupkg as a zip and throw, so rename it to zip $compressionLib = [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem')
$kreZip = [System.IO.Path]::ChangeExtension($kreFile, "zip")
Rename-Item $kreFile $kreZip if($compressionLib -eq $null) {
#Use the shell to uncompress the nupkg try {
$shell_app=new-object -com shell.application # Shell will not recognize nupkg as a zip and throw, so rename it to zip
$zip_file = $shell_app.namespace($kreZip) $kreZip = [System.IO.Path]::ChangeExtension($kreFile, "zip")
$destination = $shell_app.namespace($kreFolder) Rename-Item $kreFile $kreZip
$destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files # Use the shell to uncompress the nupkg
} $shell_app=new-object -com shell.application
finally { $zip_file = $shell_app.namespace($kreZip)
#make it a nupkg again $destination = $shell_app.namespace($kreFolder)
Rename-Item $kreZip $kreFile $destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
}
finally {
# make it a nupkg again
Rename-Item $kreZip $kreFile
}
} else {
[System.IO.Compression.ZipFile]::ExtractToDirectory($kreFile, $kreFolder)
} }
If (Test-Path ($kreFolder + "\[Content_Types].xml")) { If (Test-Path ($kreFolder + "\[Content_Types].xml")) {
@ -313,13 +326,13 @@ param(
$kreFolder = "$packageFolder\$kreFullName" $kreFolder = "$packageFolder\$kreFullName"
$folderExists = Test-Path $kreFolder $folderExists = Test-Path $kreFolder
if ($folderExists -and $force) { if ($folderExists -and $Force) {
del $kreFolder -Recurse -Force del $kreFolder -Recurse -Force
$folderExists = $false; $folderExists = $false;
} }
if ($folderExists) { if ($folderExists) {
Write-Host "Target folder '$kreFolder' already exists" Console-Write "Target folder '$kreFolder' already exists"
} else { } else {
$tempUnpackFolder = Join-Path $packageFolder "temp" $tempUnpackFolder = Join-Path $packageFolder "temp"
$tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg" $tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg"
@ -333,7 +346,7 @@ param(
Do-Kvm-Unpack $tempKreFile $tempUnpackFolder Do-Kvm-Unpack $tempKreFile $tempUnpackFolder
md $kreFolder -Force | Out-Null md $kreFolder -Force | Out-Null
Write-Host "Installing to $kreFolder" Console-Write "Installing to $kreFolder"
mv "$tempUnpackFolder\*" $kreFolder mv "$tempUnpackFolder\*" $kreFolder
Remove-Item "$tempUnpackFolder" -Force | Out-Null Remove-Item "$tempUnpackFolder" -Force | Out-Null
} }
@ -341,16 +354,27 @@ param(
$packageVersion = Package-Version $kreFullName $packageVersion = Package-Version $kreFullName
Kvm-Use $packageVersion Kvm-Use $packageVersion
if (!$(String-IsEmptyOrWhitespace($alias))) { if (!$(String-IsEmptyOrWhitespace($Alias))) {
Kvm-Alias-Set $alias $packageVersion Kvm-Alias-Set $Alias $packageVersion
} }
} }
else else
{ {
Do-Kvm-Download $kreFullName $packageFolder Do-Kvm-Download $kreFullName $packageFolder
Kvm-Use $versionOrAlias Kvm-Use $versionOrAlias
if (!$(String-IsEmptyOrWhitespace($alias))) { if (!$(String-IsEmptyOrWhitespace($Alias))) {
Kvm-Alias-Set "$alias" $versionOrAlias Kvm-Alias-Set "$Alias" $versionOrAlias
}
}
if ($kreFullName.Contains("CoreCLR")) {
if ($NoNative) {
Console-Write "Native image generation is skipped"
}
else {
Console-Write "Compiling native images for $kreFullName to improve startup performance..."
Start-Process "k-crossgen" -Wait
Console-Write "Finished native image compilation."
} }
} }
} }
@ -384,7 +408,10 @@ filter List-Parts {
} }
$active = $false $active = $false
foreach($portion in $env:Path.Split(';')) { foreach($portion in $env:Path.Split(';')) {
if ($portion.StartsWith($_.FullName)) { # Append \ to the end because otherwise you might see
# multiple active versions if the folders have the same
# name prefix (like 1.0-beta and 1.0)
if ($portion.StartsWith($_.FullName + "\")) {
$active = $true $active = $true
} }
} }
@ -393,7 +420,7 @@ filter List-Parts {
$delim="" $delim=""
foreach($alias in $aliases){ foreach($alias in $aliases){
if($_.Name.Split('\', 2).Contains($alias.Name)){ if($_.Name.Split('\', 2) -contains $alias.Name){
$fullAlias += $delim + $alias.Alias $fullAlias += $delim + $alias.Alias
$delim = ", " $delim = ", "
} }
@ -415,6 +442,8 @@ function Kvm-Global-Use {
param( param(
[string] $versionOrAlias [string] $versionOrAlias
) )
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
If (Needs-Elevation) { If (Needs-Elevation) {
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' use '$versionOrAlias' -global $(Requested-Switches) -wait" $arguments = "-ExecutionPolicy unrestricted & '$scriptPath' use '$versionOrAlias' -global $(Requested-Switches) -wait"
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
@ -425,8 +454,8 @@ param(
Kvm-Set-Global-Process-Path "$versionOrAlias" Kvm-Set-Global-Process-Path "$versionOrAlias"
if ($versionOrAlias -eq "none") { if ($versionOrAlias -eq "none") {
if ($persistent) { if ($Persistent) {
Write-Host "Removing KRE from machine PATH" Console-Write "Removing KRE from machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) $machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$machinePath = Change-Path $machinePath "" ($globalKrePackages, $userKrePackages) $machinePath = Change-Path $machinePath "" ($globalKrePackages, $userKrePackages)
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
@ -437,12 +466,11 @@ param(
$kreFullName = Requested-VersionOrAlias "$versionOrAlias" $kreFullName = Requested-VersionOrAlias "$versionOrAlias"
$kreBin = Locate-KreBinFromFullName $kreFullName $kreBin = Locate-KreBinFromFullName $kreFullName
if ($kreBin -eq $null) { if ($kreBin -eq $null) {
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?" throw "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
return
} }
if ($persistent) { if ($Persistent) {
Write-Host "Adding $kreBin to machine PATH" Console-Write "Adding $kreBin to machine PATH"
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine) $machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$machinePath = Change-Path $machinePath $kreBin ($globalKrePackages, $userKrePackages) $machinePath = Change-Path $machinePath $kreBin ($globalKrePackages, $userKrePackages)
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
@ -454,7 +482,7 @@ param(
[string] $versionOrAlias [string] $versionOrAlias
) )
if ($versionOrAlias -eq "none") { if ($versionOrAlias -eq "none") {
Write-Host "Removing KRE from process PATH" Console-Write "Removing KRE from process PATH"
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages)) Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
return return
} }
@ -462,11 +490,11 @@ param(
$kreFullName = Requested-VersionOrAlias $versionOrAlias $kreFullName = Requested-VersionOrAlias $versionOrAlias
$kreBin = Locate-KreBinFromFullName $kreFullName $kreBin = Locate-KreBinFromFullName $kreFullName
if ($kreBin -eq $null) { if ($kreBin -eq $null) {
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?" Console-Write "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
return return
} }
Write-Host "Adding" $kreBin "to process PATH" Console-Write "Adding $kreBin to process PATH"
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages)) Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
} }
@ -474,12 +502,14 @@ function Kvm-Use {
param( param(
[string] $versionOrAlias [string] $versionOrAlias
) )
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
if ($versionOrAlias -eq "none") { if ($versionOrAlias -eq "none") {
Write-Host "Removing KRE from process PATH" Console-Write "Removing KRE from process PATH"
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages)) Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
if ($persistent) { if ($Persistent) {
Write-Host "Removing KRE from user PATH" Console-Write "Removing KRE from user PATH"
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$userPath = Change-Path $userPath "" ($globalKrePackages, $userKrePackages) $userPath = Change-Path $userPath "" ($globalKrePackages, $userKrePackages)
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User) [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
@ -491,15 +521,14 @@ param(
$kreBin = Locate-KreBinFromFullName $kreFullName $kreBin = Locate-KreBinFromFullName $kreFullName
if ($kreBin -eq $null) { if ($kreBin -eq $null) {
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?" throw "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
return
} }
Write-Host "Adding" $kreBin "to process PATH" Console-Write "Adding $kreBin to process PATH"
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages)) Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
if ($persistent) { if ($Persistent) {
Write-Host "Adding $kreBin to user PATH" Console-Write "Adding $kreBin to user PATH"
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) $userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
$userPath = Change-Path $userPath $kreBin ($globalKrePackages, $userKrePackages) $userPath = Change-Path $userPath $kreBin ($globalKrePackages, $userKrePackages)
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User) [Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
@ -519,9 +548,11 @@ param(
md ($userKrePath + "\alias\") -Force | Out-Null md ($userKrePath + "\alias\") -Force | Out-Null
$aliasFilePath=$userKrePath + "\alias\" + $name + ".txt" $aliasFilePath=$userKrePath + "\alias\" + $name + ".txt"
if (!(Test-Path $aliasFilePath)) { if (!(Test-Path $aliasFilePath)) {
Write-Host "Alias '$name' does not exist" Console-Write "Alias '$name' does not exist"
$script:exitCode = 1 # Return non-zero exit code for scripting
} else { } else {
Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt")) $aliasValue = (Get-Content ($userKrePath + "\alias\" + $name + ".txt"))
Console-Write "Alias '$name' is set to $aliasValue"
} }
} }
@ -533,7 +564,7 @@ param(
$kreFullName = Requested-VersionOrAlias $value $kreFullName = Requested-VersionOrAlias $value
$aliasFilePath = $userKrePath + "\alias\" + $name + ".txt" $aliasFilePath = $userKrePath + "\alias\" + $name + ".txt"
$action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" } $action = if (Test-Path $aliasFilePath) { "Updating" } else { "Setting" }
Write-Host "$action alias '$name' to '$kreFullName'" Console-Write "$action alias '$name' to '$kreFullName'"
md ($userKrePath + "\alias\") -Force | Out-Null md ($userKrePath + "\alias\") -Force | Out-Null
$kreFullName | Out-File ($aliasFilePath) ascii $kreFullName | Out-File ($aliasFilePath) ascii
} }
@ -544,10 +575,11 @@ param(
) )
$aliasPath=$userKrePath + "\alias\" + $name + ".txt" $aliasPath=$userKrePath + "\alias\" + $name + ".txt"
if (Test-Path -literalPath "$aliasPath") { if (Test-Path -literalPath "$aliasPath") {
Write-Host "Removing alias $name" Console-Write "Removing alias $name"
Remove-Item -literalPath $aliasPath Remove-Item -literalPath $aliasPath
} else { } else {
Write-Host "Cannot remove alias, '$name' is not a valid alias name" Console-Write "Cannot remove alias, '$name' is not a valid alias name"
$script:exitCode = 1 # Return non-zero exit code for scripting
} }
} }
@ -595,6 +627,15 @@ function Requested-VersionOrAlias() {
param( param(
[string] $versionOrAlias [string] $versionOrAlias
) )
Validate-Full-Package-Name-Arguments-Combination $versionOrAlias
$kreBin = Locate-KreBinFromFullName $versionOrAlias
# If the name specified is an existing package, just use it as is
if ($kreBin -ne $null) {
return $versionOrAlias
}
If (Test-Path ($userKrePath + "\alias\" + $versionOrAlias + ".txt")) { If (Test-Path ($userKrePath + "\alias\" + $versionOrAlias + ".txt")) {
$aliasValue = Get-Content ($userKrePath + "\alias\" + $versionOrAlias + ".txt") $aliasValue = Get-Content ($userKrePath + "\alias\" + $versionOrAlias + ".txt")
$parts = $aliasValue.Split('.', 2) $parts = $aliasValue.Split('.', 2)
@ -659,6 +700,10 @@ SET "PATH=$newPath"
} }
function Needs-Elevation() { function Needs-Elevation() {
if($AssumeElevated) {
return $false
}
$user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() $user = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
$elevated = $user.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator") $elevated = $user.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
return -NOT $elevated return -NOT $elevated
@ -666,69 +711,135 @@ function Needs-Elevation() {
function Requested-Switches() { function Requested-Switches() {
$arguments = "" $arguments = ""
if ($x86) {$arguments = "$arguments -x86"} if ($X86) {$arguments = "$arguments -x86"}
if ($amd64) {$arguments = "$arguments -amd64"} if ($Amd64) {$arguments = "$arguments -amd64"}
#deprecated #deprecated
if ($x64) {$arguments = "$arguments -x64"} if ($X64) {$arguments = "$arguments -x64"}
if ($selectedRuntime) {$arguments = "$arguments -runtime $selectedRuntime"} if ($selectedRuntime) {$arguments = "$arguments -runtime $selectedRuntime"}
if ($persistent) {$arguments = "$arguments -persistent"} if ($Persistent) {$arguments = "$arguments -persistent"}
if ($force) {$arguments = "$arguments -force"} if ($Force) {$arguments = "$arguments -force"}
if (!$(String-IsEmptyOrWhitespace($alias))) {$arguments = "$arguments -alias '$alias'"} if (!$(String-IsEmptyOrWhitespace($Alias))) {$arguments = "$arguments -alias '$Alias'"}
return $arguments return $arguments
} }
function Validate-And-Santitise-Switches() function Validate-And-Santitize-Switches()
{ {
if ($svr50 -and $runtime) {throw "You cannot select both the -runtime switch and the -svr50 runtimes"} if ($Svr50 -and $Runtime) {throw "You cannot select both the -runtime switch and the -svr50 runtimes"}
if ($svrc50 -and $runtime) {throw "You cannot select both the -runtime switch and the -svrc50 runtimes"} if ($Svrc50 -and $Runtime) {throw "You cannot select both the -runtime switch and the -svrc50 runtimes"}
if ($x86 -and $amd64) {throw "You cannot select both x86 and amd64 architectures"} if ($X86 -and $Amd64) {throw "You cannot select both x86 and amd64 architectures"}
if ($x86 -and $x64) {throw "You cannot select both x86 and x64 architectures"} if ($X86 -and $X64) {throw "You cannot select both x86 and x64 architectures"}
if ($x64 -and $amd64) {throw "You cannot select both x64 and amd64 architectures"} if ($X64 -and $Amd64) {throw "You cannot select both x64 and amd64 architectures"}
if ($runtime) { if ($Runtime) {
$validRuntimes = "CoreCLR", "CLR", "svr50", "svrc50" $validRuntimes = "CoreCLR", "CLR", "svr50", "svrc50"
$match = $validRuntimes | ? { $_ -like $runtime } | Select -First 1 $match = $validRuntimes | ? { $_ -like $Runtime } | Select -First 1
if (!$match) {throw "'$runtime' is not a valid runtime"} if (!$match) {throw "'$runtime' is not a valid runtime"}
Set-Variable -Name "selectedRuntime" -Value $match -Scope Script Set-Variable -Name "selectedRuntime" -Value $match -Scope Script
} elseif ($svr50) { } elseif ($Svr50) {
Write-Host "Warning: -svr50 is deprecated, use -runtime CLR for new packages." Console-Write "Warning: -svr50 is deprecated, use -runtime CLR for new packages."
Set-Variable -Name "selectedRuntime" -Value "svr50" -Scope Script Set-Variable -Name "selectedRuntime" -Value "svr50" -Scope Script
} elseif ($svrc50) { } elseif ($Svrc50) {
Write-Host "Warning: -svrc50 is deprecated, use -runtime CoreCLR for new packages." Console-Write "Warning: -svrc50 is deprecated, use -runtime CoreCLR for new packages."
Set-Variable -Name "selectedRuntime" -Value "svrc50" -Scope Script Set-Variable -Name "selectedRuntime" -Value "svrc50" -Scope Script
} }
if ($x64) { if($Architecture) {
Write-Host "Warning: -x64 is deprecated, use -amd64 for new packages." $validArchitectures = "amd64", "x86"
Set-Variable -Name "selectedArch" -Value "x64" -Scope Script $match = $validArchitectures | ? { $_ -like $Architecture } | Select -First 1
} elseif ($amd64) { if(!$match) {throw "'$architecture' is not a valid architecture"}
Set-Variable -Name "selectedArch" -Value "amd64" -Scope Script Set-Variable -Name "selectedArch" -Value $match -Scope Script
} elseif ($x86) { }
Set-Variable -Name "selectedArch" -Value "x86" -Scope Script else {
if ($X64) {
Console-Write "Warning: -x64 is deprecated, use -amd64 for new packages."
Set-Variable -Name "selectedArch" -Value "x64" -Scope Script
} elseif ($Amd64) {
Set-Variable -Name "selectedArch" -Value "amd64" -Scope Script
} elseif ($X86) {
Set-Variable -Name "selectedArch" -Value "x86" -Scope Script
}
}
}
$script:capturedOut = @()
function Console-Write() {
param(
[Parameter(ValueFromPipeline=$true)]
[string] $message
)
if($OutputVariable) {
# Update the capture output
$script:capturedOut += @($message)
}
if(!$Quiet) {
if ($useHostOutputMethods) {
try {
Write-Host $message
}
catch {
$script:useHostOutputMethods = $false
Console-Write $message
}
}
else {
[Console]::WriteLine($message)
}
} }
} }
function Console-Write-Error() {
param(
[Parameter(ValueFromPipeline=$true)]
[string] $message
)
if ($useHostOutputMethods) {
try {
Write-Error $message
}
catch {
$script:useHostOutputMethods = $false
Console-Write-Error $message
}
}
else {
[Console]::Error.WriteLine($message)
}
}
function Validate-Full-Package-Name-Arguments-Combination() {
param(
[string] $versionOrAlias
)
if ($versionOrAlias -like "KRE-*" -and
($selectedArch -or $selectedRuntime)) {
throw "Runtime or architecture cannot be specified when using the full package name."
}
}
$script:exitCode = 0
try { try {
Validate-And-Santitise-Switches Validate-And-Santitize-Switches
if ($global) { if ($Global) {
switch -wildcard ($command + " " + $args.Count) { switch -wildcard ($Command + " " + $Args.Count) {
"setup 0" {Kvm-Global-Setup} "setup 0" {Kvm-Global-Setup}
"upgrade 0" {Kvm-Global-Upgrade} "upgrade 0" {Kvm-Upgrade $true}
"install 1" {Kvm-Install $args[0] $true} "install 1" {Kvm-Install $Args[0] $true}
"use 1" {Kvm-Global-Use $args[0]} "use 1" {Kvm-Global-Use $Args[0]}
default {throw "Unknown command, or global switch not supported"}; default {throw "Unknown command, or global switch not supported"};
} }
} else { } else {
switch -wildcard ($command + " " + $args.Count) { switch -wildcard ($Command + " " + $Args.Count) {
"setup 0" {Kvm-Global-Setup} "setup 0" {Kvm-Global-Setup}
"upgrade 0" {Kvm-Upgrade} "upgrade 0" {Kvm-Upgrade $false}
"install 1" {Kvm-Install $args[0] $false} "install 1" {Kvm-Install $Args[0] $false}
"list 0" {Kvm-List} "list 0" {Kvm-List}
"use 1" {Kvm-Use $args[0]} "use 1" {Kvm-Use $Args[0]}
"alias 0" {Kvm-Alias-List} "alias 0" {Kvm-Alias-List}
"alias 1" {Kvm-Alias-Get $args[0]} "alias 1" {Kvm-Alias-Get $Args[0]}
"alias 2" {Kvm-Alias-Set $args[0] $args[1]} "alias 2" {Kvm-Alias-Set $Args[0] $Args[1]}
"unalias 1" {Kvm-Unalias $args[0]} "unalias 1" {Kvm-Unalias $Args[0]}
"help 0" {Kvm-Help} "help 0" {Kvm-Help}
" 0" {Kvm-Help} " 0" {Kvm-Help}
default {throw "Unknown command"}; default {throw "Unknown command"};
@ -736,10 +847,18 @@ try {
} }
} }
catch { catch {
Write-Host $_ -ForegroundColor Red ; Console-Write-Error $_
Write-Host "Type 'kvm help' for help on how to use kvm." Console-Write "Type 'kvm help' for help on how to use kvm."
$script:exitCode = -1
} }
if ($wait) { if ($Wait) {
Write-Host "Press any key to continue ..." Console-Write "Press any key to continue ..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC") $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
} }
# If the user specified an output variable, push the value up to the parent scope
if($OutputVariable) {
Set-Variable $OutputVariable $script:capturedOut -Scope 1
}
exit $script:exitCode

71
kvm.sh
View File

@ -83,13 +83,13 @@ _kvm_download() {
mkdir -p "$kreFolder" > /dev/null 2>&1 mkdir -p "$kreFolder" > /dev/null 2>&1
local httpResult=$(curl -L -D - -u aspnetreadonly:4d8a2d9c-7b80-4162-9978-47e918c9658c "$url" -o "$kreFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/") local httpResult=$(curl -L -D - "$url" -o "$kreFile" 2>/dev/null | grep "^HTTP/1.1" | head -n 1 | sed "s/HTTP.1.1 \([0-9]*\).*/\1/")
[[ $httpResult == "404" ]] && echo "$kreFullName was not found in repository $KRE_FEED" && return 1 [[ $httpResult == "404" ]] && echo "$kreFullName was not found in repository $KRE_FEED" && return 1
[[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $kreFullName from $KRE_FEED" && return 1 [[ $httpResult != "302" && $httpResult != "200" ]] && echo "HTTP Error $httpResult fetching $kreFullName from $KRE_FEED" && return 1
_kvm_unpack $kreFile $kreFolder _kvm_unpack $kreFile $kreFolder
return $? return $?
} }
_kvm_unpack() { _kvm_unpack() {
@ -118,18 +118,24 @@ _kvm_unpack() {
_kvm_requested_version_or_alias() { _kvm_requested_version_or_alias() {
local versionOrAlias="$1" local versionOrAlias="$1"
local kreBin=$(_kvm_locate_kre_bin_from_full_name "$versionOrAlias")
# If the name specified is an existing package, just use it as is
if [ -n "$kreBin" ]; then
echo "$versionOrAlias"
else
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=$(echo "$pkgName" | sed "s/KRE-\([^.-]*\).*/\1/")
else
local pkgVersion=$versionOrAlias
local pkgPlatform="Mono"
fi
if [ -e "$KRE_USER_HOME/alias/$versionOrAlias.alias" ]; then echo "KRE-$pkgPlatform.$pkgVersion"
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=$(echo "$pkgName" | sed "s/KRE-\([^.-]*\).*/\1/")
else
local pkgVersion=$versionOrAlias
local pkgPlatform="Mono"
fi fi
echo "KRE-$pkgPlatform.$pkgVersion"
} }
# This will be more relevant if we support global installs # This will be more relevant if we support global installs
@ -148,7 +154,7 @@ kvm()
case $1 in case $1 in
"help" ) "help" )
echo "" echo ""
echo "K Runtime Environment Version Manager - Build 10017" echo "K Runtime Environment Version Manager - Build 10058"
echo "" echo ""
echo "USAGE: kvm <command> [options]" echo "USAGE: kvm <command> [options]"
echo "" echo ""
@ -165,10 +171,10 @@ kvm()
echo "-p -persistent set installed version as default" echo "-p -persistent set installed version as default"
echo "add KRE bin to path of current command line" echo "add KRE bin to path of current command line"
echo "" echo ""
echo "kvm use <semver>|<alias>|none [-p -persistent]" echo "kvm use <semver>|<alias>|<package>|none [-p -persistent]"
echo "<semver>|<alias> add KRE bin to path of current command line " echo "<semver>|<alias>|<package> add KRE bin to path of current command line "
echo "none remove KRE bin from path of current command line" echo "none remove KRE bin from path of current command line"
echo "-p -persistent set selected version as default" echo "-p -persistent set selected version as default"
echo "" echo ""
echo "kvm list" echo "kvm list"
echo "list KRE versions installed " echo "list KRE versions installed "
@ -179,9 +185,9 @@ kvm()
echo "kvm alias <alias>" echo "kvm alias <alias>"
echo "display value of the specified alias" echo "display value of the specified alias"
echo "" echo ""
echo "kvm alias <alias> <semver>" echo "kvm alias <alias> <semver>|<alias>|<package>"
echo "<alias> The name of the alias to set" echo "<alias> the name of the alias to set"
echo "<semver>|<alias> The KRE version to set the alias to. Alternatively use the version of the specified alias" echo "<semver>|<alias>|<package> the KRE version to set the alias to. Alternatively use the version of the specified alias"
echo "" echo ""
echo "kvm unalias <alias>" echo "kvm unalias <alias>"
echo "remove the specified alias" echo "remove the specified alias"
@ -328,10 +334,10 @@ kvm()
echo "$action alias '$name' to '$kreFullName'" echo "$action alias '$name' to '$kreFullName'"
echo "$kreFullName" > "$KRE_USER_HOME/alias/$name.alias" echo "$kreFullName" > "$KRE_USER_HOME/alias/$name.alias"
;; ;;
"unalias" ) "unalias" )
[[ $# -ne 2 ]] && kvm help && return [[ $# -ne 2 ]] && kvm help && return
local name=$2 local name=$2
local aliasPath="$KRE_USER_HOME/alias/$name.alias" local aliasPath="$KRE_USER_HOME/alias/$name.alias"
[[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1 [[ ! -e "$aliasPath" ]] && echo "Cannot remove alias, '$name' is not a valid alias name" && return 1
@ -350,21 +356,26 @@ kvm()
local searchGlob=$(_kvm_requested_version_or_alias "$versionOrAlias") local searchGlob=$(_kvm_requested_version_or_alias "$versionOrAlias")
fi fi
echo "" echo ""
local arr=() # Separate empty array declaration from initialization
local i=0 # to avoid potential ZSH error: local:217: maximum nested function level reached
local arr
arr=()
# Z shell array-index starts at one.
local i=1
local format="%-20s %s\n" local format="%-20s %s\n"
for _kvm_file in $(find "$KRE_USER_HOME/alias" -name *.alias); do for _kvm_file in $(find "$KRE_USER_HOME/alias" -name *.alias); do
arr[$i]="$(basename $_kvm_file | sed 's/.alias//')/$(cat $_kvm_file)" arr[$i]="$(basename $_kvm_file | sed 's/.alias//')/$(cat $_kvm_file)"
let i+=1 let i+=1
done done
local formatString="%-6s %-20s %-7s %-20s %s\n" local formatString="%-6s %-20s %-7s %-20s %s\n"
printf "$formatString" "Active" "Version" "Runtime" "Location" "Alias" printf "$formatString" "Active" "Version" "Runtime" "Location" "Alias"
printf "$formatString" "------" "-------" "-------" "--------" "-----" printf "$formatString" "------" "-------" "-------" "--------" "-----"
local formattedHome=`(echo $KRE_USER_PACKAGES | sed s=$HOME=~=g)` 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 for f in $(find $KRE_USER_PACKAGES -name "$searchGlob" \( -type d -or -type l \) -prune -exec basename {} \;); do
local active="" local active=""
[[ $PATH == *"$KRE_USER_PACKAGES/$f/bin"* ]] && local active=" *" [[ $PATH == *"$KRE_USER_PACKAGES/$f/bin"* ]] && local active=" *"
local pkgName=$(_kvm_package_runtime "$f") local pkgName=$(_kvm_package_runtime "$f")
@ -372,7 +383,7 @@ kvm()
local alias="" local alias=""
local delim="" local delim=""
for i in "${arr[@]}"; do for i in "${arr[@]}"; do
temp="KRE-$pkgName.$pkgVersion" temp="KRE-$pkgName.$pkgVersion"
temp2="KRE-$pkgName-x86.$pkgVersion" temp2="KRE-$pkgName-x86.$pkgVersion"
if [[ ${i#*/} == $temp || ${i#*/} == $temp2 ]]; then if [[ ${i#*/} == $temp || ${i#*/} == $temp2 ]]; then
@ -393,7 +404,7 @@ kvm()
echo "Unknown command $1" echo "Unknown command $1"
return 1 return 1
esac esac
return 0 return 0
} }