Add ToolsRoot so Chocolatey_Bin_Root is \tools

This commit is contained in:
Iristyle
2012-12-03 14:31:12 -05:00
parent ddbf24cbf7
commit 7a84f6df89
3 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>toolsroot</id>
<version>0.1.0</version>
<title>Tools Root</title>
<authors>Ethan J. Brown</authors>
<owners>Ethan J. Brown</owners>
<!--<iconUrl></iconUrl>-->
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Set's the chocolatey_bin_root environment variable to a default value of '\tools' if not already set. This allows packages such as Ruby, Python etc. to install in \tools instead of the system root.
</description>
<summary>Sets the chocolatey_bin_root default value to \tools.</summary>
<tags>path</tags>
<!--<dependencies>
<dependency id="" version="" />
</dependencies>-->
</metadata>
</package>

View File

@@ -0,0 +1,22 @@
$packageName = 'ToolsRoot'
try
{
$variableName = 'Chocolatey_Bin_Root'
if (!(Get-Item Env:$variableName -ErrorAction SilentlyContinue))
{
$path = '\tools'
[Environment]::SetEnvironmentVariable($variableName, $path, 'User')
Set-Item Env:$variableName $path
$binRoot = Join-Path $Env:SystemDrive $path
Write-Host "Configured $variableName as $binRoot"
}
Write-ChocolateySuccess $package
}
catch
{
Write-ChocolateyFailure $package "$($_.Exception.Message)"
throw
}

View File

@@ -0,0 +1,23 @@
$package = 'ToolsRoot'
try
{
$variableName = 'Chocolatey_Bin_Root'
$binRoot = Get-Item Env:$variableName -ErrorAction SilentlyContinue |
Select -ExpandProperty Value -First 1
if ($binRoot)
{
[Environment]::SetEnvironmentVariable($variableName, '', 'User')
Set-Item Env:$variableName $null
Write-Host "Removed $variableName [was $binRoot]"
}
Write-ChocolateySuccess $package
}
catch
{
Write-ChocolateyFailure $package "$($_.Exception.Message)"
throw
}