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