parent
1d06f1f935
commit
615efcc78e
125
dnvm.ps1
125
dnvm.ps1
|
|
@ -67,7 +67,7 @@ function _WriteOut {
|
|||
|
||||
### Constants
|
||||
$ProductVersion="1.0.0"
|
||||
$BuildVersion="beta8-15516"
|
||||
$BuildVersion="beta8-15517"
|
||||
$Authors="Microsoft Open Technologies, Inc."
|
||||
|
||||
# If the Version hasn't been replaced...
|
||||
|
|
@ -154,11 +154,11 @@ if($__TeeTo) {
|
|||
$DeprecatedCommands = @("unalias")
|
||||
|
||||
# Load Environment variables
|
||||
$RuntimeHomes = $env:DNX_HOME
|
||||
$RuntimeHomes = $(if (Test-Path "env:\$HomeEnvVar") {Get-Content "env:\$HomeEnvVar"})
|
||||
$UserHome = $env:DNX_USER_HOME
|
||||
$GlobalHome = $env:DNX_GLOBAL_HOME
|
||||
$ActiveFeed = $env:DNX_FEED
|
||||
$ActiveUnstableFeed = $env:DNX_UNSTABLE_FEED
|
||||
$ActiveFeed = $(if (Test-Path "env:\$DefaultFeedKey") {Get-Content "env:\$DefaultFeedKey"})
|
||||
$ActiveUnstableFeed = $(if (Test-Path "env:\$DefaultUnstableFeedKey") {Get-Content "env:\$DefaultUnstableFeedKey"})
|
||||
|
||||
# Default Exit Code
|
||||
$Script:ExitCode = $ExitCodes.Success
|
||||
|
|
@ -181,13 +181,32 @@ if($CmdPathFile) {
|
|||
_WriteDebug "Using CMD PATH file: $CmdPathFile"
|
||||
}
|
||||
|
||||
# Determine where runtimes can exist (RuntimeHomes)
|
||||
if(!$RuntimeHomes) {
|
||||
# Set up a default value for the runtime home
|
||||
$UnencodedHomes = "$env:USERPROFILE\$DefaultUserDirectoryName;$GlobalHome\$DefaultGlobalDirectoryName"
|
||||
} else {
|
||||
$UnencodedHomes = $RuntimeHomes
|
||||
# Determine the default installation directory (UserHome)
|
||||
if(!$UserHome) {
|
||||
if ($RuntimeHomes) {
|
||||
_WriteDebug "Detecting User Home..."
|
||||
$pf = $env:ProgramFiles
|
||||
if(Test-Path "env:\ProgramFiles(x86)") {
|
||||
$pf32 = Get-Content "env:\ProgramFiles(x86)"
|
||||
}
|
||||
|
||||
# Canonicalize so we can do StartsWith tests
|
||||
if(!$pf.EndsWith("\")) { $pf += "\" }
|
||||
if($pf32 -and !$pf32.EndsWith("\")) { $pf32 += "\" }
|
||||
|
||||
$UserHome = $RuntimeHomes.Split(";") | Where-Object {
|
||||
# Take the first path that isn't under program files
|
||||
!($_.StartsWith($pf) -or $_.StartsWith($pf32))
|
||||
} | Select-Object -First 1
|
||||
|
||||
_WriteDebug "Found: $UserHome"
|
||||
}
|
||||
|
||||
if(!$UserHome) {
|
||||
$UserHome = "$DefaultUserHome"
|
||||
}
|
||||
}
|
||||
$UserHome = [Environment]::ExpandEnvironmentVariables($UserHome)
|
||||
|
||||
# Determine the default global installation directory (GlobalHome)
|
||||
if(!$GlobalHome) {
|
||||
|
|
@ -196,40 +215,27 @@ if(!$GlobalHome) {
|
|||
} else {
|
||||
$GlobalHome = "$env:AllUsersProfile\$DefaultGlobalDirectoryName"
|
||||
}
|
||||
}
|
||||
$GlobalHome = [Environment]::ExpandEnvironmentVariables($GlobalHome)
|
||||
|
||||
$env:DNX_GLOBAL_HOME="$GlobalHome"
|
||||
$env:DNX_HOME="$env:DNX_HOME;$env:DNX_GLOBAL_HOME"
|
||||
$UnencodedHomes = "$UnencodedHomes;$GlobalHome"
|
||||
# Determine where runtimes can exist (RuntimeHomes)
|
||||
if(!$RuntimeHomes) {
|
||||
# Set up a default value for the runtime home
|
||||
$UnencodedHomes = "$UserHome;$GlobalHome"
|
||||
} elseif ($RuntimeHomes.StartsWith(';')) {
|
||||
_WriteOut "Ignoring invalid $HomeEnvVar; value was '$RuntimeHomes'" -ForegroundColor $ColorScheme.Warning
|
||||
Clean-HomeEnv($true)
|
||||
|
||||
# Use default instead.
|
||||
$UnencodedHomes = "$UserHome;$GlobalHome"
|
||||
} else {
|
||||
$UnencodedHomes = $RuntimeHomes
|
||||
}
|
||||
|
||||
$UnencodedHomes = $UnencodedHomes.Split(";")
|
||||
$RuntimeHomes = $UnencodedHomes | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_) }
|
||||
$RuntimeDirs = $RuntimeHomes | ForEach-Object { Join-Path $_ "runtimes" }
|
||||
|
||||
# Determine the default installation directory (UserHome)
|
||||
if(!$UserHome) {
|
||||
_WriteDebug "Detecting User Home..."
|
||||
$pf = $env:ProgramFiles
|
||||
if(Test-Path "env:\ProgramFiles(x86)") {
|
||||
$pf32 = Get-Content "env:\ProgramFiles(x86)"
|
||||
}
|
||||
|
||||
# Canonicalize so we can do StartsWith tests
|
||||
if(!$pf.EndsWith("\")) { $pf += "\" }
|
||||
if($pf32 -and !$pf32.EndsWith("\")) { $pf32 += "\" }
|
||||
|
||||
$UserHome = $RuntimeHomes | Where-Object {
|
||||
# Take the first path that isn't under program files
|
||||
!($_.StartsWith($pf) -or $_.StartsWith($pf32))
|
||||
} | Select-Object -First 1
|
||||
|
||||
_WriteDebug "Found: $UserHome"
|
||||
|
||||
if(!$UserHome) {
|
||||
$UserHome = "$env:USERPROFILE\$DefaultUserDirectoryName"
|
||||
}
|
||||
}
|
||||
|
||||
_WriteDebug ""
|
||||
_WriteDebug "=== Running $CommandName ==="
|
||||
_WriteDebug "Runtime Homes: $RuntimeHomes"
|
||||
|
|
@ -240,6 +246,22 @@ $GlobalRuntimesDir = Join-Path $GlobalHome "runtimes"
|
|||
$Aliases = $null
|
||||
|
||||
### Helper Functions
|
||||
# Remove $HomeEnv from process and user environment.
|
||||
# Called when current value is invalid or after installing files to default location.
|
||||
function Clean-HomeEnv {
|
||||
param([switch]$SkipUserEnvironment)
|
||||
|
||||
if (Test-Path "env:\$HomeEnvVar") {
|
||||
_WriteOut "Removing Process $HomeEnvVar"
|
||||
Set-Content "env:\$HomeEnvVar" $null
|
||||
}
|
||||
|
||||
if (!$SkipUserEnvironment -and [Environment]::GetEnvironmentVariable($HomeEnvVar, "User")) {
|
||||
_WriteOut "Removing User $HomeEnvVar"
|
||||
[Environment]::SetEnvironmentVariable($HomeEnvVar, $null, "User")
|
||||
}
|
||||
}
|
||||
|
||||
# Checks if a specified file exists in the destination folder and if not, copies the file
|
||||
# to the destination folder.
|
||||
function Safe-Filecopy {
|
||||
|
|
@ -1543,12 +1565,12 @@ function dnvm-use {
|
|||
|
||||
if ($versionOrAlias -eq "none") {
|
||||
_WriteOut "Removing all runtimes from process PATH"
|
||||
Set-Path (Change-Path $env:Path "" ($RuntimeDirs))
|
||||
Set-Path (Change-Path $env:Path "" $RuntimeDirs)
|
||||
|
||||
if ($Persistent) {
|
||||
_WriteOut "Removing all runtimes from user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath "" ($RuntimeDirs)
|
||||
$userPath = Change-Path $userPath "" $RuntimeDirs
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
return;
|
||||
|
|
@ -1562,12 +1584,12 @@ function dnvm-use {
|
|||
}
|
||||
|
||||
_WriteOut "Adding $runtimeBin to process PATH"
|
||||
Set-Path (Change-Path $env:Path $runtimeBin ($RuntimeDirs))
|
||||
Set-Path (Change-Path $env:Path $runtimeBin $RuntimeDirs)
|
||||
|
||||
if ($Persistent) {
|
||||
_WriteOut "Adding $runtimeBin to user PATH"
|
||||
$userPath = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User)
|
||||
$userPath = Change-Path $userPath $runtimeBin ($RuntimeDirs)
|
||||
$userPath = Change-Path $userPath $runtimeBin $RuntimeDirs
|
||||
[Environment]::SetEnvironmentVariable("Path", $userPath, [System.EnvironmentVariableTarget]::User)
|
||||
}
|
||||
}
|
||||
|
|
@ -1667,7 +1689,7 @@ function dnvm-setup {
|
|||
param(
|
||||
[switch]$SkipUserEnvironmentInstall)
|
||||
|
||||
$DestinationHome = "$env:USERPROFILE\$DefaultUserDirectoryName"
|
||||
$DestinationHome = [Environment]::ExpandEnvironmentVariables("$DefaultUserHome")
|
||||
|
||||
# Install scripts
|
||||
$Destination = "$DestinationHome\bin"
|
||||
|
|
@ -1683,7 +1705,7 @@ function dnvm-setup {
|
|||
# Also, clean old user home values if present
|
||||
# We'll be removing any existing homes, both
|
||||
$PathsToRemove = @(
|
||||
"%USERPROFILE%\$DefaultUserDirectoryName",
|
||||
"$DefaultUserHome",
|
||||
[Environment]::ExpandEnvironmentVariables($OldUserHome),
|
||||
$DestinationHome,
|
||||
$OldUserHome)
|
||||
|
|
@ -1699,21 +1721,8 @@ function dnvm-setup {
|
|||
[Environment]::SetEnvironmentVariable("PATH", $userPath, "User")
|
||||
}
|
||||
|
||||
# Now the HomeEnvVar
|
||||
_WriteOut "Adding $DestinationHome to Process $HomeEnvVar"
|
||||
$processHome = ""
|
||||
if(Test-Path "env:\$HomeEnvVar") {
|
||||
$processHome = Get-Content "env:\$HomeEnvVar"
|
||||
}
|
||||
$processHome = Change-Path $processHome "%USERPROFILE%\$DefaultUserDirectoryName" $PathsToRemove
|
||||
Set-Content "env:\$HomeEnvVar" $processHome
|
||||
|
||||
if(!$SkipUserEnvironmentInstall) {
|
||||
_WriteOut "Adding $DestinationHome to User $HomeEnvVar"
|
||||
$userHomeVal = [Environment]::GetEnvironmentVariable($HomeEnvVar, "User")
|
||||
$userHomeVal = Change-Path $userHomeVal "%USERPROFILE%\$DefaultUserDirectoryName" $PathsToRemove
|
||||
[Environment]::SetEnvironmentVariable($HomeEnvVar, $userHomeVal, "User")
|
||||
}
|
||||
# Now clean up the HomeEnvVar if currently set; script installed to default location.
|
||||
Clean-HomeEnv($SkipUserEnvironmentInstall)
|
||||
}
|
||||
|
||||
function Check-Runtimes(){
|
||||
|
|
|
|||
2
dnvm.sh
2
dnvm.sh
|
|
@ -2,7 +2,7 @@
|
|||
# Source this file from your .bash-profile or script to use
|
||||
|
||||
# "Constants"
|
||||
_DNVM_BUILDNUMBER="beta8-15516"
|
||||
_DNVM_BUILDNUMBER="beta8-15517"
|
||||
_DNVM_AUTHORS="Microsoft Open Technologies, Inc."
|
||||
_DNVM_RUNTIME_PACKAGE_NAME="dnx"
|
||||
_DNVM_RUNTIME_FRIENDLY_NAME=".NET Execution Environment"
|
||||
|
|
|
|||
Loading…
Reference in New Issue