Skip to content

Commit

Permalink
(maint) installer cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed Apr 3, 2014
1 parent 483bc48 commit 42524a7
Showing 1 changed file with 2 additions and 45 deletions.
47 changes: 2 additions & 45 deletions nuget/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
$thisScriptFolder = (Split-Path -parent $MyInvocation.MyCommand.Definition)
$chocInstallVariableName = "ChocolateyInstall"
$sysDrive = $env:SystemDrive
#$defaultNugetPath = "$sysDrive\Chocolatey"
$defaultChocolateyPathOld = "$sysDrive\NuGet"

function Set-ChocolateyInstallFolder($folder){
#if(test-path $folder){
Expand Down Expand Up @@ -79,16 +77,13 @@ param(

#if we have an already environment variable path, use it.
$alreadyInitializedNugetPath = Get-ChocolateyInstallFolder
if($alreadyInitializedNugetPath -and $alreadyInitializedNugetPath -ne $chocolateyPath -and $alreadyInitializedNugetPath -ne $defaultChocolateyPathOld){
if($alreadyInitializedNugetPath -and $alreadyInitializedNugetPath -ne $chocolateyPath){
$chocolateyPath = $alreadyInitializedNugetPath
}
else {
Set-ChocolateyInstallFolder $chocolateyPath
}

if(!(test-path $chocolateyPath)){
mkdir $chocolateyPath | out-null
}
Create-DirectoryIfNotExists $chocolateyPath

#set up variables to add
$chocolateyExePath = Join-Path $chocolateyPath 'bin'
Expand All @@ -110,13 +105,8 @@ Creating Chocolatey NuGet folders if they do not already exist.
Create-DirectoryIfNotExists $chocolateyExePath
Create-DirectoryIfNotExists $chocolateyLibPath
Create-DirectoryIfNotExists $chocolateyInstallPath

Upgrade-OldNuGetDirectory $defaultChocolateyPathOld $chocolateyPath

Install-ChocolateyFiles $chocolateyPath

Import-Module "$chocolateyInstallPath\helpers\chocolateyInstaller.psm1"

$chocolateyExePathVariable = $chocolateyExePath.ToLower().Replace($chocolateyPath.ToLower(), "%DIR%..\").Replace("\\","\")
Install-ChocolateyBinFiles $chocolateyInstallPath $chocolateyExePath
Initialize-ChocolateyPath $chocolateyExePath $chocolateyExePathVariable
Expand Down Expand Up @@ -145,39 +135,6 @@ param(
}
}

function Upgrade-OldNuGetDirectory {
param(
[string]$chocolateyPathOld = "$sysDrive\NuGet",
[string]$chocolateyPath = "$sysDrive\NuGet"
)

if((test-path $defaultChocolateyPathOld)){
Write-Host "Upgrading `'$chocolateyPathOld`' to `'$chocolateyPath`'."

Write-Host "Copying the contents of `'$chocolateyPathOld`' to `'$chocolateyPath`'. This step may fail if you have anything in this folder running or locked."
Write-Host 'If it fails, just manually copy the rest of the items out and then delete the folder.'
Copy-Item "$($chocolateyPathOld)\*" "$chocolateyPath" -force -recurse
#write-host "Attempting to remove `'$chocolateyPathOld`'. This may fail if something in the folder is being used or locked. If it fails, same idea as above."
#Remove-Item "$($chocolateyPathOld)" -force -recurse

$chocolateyExePathOld = Join-Path $chocolateyPathOld 'bin'
$statementTerminator = ";"
#get the PATH variable
$envPath = $env:PATH
#remove the old environment variable
if ($envPath.Contains($chocolateyExePathOld)) {
Write-Host "Attempting to remove older `'$chocolateyExePathOld`' from the PATH."
$userPath = [Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)
if ($userPath.Contains($chocolateyExePathOld)) {
$userPath = $userPath.Replace("$chocolateyExePathOld","").Replace("$chocolateyExePathOld);","")
[Environment]::SetEnvironmentVariable('Path', $userPath, [System.EnvironmentVariableTarget]::User)
} else {
Write-Host "Chocolatey was not able to remove `'$chocolateyExePathOld`' automatically. It's likely in the system's path instead of the user path, but it could be due to other factors (including casing). Please manually find and remove it from either the user PATH or the machine PATH."
}
}
}
}

function Install-ChocolateyFiles {
param(
[string]$chocolateyPath = "$sysDrive\Chocolatey"
Expand Down

0 comments on commit 42524a7

Please sign in to comment.