Updating the home repo with the latest KVM scripts
This commit is contained in:
parent
fcc3ae5e03
commit
07424caead
|
|
@ -85,7 +85,7 @@ The samples in this repo are basic starting points for you to experiment with.
|
||||||
|
|
||||||
By default when running ASP.NET vNext applications on the Windows platform you are running on the full .NET Framework. You can switch to use the new Cloud Optimized runtime, or Core CLR, using the KVM command.
|
By default when running ASP.NET vNext applications on the Windows platform you are running on the full .NET Framework. You can switch to use the new Cloud Optimized runtime, or Core CLR, using the KVM command.
|
||||||
|
|
||||||
1. Run ```kvm upgrade -svrc50``` This command gets the latest Core CLR version of the k runtime and sets it as your default. The -svrc50 switch tells it to use Core CLR. You can use -svr50 to target desktop again.
|
1. Run ```kvm upgrade -runtime CoreCLR``` This command gets the latest Core CLR version of the k runtime and sets it as your default. The `-runtime CoreCLR` switch tells it to use Core CLR. You can use `-r CLR` to target desktop again.
|
||||||
2. Run ```k web``` to run on WebListener.
|
2. Run ```k web``` to run on WebListener.
|
||||||
3. The first line of your output should say "Loaded Module: klr.core45.dll" instead of "Loaded Module: klr.net45.dll"
|
3. The first line of your output should say "Loaded Module: klr.core45.dll" instead of "Loaded Module: klr.net45.dll"
|
||||||
4. The HelloWeb app should work the same as when running on the full desktop .NET Framework but now as a fully self-contained app with true side-by-side versioning support.
|
4. The HelloWeb app should work the same as when running on the full desktop .NET Framework but now as a fully self-contained app with true side-by-side versioning support.
|
||||||
|
|
|
||||||
754
kvm.ps1
754
kvm.ps1
|
|
@ -6,16 +6,26 @@ param(
|
||||||
[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,
|
||||||
[switch] $x86 = $false,
|
[switch] $x86 = $false,
|
||||||
|
[switch] $amd64 = $false,
|
||||||
|
#deprecated
|
||||||
[switch] $x64 = $false,
|
[switch] $x64 = $false,
|
||||||
|
#deprecated
|
||||||
[switch] $svr50 = $false,
|
[switch] $svr50 = $false,
|
||||||
|
#deprecated
|
||||||
[switch] $svrc50 = $false,
|
[switch] $svrc50 = $false,
|
||||||
|
[alias("w")][switch] $wait = $false,
|
||||||
[alias("a")]
|
[alias("a")]
|
||||||
[string] $alias = $null,
|
[string] $alias = $null,
|
||||||
[parameter(Position=1, ValueFromRemainingArguments=$true)]
|
[parameter(Position=1, ValueFromRemainingArguments=$true)]
|
||||||
[string[]]$args=@()
|
[string[]]$args=@()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
$selectedArch=$null;
|
||||||
|
$defaultArch="x86"
|
||||||
|
$selectedRuntime=$null
|
||||||
|
$defaultRuntime="CLR"
|
||||||
$userKrePath = $env:USERPROFILE + "\.kre"
|
$userKrePath = $env:USERPROFILE + "\.kre"
|
||||||
$userKrePackages = $userKrePath + "\packages"
|
$userKrePackages = $userKrePath + "\packages"
|
||||||
$globalKrePath = $env:ProgramFiles + "\KRE"
|
$globalKrePath = $env:ProgramFiles + "\KRE"
|
||||||
|
|
@ -35,11 +45,11 @@ $scriptPath = $myInvocation.MyCommand.Definition
|
||||||
|
|
||||||
function Kvm-Help {
|
function Kvm-Help {
|
||||||
@"
|
@"
|
||||||
K Runtime Environment Version Manager - Build 10010
|
K Runtime Environment Version Manager - Build 10015
|
||||||
|
|
||||||
USAGE: kvm <command> [options]
|
USAGE: kvm <command> [options]
|
||||||
|
|
||||||
kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>]
|
kvm upgrade [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-g|-global] [-f|-force] [-proxy <ADDRESS>]
|
||||||
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
|
||||||
|
|
@ -47,7 +57,7 @@ kvm upgrade [-x86][-x64] [-svr50][-svrc50] [-g|-global] [-proxy <ADDRESS>]
|
||||||
-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
|
||||||
|
|
||||||
kvm install <semver>|<alias>|<nupkg>|latest [-x86][-x64] [-svr50][-svrc50] [-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]
|
||||||
<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
|
||||||
|
|
@ -57,7 +67,7 @@ kvm install <semver>|<alias>|<nupkg>|latest [-x86][-x64] [-svr50][-svrc50] [-a|-
|
||||||
-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
|
||||||
|
|
||||||
kvm use <semver>|<alias>|none [-x86][-x64] [-svr50][-svrc50] [-p|-persistent] [-g|-global]
|
kvm use <semver>|<alias>|none [-x86][-amd64] [-r|-runtime CLR|CoreCLR] [-p|-persistent] [-g|-global]
|
||||||
<semver>|<alias> add KRE bin to path of current command line
|
<semver>|<alias> 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
|
||||||
|
|
@ -72,7 +82,7 @@ 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][-x64] [-svr50][-svrc50]
|
kvm alias <alias> <semver>|<alias> [-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> The KRE version to set the alias to. Alternatively use the version of the specified alias
|
||||||
|
|
||||||
|
|
@ -83,103 +93,112 @@ kvm unalias <alias>
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Global-Setup {
|
function Kvm-Global-Setup {
|
||||||
If (Needs-Elevation)
|
$kvmBinPath = "$userKrePath\bin"
|
||||||
{
|
|
||||||
$arguments = "& '$scriptPath' setup $(Requested-Switches) -persistent"
|
|
||||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
|
||||||
Write-Host "Setup complete"
|
|
||||||
Kvm-Help
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
|
|
||||||
|
|
||||||
$kvmBinPath = "$userKrePath\bin"
|
|
||||||
|
|
||||||
Write-Host "Copying file $kvmBinPath\kvm.ps1"
|
|
||||||
md $kvmBinPath -Force | Out-Null
|
|
||||||
copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1"
|
|
||||||
|
|
||||||
Write-Host "Copying file $kvmBinPath\kvm.cmd"
|
|
||||||
copy "$scriptFolder\kvm.cmd" "$kvmBinPath\kvm.cmd"
|
|
||||||
|
|
||||||
|
If (Needs-Elevation)
|
||||||
|
{
|
||||||
|
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' setup -global -wait"
|
||||||
|
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||||
Write-Host "Adding $kvmBinPath to process PATH"
|
Write-Host "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"
|
|
||||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
|
||||||
$userPath = Change-Path $userPath $kvmBinPath ($kvmBinPath)
|
|
||||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
|
||||||
|
|
||||||
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
|
Write-Host "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"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to machine KRE_HOME"
|
$scriptFolder = [System.IO.Path]::GetDirectoryName($scriptPath)
|
||||||
$machineKreHome = [Environment]::GetEnvironmentVariable("KRE_HOME", [System.EnvironmentVariableTarget]::Machine)
|
|
||||||
$machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
|
|
||||||
$machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath)
|
|
||||||
[Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine)
|
|
||||||
|
|
||||||
Write-Host "Press any key to continue ..."
|
Write-Host "Copying file $kvmBinPath\kvm.ps1"
|
||||||
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
|
md $kvmBinPath -Force | Out-Null
|
||||||
|
copy "$scriptFolder\kvm.ps1" "$kvmBinPath\kvm.ps1"
|
||||||
|
|
||||||
|
Write-Host "Copying file $kvmBinPath\kvm.cmd"
|
||||||
|
copy "$scriptFolder\kvm.cmd" "$kvmBinPath\kvm.cmd"
|
||||||
|
|
||||||
|
Write-Host "Adding $kvmBinPath to process PATH"
|
||||||
|
Set-Path (Change-Path $env:Path $kvmBinPath ($kvmBinPath))
|
||||||
|
|
||||||
|
Write-Host "Adding $kvmBinPath to user PATH"
|
||||||
|
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||||
|
$userPath = Change-Path $userPath $kvmBinPath ($kvmBinPath)
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||||
|
|
||||||
|
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to process KRE_HOME"
|
||||||
|
$envKreHome = $env:KRE_HOME
|
||||||
|
$envKreHome = Change-Path $envKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
|
||||||
|
$envKreHome = Change-Path $envKreHome $globalKrePath ($globalKrePath)
|
||||||
|
$env:KRE_HOME = $envKreHome
|
||||||
|
|
||||||
|
Write-Host "Adding $globalKrePath;%USERPROFILE%\.kre to machine KRE_HOME"
|
||||||
|
$machineKreHome = [Environment]::GetEnvironmentVariable("KRE_HOME", [System.EnvironmentVariableTarget]::Machine)
|
||||||
|
$machineKreHome = Change-Path $machineKreHome "%USERPROFILE%\.kre" ("%USERPROFILE%\.kre")
|
||||||
|
$machineKreHome = Change-Path $machineKreHome $globalKrePath ($globalKrePath)
|
||||||
|
[Environment]::SetEnvironmentVariable("KRE_HOME", $machineKreHome, [System.EnvironmentVariableTarget]::Machine)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Global-Upgrade {
|
function Kvm-Global-Upgrade {
|
||||||
$persistent = $true
|
$persistent = $true
|
||||||
$alias="default"
|
$alias="default"
|
||||||
If (Needs-Elevation) {
|
$versionOrAlias = Kvm-Find-Latest $selectedRuntime $selectedArch
|
||||||
$arguments = "& '$scriptPath' upgrade -global $(Requested-Switches)"
|
If (Needs-Elevation) {
|
||||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
|
||||||
break
|
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||||
}
|
Kvm-Set-Global-Process-Path $versionOrAlias
|
||||||
Kvm-Global-Install "latest"
|
break
|
||||||
|
}
|
||||||
|
Kvm-Install $versionOrAlias $true
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Upgrade {
|
function Kvm-Upgrade {
|
||||||
$persistent = $true
|
$persistent = $true
|
||||||
$alias="default"
|
$alias="default"
|
||||||
Kvm-Install "latest"
|
Kvm-Install "latest" $false
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
$wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password)
|
$wp.Credentials = New-Object System.Net.NetworkCredential($pb.UserName, $pb.Password)
|
||||||
}
|
|
||||||
$wc.Proxy = $wp
|
|
||||||
}
|
}
|
||||||
|
$wc.Proxy = $wp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Find-Latest {
|
function Kvm-Find-Latest {
|
||||||
param(
|
param(
|
||||||
[string] $platform,
|
[string] $platform,
|
||||||
[string] $architecture
|
[string] $architecture
|
||||||
)
|
)
|
||||||
Write-Host "Determining latest version"
|
Write-Host "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")
|
$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)
|
||||||
|
|
||||||
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
|
$version = Select-Xml "//d:Version" -Namespace @{d='http://schemas.microsoft.com/ado/2007/08/dataservices'} $xml
|
||||||
|
|
||||||
return $version
|
if (String-IsEmptyOrWhitespace($version)) {
|
||||||
|
throw "There are no packages for platform '$platform', architecture '$architecture' in the feed '$feed'"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $version
|
||||||
}
|
}
|
||||||
|
|
||||||
function Do-Kvm-Download {
|
function Do-Kvm-Download {
|
||||||
|
|
@ -187,45 +206,45 @@ param(
|
||||||
[string] $kreFullName,
|
[string] $kreFullName,
|
||||||
[string] $packagesFolder
|
[string] $packagesFolder
|
||||||
)
|
)
|
||||||
$parts = $kreFullName.Split(".", 2)
|
$parts = $kreFullName.Split(".", 2)
|
||||||
|
|
||||||
$url = "$feed/package/" + $parts[0] + "/" + $parts[1]
|
$url = "$feed/package/" + $parts[0] + "/" + $parts[1]
|
||||||
$kreFolder = Join-Path $packagesFolder $kreFullName
|
$kreFolder = Join-Path $packagesFolder $kreFullName
|
||||||
$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 {
|
|
||||||
Write-Host "$kreFullName already installed."
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Downloading" $kreFullName "from $feed"
|
|
||||||
|
|
||||||
#Downloading to temp location
|
|
||||||
$kreTempDownload = Join-Path $packagesFolder "temp"
|
|
||||||
$tempKreFile = Join-Path $kreTempDownload "$kreFullName.nupkg"
|
|
||||||
|
|
||||||
if(Test-Path $kreTempDownload) {
|
|
||||||
del "$kreTempDownload\*" -recurse
|
|
||||||
} else {
|
} else {
|
||||||
md $kreTempDownload -Force | Out-Null
|
Write-Host "$kreFullName already installed."
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$wc = New-Object System.Net.WebClient
|
Write-Host "Downloading" $kreFullName "from $feed"
|
||||||
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
|
|
||||||
Add-Proxy-If-Specified($wc)
|
|
||||||
$wc.DownloadFile($url, $tempKreFile)
|
|
||||||
|
|
||||||
Do-Kvm-Unpack $tempKreFile $kreTempDownload
|
#Downloading to temp location
|
||||||
|
$kreTempDownload = Join-Path $packagesFolder "temp"
|
||||||
|
$tempKreFile = Join-Path $kreTempDownload "$kreFullName.nupkg"
|
||||||
|
|
||||||
md $kreFolder -Force | Out-Null
|
if(Test-Path $kreTempDownload) {
|
||||||
Write-Host "Installing to $kreFolder"
|
del "$kreTempDownload\*" -recurse
|
||||||
mv "$kreTempDownload\*" $kreFolder
|
} else {
|
||||||
Remove-Item "$kreTempDownload" -Force | Out-Null
|
md $kreTempDownload -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$wc = New-Object System.Net.WebClient
|
||||||
|
$wc.Credentials = new-object System.Net.NetworkCredential("aspnetreadonly", "4d8a2d9c-7b80-4162-9978-47e918c9658c")
|
||||||
|
Add-Proxy-If-Specified($wc)
|
||||||
|
$wc.DownloadFile($url, $tempKreFile)
|
||||||
|
|
||||||
|
Do-Kvm-Unpack $tempKreFile $kreTempDownload
|
||||||
|
|
||||||
|
md $kreFolder -Force | Out-Null
|
||||||
|
Write-Host "Installing to $kreFolder"
|
||||||
|
mv "$kreTempDownload\*" $kreFolder
|
||||||
|
Remove-Item "$kreTempDownload" -Force | Out-Null
|
||||||
}
|
}
|
||||||
|
|
||||||
function Do-Kvm-Unpack {
|
function Do-Kvm-Unpack {
|
||||||
|
|
@ -233,111 +252,107 @@ param(
|
||||||
[string] $kreFile,
|
[string] $kreFile,
|
||||||
[string] $kreFolder
|
[string] $kreFolder
|
||||||
)
|
)
|
||||||
Write-Host "Unpacking to" $kreFolder
|
Write-Host "Unpacking to" $kreFolder
|
||||||
try {
|
try {
|
||||||
#Shell will not recognize nupkg as a zip and throw, so rename it to zip
|
#Shell will not recognize nupkg as a zip and throw, so rename it to zip
|
||||||
$kreZip = [System.IO.Path]::ChangeExtension($kreFile, "zip")
|
$kreZip = [System.IO.Path]::ChangeExtension($kreFile, "zip")
|
||||||
Rename-Item $kreFile $kreZip
|
Rename-Item $kreFile $kreZip
|
||||||
#Use the shell to uncompress the nupkg
|
#Use the shell to uncompress the nupkg
|
||||||
$shell_app=new-object -com shell.application
|
$shell_app=new-object -com shell.application
|
||||||
$zip_file = $shell_app.namespace($kreZip)
|
$zip_file = $shell_app.namespace($kreZip)
|
||||||
$destination = $shell_app.namespace($kreFolder)
|
$destination = $shell_app.namespace($kreFolder)
|
||||||
$destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
|
$destination.Copyhere($zip_file.items(), 0x14) #0x4 = don't show UI, 0x10 = overwrite files
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
#make it a nupkg again
|
#make it a nupkg again
|
||||||
Rename-Item $kreZip $kreFile
|
Rename-Item $kreZip $kreFile
|
||||||
}
|
}
|
||||||
|
|
||||||
If (Test-Path ($kreFolder + "\[Content_Types].xml")) {
|
If (Test-Path ($kreFolder + "\[Content_Types].xml")) {
|
||||||
Remove-Item ($kreFolder + "\[Content_Types].xml")
|
Remove-Item ($kreFolder + "\[Content_Types].xml")
|
||||||
}
|
}
|
||||||
If (Test-Path ($kreFolder + "\_rels\")) {
|
If (Test-Path ($kreFolder + "\_rels\")) {
|
||||||
Remove-Item ($kreFolder + "\_rels\") -Force -Recurse
|
Remove-Item ($kreFolder + "\_rels\") -Force -Recurse
|
||||||
}
|
}
|
||||||
If (Test-Path ($kreFolder + "\package\")) {
|
If (Test-Path ($kreFolder + "\package\")) {
|
||||||
Remove-Item ($kreFolder + "\package\") -Force -Recurse
|
Remove-Item ($kreFolder + "\package\") -Force -Recurse
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function Kvm-Global-Install {
|
|
||||||
param(
|
|
||||||
[string] $versionOrAlias
|
|
||||||
)
|
|
||||||
If (Needs-Elevation) {
|
|
||||||
$arguments = "& '$scriptPath' install -global $versionOrAlias $(Requested-Switches)"
|
|
||||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
|
||||||
Kvm-Global-Use $versionOrAlias
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($versionOrAlias -eq "latest") {
|
|
||||||
$versionOrAlias = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86")
|
|
||||||
}
|
|
||||||
|
|
||||||
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
|
||||||
|
|
||||||
Do-Kvm-Download $kreFullName $globalKrePackages
|
|
||||||
Kvm-Use $versionOrAlias
|
|
||||||
if (!$(String-IsEmptyOrWhitespace($alias))) {
|
|
||||||
Kvm-Alias-Set $alias $versionOrAlias
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Install {
|
function Kvm-Install {
|
||||||
param(
|
param(
|
||||||
[string] $versionOrAlias
|
[string] $versionOrAlias,
|
||||||
|
[boolean] $isGlobal
|
||||||
)
|
)
|
||||||
if ($versionOrAlias.EndsWith(".nupkg"))
|
if ($versionOrAlias -eq "latest") {
|
||||||
{
|
$versionOrAlias = Kvm-Find-Latest (Requested-Platform $defaultRuntime) (Requested-Architecture $defaultArch)
|
||||||
$kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
|
}
|
||||||
$kreFolder = "$userKrePackages\$kreFullName"
|
|
||||||
$folderExists = Test-Path $kreFolder
|
|
||||||
|
|
||||||
if($folderExists -and $force) {
|
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||||
del $kreFolder -Recurse -Force
|
$kreFullName = [System.IO.Path]::GetFileNameWithoutExtension($versionOrAlias)
|
||||||
$folderExists = $false;
|
} else {
|
||||||
}
|
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
||||||
|
}
|
||||||
|
|
||||||
if($folderExists) {
|
if ($isGlobal) {
|
||||||
Write-Host "Target folder '$kreFolder' already exists"
|
if (Needs-Elevation) {
|
||||||
} else {
|
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' install '$versionOrAlias' -global $(Requested-Switches) -wait"
|
||||||
$tempUnpackFolder = Join-Path $userKrePackages "temp"
|
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||||
$tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg"
|
Kvm-Set-Global-Process-Path $versionOrAlias
|
||||||
|
break
|
||||||
if(Test-Path $tempUnpackFolder) {
|
|
||||||
del "$tempUnpackFolder\*" -recurse
|
|
||||||
} else {
|
|
||||||
md $tempUnpackFolder -Force | Out-Null
|
|
||||||
}
|
|
||||||
copy $versionOrAlias $tempKreFile
|
|
||||||
|
|
||||||
Do-Kvm-Unpack $tempKreFile $tempUnpackFolder
|
|
||||||
md $kreFolder -Force | Out-Null
|
|
||||||
Write-Host "Installing to $kreFolder"
|
|
||||||
mv "$tempUnpackFolder\*" $kreFolder
|
|
||||||
Remove-Item "$tempUnpackFolder" -Force | Out-Null
|
|
||||||
}
|
|
||||||
|
|
||||||
$packageVersion = Package-Version $kreFullName
|
|
||||||
Kvm-Use $packageVersion
|
|
||||||
if (!$(String-IsEmptyOrWhitespace($alias))) {
|
|
||||||
Kvm-Alias-Set $alias $packageVersion
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
$packageFolder = $globalKrePackages
|
||||||
{
|
} else {
|
||||||
if ($versionOrAlias -eq "latest") {
|
$packageFolder = $userKrePackages
|
||||||
$versionOrAlias = Kvm-Find-Latest (Requested-Platform "svr50") (Requested-Architecture "x86")
|
}
|
||||||
}
|
|
||||||
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
|
||||||
|
|
||||||
Do-Kvm-Download $kreFullName $userKrePackages
|
if ($versionOrAlias.EndsWith(".nupkg")) {
|
||||||
Kvm-Use $versionOrAlias
|
Set-Variable -Name "selectedArch" -Value (Package-Arch $kreFullName) -Scope Script
|
||||||
if (!$(String-IsEmptyOrWhitespace($alias))) {
|
Set-Variable -Name "selectedRuntime" -Value (Package-Platform $kreFullName) -Scope Script
|
||||||
Kvm-Alias-Set $alias $versionOrAlias
|
|
||||||
}
|
$kreFolder = "$packageFolder\$kreFullName"
|
||||||
|
$folderExists = Test-Path $kreFolder
|
||||||
|
|
||||||
|
if ($folderExists -and $force) {
|
||||||
|
del $kreFolder -Recurse -Force
|
||||||
|
$folderExists = $false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($folderExists) {
|
||||||
|
Write-Host "Target folder '$kreFolder' already exists"
|
||||||
|
} else {
|
||||||
|
$tempUnpackFolder = Join-Path $packageFolder "temp"
|
||||||
|
$tempKreFile = Join-Path $tempUnpackFolder "$kreFullName.nupkg"
|
||||||
|
|
||||||
|
if(Test-Path $tempUnpackFolder) {
|
||||||
|
del "$tempUnpackFolder\*" -recurse
|
||||||
|
} else {
|
||||||
|
md $tempUnpackFolder -Force | Out-Null
|
||||||
|
}
|
||||||
|
copy $versionOrAlias $tempKreFile
|
||||||
|
|
||||||
|
Do-Kvm-Unpack $tempKreFile $tempUnpackFolder
|
||||||
|
md $kreFolder -Force | Out-Null
|
||||||
|
Write-Host "Installing to $kreFolder"
|
||||||
|
mv "$tempUnpackFolder\*" $kreFolder
|
||||||
|
Remove-Item "$tempUnpackFolder" -Force | Out-Null
|
||||||
|
}
|
||||||
|
|
||||||
|
$packageVersion = Package-Version $kreFullName
|
||||||
|
|
||||||
|
Kvm-Use $packageVersion
|
||||||
|
if (!$(String-IsEmptyOrWhitespace($alias))) {
|
||||||
|
Kvm-Alias-Set $alias $packageVersion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Do-Kvm-Download $kreFullName $packageFolder
|
||||||
|
Kvm-Use $versionOrAlias
|
||||||
|
if (!$(String-IsEmptyOrWhitespace($alias))) {
|
||||||
|
Kvm-Alias-Set "$alias" $versionOrAlias
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-List {
|
function Kvm-List {
|
||||||
|
|
@ -400,100 +415,114 @@ function Kvm-Global-Use {
|
||||||
param(
|
param(
|
||||||
[string] $versionOrAlias
|
[string] $versionOrAlias
|
||||||
)
|
)
|
||||||
If (Needs-Elevation) {
|
If (Needs-Elevation) {
|
||||||
$arguments = "& '$scriptPath' use -global $versionOrAlias $(Requested-Switches)"
|
$arguments = "-ExecutionPolicy unrestricted & '$scriptPath' use '$versionOrAlias' -global $(Requested-Switches) -wait"
|
||||||
if ($persistent) {
|
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
||||||
$arguments = $arguments + " -persistent"
|
Kvm-Set-Global-Process-Path $versionOrAlias
|
||||||
}
|
break
|
||||||
Start-Process "$psHome\powershell.exe" -Verb runAs -ArgumentList $arguments -Wait
|
}
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($versionOrAlias -eq "none") {
|
Kvm-Set-Global-Process-Path "$versionOrAlias"
|
||||||
Write-Host "Removing KRE from process PATH"
|
|
||||||
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
|
|
||||||
|
|
||||||
if ($persistent) {
|
|
||||||
Write-Host "Removing KRE from machine PATH"
|
|
||||||
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
|
|
||||||
$machinePath = Change-Path $machinePath "" ($globalKrePackages, $userKrePackages)
|
|
||||||
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
|
||||||
|
|
||||||
$kreBin = Locate-KreBinFromFullName $kreFullName
|
|
||||||
if ($kreBin -eq $null) {
|
|
||||||
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Adding" $kreBin "to process PATH"
|
|
||||||
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
|
|
||||||
|
|
||||||
|
if ($versionOrAlias -eq "none") {
|
||||||
if ($persistent) {
|
if ($persistent) {
|
||||||
Write-Host "Adding $kreBin to machine PATH"
|
Write-Host "Removing KRE from 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 "" ($globalKrePackages, $userKrePackages)
|
||||||
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
|
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$kreFullName = Requested-VersionOrAlias "$versionOrAlias"
|
||||||
|
$kreBin = Locate-KreBinFromFullName $kreFullName
|
||||||
|
if ($kreBin -eq $null) {
|
||||||
|
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($persistent) {
|
||||||
|
Write-Host "Adding $kreBin to machine PATH"
|
||||||
|
$machinePath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
|
||||||
|
$machinePath = Change-Path $machinePath $kreBin ($globalKrePackages, $userKrePackages)
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $machinePath, [System.EnvironmentVariableTarget]::Machine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Kvm-Set-Global-Process-Path {
|
||||||
|
param(
|
||||||
|
[string] $versionOrAlias
|
||||||
|
)
|
||||||
|
if ($versionOrAlias -eq "none") {
|
||||||
|
Write-Host "Removing KRE from process PATH"
|
||||||
|
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
||||||
|
$kreBin = Locate-KreBinFromFullName $kreFullName
|
||||||
|
if ($kreBin -eq $null) {
|
||||||
|
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Adding" $kreBin "to process PATH"
|
||||||
|
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Use {
|
function Kvm-Use {
|
||||||
param(
|
param(
|
||||||
[string] $versionOrAlias
|
[string] $versionOrAlias
|
||||||
)
|
)
|
||||||
if ($versionOrAlias -eq "none") {
|
if ($versionOrAlias -eq "none") {
|
||||||
Write-Host "Removing KRE from process PATH"
|
Write-Host "Removing KRE from process PATH"
|
||||||
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
|
Set-Path (Change-Path $env:Path "" ($globalKrePackages, $userKrePackages))
|
||||||
|
|
||||||
if ($persistent) {
|
|
||||||
Write-Host "Removing KRE from user PATH"
|
|
||||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
|
||||||
$userPath = Change-Path $userPath "" ($globalKrePackages, $userKrePackages)
|
|
||||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
|
||||||
|
|
||||||
$kreBin = Locate-KreBinFromFullName $kreFullName
|
|
||||||
if ($kreBin -eq $null) {
|
|
||||||
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Adding" $kreBin "to process PATH"
|
|
||||||
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
|
|
||||||
|
|
||||||
if ($persistent) {
|
if ($persistent) {
|
||||||
Write-Host "Adding $kreBin to user PATH"
|
Write-Host "Removing KRE from 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 "" ($globalKrePackages, $userKrePackages)
|
||||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$kreFullName = Requested-VersionOrAlias $versionOrAlias
|
||||||
|
|
||||||
|
$kreBin = Locate-KreBinFromFullName $kreFullName
|
||||||
|
if ($kreBin -eq $null) {
|
||||||
|
Write-Host "Cannot find $kreFullName, do you need to run 'kvm install $versionOrAlias'?"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Adding" $kreBin "to process PATH"
|
||||||
|
Set-Path (Change-Path $env:Path $kreBin ($globalKrePackages, $userKrePackages))
|
||||||
|
|
||||||
|
if ($persistent) {
|
||||||
|
Write-Host "Adding $kreBin to user PATH"
|
||||||
|
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||||
|
$userPath = Change-Path $userPath $kreBin ($globalKrePackages, $userKrePackages)
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Alias-List {
|
function Kvm-Alias-List {
|
||||||
md ($userKrePath + "\alias\") -Force | Out-Null
|
md ($userKrePath + "\alias\") -Force | Out-Null
|
||||||
|
|
||||||
Get-ChildItem ($userKrePath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
|
Get-ChildItem ($userKrePath + "\alias\") | Select @{label='Alias';expression={$_.BaseName}}, @{label='Name';expression={Get-Content $_.FullName }} | Format-Table -AutoSize
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Alias-Get {
|
function Kvm-Alias-Get {
|
||||||
param(
|
param(
|
||||||
[string] $name
|
[string] $name
|
||||||
)
|
)
|
||||||
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"
|
Write-Host "Alias '$name' does not exist"
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt"))
|
Write-Host "Alias '$name' is set to" (Get-Content ($userKrePath + "\alias\" + $name + ".txt"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Alias-Set {
|
function Kvm-Alias-Set {
|
||||||
|
|
@ -501,25 +530,25 @@ param(
|
||||||
[string] $name,
|
[string] $name,
|
||||||
[string] $value
|
[string] $value
|
||||||
)
|
)
|
||||||
$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'"
|
Write-Host "$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
|
||||||
}
|
}
|
||||||
|
|
||||||
function Kvm-Unalias {
|
function Kvm-Unalias {
|
||||||
param(
|
param(
|
||||||
[string] $name
|
[string] $name
|
||||||
)
|
)
|
||||||
$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"
|
Write-Host "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"
|
Write-Host "Cannot remove alias, '$name' is not a valid alias name"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Locate-KreBinFromFullName() {
|
function Locate-KreBinFromFullName() {
|
||||||
|
|
@ -544,58 +573,57 @@ function Package-Version() {
|
||||||
param(
|
param(
|
||||||
[string] $kreFullName
|
[string] $kreFullName
|
||||||
)
|
)
|
||||||
return $kreFullName -replace '[^.]*.(.*)', '$1'
|
return $kreFullName -replace '[^.]*.(.*)', '$1'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Package-Platform() {
|
||||||
|
param(
|
||||||
|
[string] $kreFullName
|
||||||
|
)
|
||||||
|
return $kreFullName -replace 'KRE-([^-]*).*', '$1'
|
||||||
|
}
|
||||||
|
|
||||||
|
function Package-Arch() {
|
||||||
|
param(
|
||||||
|
[string] $kreFullName
|
||||||
|
)
|
||||||
|
return $kreFullName -replace 'KRE-[^-]*-([^.]*).*', '$1'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function Requested-VersionOrAlias() {
|
function Requested-VersionOrAlias() {
|
||||||
param(
|
param(
|
||||||
[string] $versionOrAlias
|
[string] $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)
|
||||||
$pkgVersion = $parts[1]
|
$pkgVersion = $parts[1]
|
||||||
$parts =$parts[0].Split('-', 3)
|
$parts =$parts[0].Split('-', 3)
|
||||||
$pkgPlatform = Requested-Platform $parts[1]
|
$pkgPlatform = Requested-Platform $parts[1]
|
||||||
$pkgArchitecture = Requested-Architecture $parts[2]
|
$pkgArchitecture = Requested-Architecture $parts[2]
|
||||||
} else {
|
} else {
|
||||||
$pkgVersion = $versionOrAlias
|
$pkgVersion = $versionOrAlias
|
||||||
$pkgPlatform = Requested-Platform "svr50"
|
$pkgPlatform = Requested-Platform $defaultRuntime
|
||||||
$pkgArchitecture = Requested-Architecture "x86"
|
$pkgArchitecture = Requested-Architecture $defaultArch
|
||||||
}
|
}
|
||||||
return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion
|
return "KRE-" + $pkgPlatform + "-" + $pkgArchitecture + "." + $pkgVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
function Requested-Platform() {
|
function Requested-Platform() {
|
||||||
param(
|
param(
|
||||||
[string] $default
|
[string] $default
|
||||||
)
|
)
|
||||||
if ($svr50 -and $svrc50) {
|
if (!(String-IsEmptyOrWhitespace($selectedRuntime))) {return $selectedRuntime}
|
||||||
Throw "This command cannot accept both -svr50 and -svrc50"
|
return $default
|
||||||
}
|
|
||||||
if ($svr50) {
|
|
||||||
return "svr50"
|
|
||||||
}
|
|
||||||
if ($svrc50) {
|
|
||||||
return "svrc50"
|
|
||||||
}
|
|
||||||
return $default
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Requested-Architecture() {
|
function Requested-Architecture() {
|
||||||
param(
|
param(
|
||||||
[string] $default
|
[string] $default
|
||||||
)
|
)
|
||||||
if ($x86 -and $x64) {
|
if (!(String-IsEmptyOrWhitespace($selectedArch))) {return $selectedArch}
|
||||||
Throw "This command cannot accept both -x86 and -x64"
|
return $default
|
||||||
}
|
|
||||||
if ($x86) {
|
|
||||||
return "x86"
|
|
||||||
}
|
|
||||||
if ($x64) {
|
|
||||||
return "x64"
|
|
||||||
}
|
|
||||||
return $default
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function Change-Path() {
|
function Change-Path() {
|
||||||
|
|
@ -604,19 +632,19 @@ param(
|
||||||
[string] $prependPath,
|
[string] $prependPath,
|
||||||
[string[]] $removePaths
|
[string[]] $removePaths
|
||||||
)
|
)
|
||||||
$newPath = $prependPath
|
$newPath = $prependPath
|
||||||
foreach($portion in $existingPaths.Split(';')) {
|
foreach($portion in $existingPaths.Split(';')) {
|
||||||
$skip = $portion -eq ""
|
$skip = $portion -eq ""
|
||||||
foreach($removePath in $removePaths) {
|
foreach($removePath in $removePaths) {
|
||||||
if ($portion.StartsWith($removePath)) {
|
if ($portion.StartsWith($removePath)) {
|
||||||
$skip = $true
|
$skip = $true
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!$skip) {
|
|
||||||
$newPath = $newPath + ";" + $portion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $newPath
|
if (!$skip) {
|
||||||
|
$newPath = $newPath + ";" + $portion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $newPath
|
||||||
}
|
}
|
||||||
|
|
||||||
function Set-Path() {
|
function Set-Path() {
|
||||||
|
|
@ -631,35 +659,70 @@ SET "PATH=$newPath"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Needs-Elevation() {
|
function Needs-Elevation() {
|
||||||
$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
|
||||||
}
|
}
|
||||||
|
|
||||||
function Requested-Switches() {
|
function Requested-Switches() {
|
||||||
$arguments = ""
|
$arguments = ""
|
||||||
if ($x86) {$arguments = "$arguments -x86"}
|
if ($x86) {$arguments = "$arguments -x86"}
|
||||||
|
if ($amd64) {$arguments = "$arguments -amd64"}
|
||||||
|
#deprecated
|
||||||
if ($x64) {$arguments = "$arguments -x64"}
|
if ($x64) {$arguments = "$arguments -x64"}
|
||||||
if ($svr50) {$arguments = "$arguments -svr50"}
|
if ($selectedRuntime) {$arguments = "$arguments -runtime $selectedRuntime"}
|
||||||
if ($svrc50) {$arguments = "$arguments -svrc50"}
|
if ($persistent) {$arguments = "$arguments -persistent"}
|
||||||
|
if ($force) {$arguments = "$arguments -force"}
|
||||||
|
if (!$(String-IsEmptyOrWhitespace($alias))) {$arguments = "$arguments -alias '$alias'"}
|
||||||
return $arguments
|
return $arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
function Validate-And-Santitise-Switches()
|
||||||
if ($global) {
|
{
|
||||||
|
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 ($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 ($x64 -and $amd64) {throw "You cannot select both x64 and amd64 architectures"}
|
||||||
|
|
||||||
|
if ($runtime) {
|
||||||
|
$validRuntimes = "CoreCLR", "CLR", "svr50", "svrc50"
|
||||||
|
$match = $validRuntimes | ? { $_ -like $runtime } | Select -First 1
|
||||||
|
if (!$match) {throw "'$runtime' is not a valid runtime"}
|
||||||
|
Set-Variable -Name "selectedRuntime" -Value $match -Scope Script
|
||||||
|
} elseif ($svr50) {
|
||||||
|
Write-Host "Warning: -svr50 is deprecated, use -runtime CLR for new packages."
|
||||||
|
Set-Variable -Name "selectedRuntime" -Value "svr50" -Scope Script
|
||||||
|
} elseif ($svrc50) {
|
||||||
|
Write-Host "Warning: -svrc50 is deprecated, use -runtime CoreCLR for new packages."
|
||||||
|
Set-Variable -Name "selectedRuntime" -Value "svrc50" -Scope Script
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($x64) {
|
||||||
|
Write-Host "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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Validate-And-Santitise-Switches
|
||||||
|
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-Global-Upgrade}
|
||||||
"install 1" {Kvm-Global-Install $args[0]}
|
"install 1" {Kvm-Install $args[0] $true}
|
||||||
# "list 0" {Kvm-Global-List}
|
|
||||||
"use 1" {Kvm-Global-Use $args[0]}
|
"use 1" {Kvm-Global-Use $args[0]}
|
||||||
default {Write-Host 'Unknown command, or global switch not supported'; Kvm-Help;}
|
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}
|
||||||
"install 1" {Kvm-Install $args[0]}
|
"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}
|
||||||
|
|
@ -668,10 +731,15 @@ function Requested-Switches() {
|
||||||
"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 {Write-Host 'Unknown command'; Kvm-Help;}
|
default {throw "Unknown command"};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-Host $_ -ForegroundColor Red ;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host $_ -ForegroundColor Red ;
|
||||||
|
Write-Host "Type 'kvm help' for help on how to use kvm."
|
||||||
|
}
|
||||||
|
if ($wait) {
|
||||||
|
Write-Host "Press any key to continue ..."
|
||||||
|
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown,AllowCtrlC")
|
||||||
|
}
|
||||||
|
|
|
||||||
4
kvm.sh
4
kvm.sh
|
|
@ -18,7 +18,7 @@ KRE_MONO45=
|
||||||
KRE_X86=
|
KRE_X86=
|
||||||
KRE_X64=
|
KRE_X64=
|
||||||
if [ -z "$KRE_FEED" ]; then
|
if [ -z "$KRE_FEED" ]; then
|
||||||
KRE_FEED="https://www.myget.org/F/aspnextvnext/api/v2"
|
KRE_FEED="https://www.myget.org/F/aspnetvnext/api/v2"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_kvm_find_latest() {
|
_kvm_find_latest() {
|
||||||
|
|
@ -169,7 +169,7 @@ kvm()
|
||||||
case $1 in
|
case $1 in
|
||||||
"help" )
|
"help" )
|
||||||
echo ""
|
echo ""
|
||||||
echo "K Runtime Environment Version Manager - Build 10010"
|
echo "K Runtime Environment Version Manager - Build 10015"
|
||||||
echo ""
|
echo ""
|
||||||
echo "USAGE: kvm <command> [options]"
|
echo "USAGE: kvm <command> [options]"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue