Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (version) 0.9.9-rc7
  (GH-7)(GH-91) upgrade should work with posh v2
  (GH-7) Do not reinstall bin files if no old path
  (GH-7) MOAR debug in install script
  (doc) Core lib is preview
  (GH-82) Do not state name of user
  • Loading branch information
ferventcoder committed Feb 13, 2015
2 parents 018c2be + 95c6a3f commit 2d1c0b4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .uppercut
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<property name="version.major" value="0" overwrite="false" />
<property name="version.minor" value="9" overwrite="false" />
<property name="version.patch" value="9" overwrite="false" />
<property name="version.nuget.prerelease" value="rc6" overwrite="false" />
<property name="version.nuget.prerelease" value="rc7" overwrite="false" />
<property name="version.use.build_date" value="false" overwrite="false" />
<property name="assembly.description" value="${project.name} is a product of ${company.name} - All Rights Reserved." overwrite="false" />
<property name="assembly.copyright" value="Copyright © 2011 - Present, ${company.name} - All Rights Reserved." overwrite="false" />
Expand Down
2 changes: 1 addition & 1 deletion nuget/chocolatey.lib/chocolatey.lib.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata>
<id>chocolatey.lib</id>
<title>Chocolatey Core</title>
<title>Chocolatey Core [PREVIEW]</title>
<version>0.9.9</version>
<authors>Rob Reynolds, The Chocolatey Team</authors>
<owners>Rob Reynolds</owners>
Expand Down
49 changes: 42 additions & 7 deletions nuget/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function Initialize-Chocolatey {
param(
[Parameter(Mandatory=$false)][string]$chocolateyPath = ''
)
Write-Debug "Initialize-Chocolatey"

if ($env:ChocolateyEnvironmentDebug -eq 'true') {
$debugMode = $true
}
Expand Down Expand Up @@ -105,7 +107,7 @@ Creating Chocolatey folders if they do not already exist.
$realModule = Join-Path $chocolateyPath "helpers\chocolateyInstaller.psm1"
Import-Module "$realModule" -Force

if (-not $allowInsecureRootInstall) {
if (-not $allowInsecureRootInstall -and (Test-Path($defaultChocolateyPathOld))) {
Upgrade-OldChocolateyInstall $defaultChocolateyPathOld $chocolateyPath
Install-ChocolateyBinFiles $chocolateyPath $chocolateyExePath
}
Expand All @@ -127,6 +129,8 @@ function Set-ChocolateyInstallFolder {
param(
[string]$folder
)
Write-Debug "Set-ChocolateyInstallFolder"

$environmentTarget = [System.EnvironmentVariableTarget]::User
# removing old variable
Install-ChocolateyEnvironmentVariable -variableName "$chocInstallVariableName" -variableValue $null -variableType $environmentTarget
Expand All @@ -145,17 +149,21 @@ param(
}

function Get-ChocolateyInstallFolder(){
Write-Debug "Get-ChocolateyInstallFolder"
[Environment]::GetEnvironmentVariable($chocInstallVariableName)
}

function Create-DirectoryIfNotExists($folderName){
Write-Debug "Create-DirectoryIfNotExists"
if (![System.IO.Directory]::Exists($folderName)) { [System.IO.Directory]::CreateDirectory($folderName) | Out-Null }
}

function Ensure-UserPermissions {
param(
[string]$folder
)
Write-Debug "Ensure-UserPermissions"

if (!(Test-ProcessAdminRights)) {
Write-Warning "User is not running elevated, cannot set user permissions."
return
Expand All @@ -175,7 +183,7 @@ param(
$userAccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($currentUser.Name, $rights, "Allow")

# this is idempotent
Write-Output "Adding Modify permission for $($currentUser.Name) to '$folder'"
Write-Output "Adding Modify permission for current user to '$folder'"
$acl.SetAccessRuleProtection($false,$true)
$acl.SetAccessRule($userAccessRule)
Set-Acl $folder $acl
Expand All @@ -190,11 +198,13 @@ param(
[string]$chocolateyPath = "$($env:ALLUSERSPROFILE)\chocolatey"
)

Write-Debug "Upgrade-OldChocolateyInstall"

if (Test-Path $chocolateyPathOld) {
Write-Output "Attempting to upgrade `'$chocolateyPathOld`' to `'$chocolateyPath`'."
Write-Warning "Copying the contents of `'$chocolateyPathOld`' to `'$chocolateyPath`'. `n This step may fail if you have anything in this folder running or locked."
Write-Output 'If it fails, just manually copy the rest of the items out and then delete the folder.'
Write-Warning "!!!! ATTN: YOU WILL NEED TO CLOSE AND REOPEN YOUR SHELL !!!!"
Write-Host "!!!! ATTN: YOU WILL NEED TO CLOSE AND REOPEN YOUR SHELL !!!!" -ForegroundColor Magenta -BackgroundColor Black

$chocolateyExePathOld = Join-Path $chocolateyPathOld 'bin'
'Machine', 'User' |
Expand All @@ -215,7 +225,7 @@ param(
Copy-Item "$chocolateyPathOld\lib\*" "$chocolateyPath\lib" -force -recurse

$from = "$chocolateyPathOld\bin"
$to ="$chocolateyPath\bin"
$to = "$chocolateyPath\bin"
$exclude = @("choco.exe", "chocolatey.exe", "cinst.exe", "clist.exe", "cpack.exe", "cpush.exe", "cuninst.exe", "cup.exe", "cver.exe", "RefreshEnv.cmd")
Get-ChildItem -Path $from -recurse -Exclude $exclude |
% {
Expand All @@ -239,12 +249,20 @@ function Remove-OldChocolateyInstall {
param(
[string]$chocolateyPathOld = "$sysDrive\Chocolatey"
)
Write-Debug "Remove-OldChocolateyInstall"

if (Test-Path $chocolateyPathOld) {
Write-Warning "This action will result in Log Errors, you can safely ignore those. `n You may need to finish removing '$chocolateyPathOld' manually."
try {
Get-ChildItem -Path "$chocolateyPathOld" | % {
if (Test-Path $_.FullName) {
Write-Debug "Removing $_ unless matches .log"
Remove-Item $_.FullName -exclude *.log -recurse -force -ErrorAction SilentlyContinue
}
}

Write-Output "Attempting to remove `'$chocolateyPathOld`'. This may fail if something in the folder is being used or locked."
Remove-Item "$($chocolateyPathOld)" -force -recurse -ErrorAction Continue
Remove-Item "$($chocolateyPathOld)" -force -recurse -ErrorAction Stop
}
catch {
Write-Warning "Was not able to remove `'$chocolateyPathOld`'. You will need to manually remove it."
Expand All @@ -256,11 +274,19 @@ function Install-ChocolateyFiles {
param(
[string]$chocolateyPath
)
Write-Debug "Install-ChocolateyFiles"

Write-Debug "Removing install files in chocolateyInstall, helpers, redirects, and tools"
"$chocolateyPath\chocolateyInstall", "$chocolateyPath\helpers", "$chocolateyPath\redirects", "$chocolateyPath\tools" | % {
#Write-Debug "Checking path $_"
if (Test-Path $_) {
Remove-Item $_ -exclude '*.log' -recurse -force -ErrorAction SilentlyContinue
Get-ChildItem -Path "$_" | % {
#Write-Debug "Checking child path $_ ($($_.FullName))"
if (Test-Path $_.FullName) {
Write-Debug "Removing $_ unless matches .log"
Remove-Item $_.FullName -exclude *.log -recurse -force -ErrorAction SilentlyContinue
}
}
}
}

Expand Down Expand Up @@ -295,6 +321,7 @@ function Ensure-ChocolateyLibFiles {
param(
[string]$chocolateyLibPath
)
Write-Debug "Ensure-ChocolateyLibFiles"
$chocoPkgDirectory = Join-Path $chocolateyLibPath 'chocolatey'

if ( -not (Test-Path("$chocoPkgDirectory\chocolatey.nupkg")) ) {
Expand All @@ -318,8 +345,14 @@ param(
[string] $chocolateyPath,
[string] $chocolateyExePath
)
Write-Debug "Install-ChocolateyBinFiles"
Write-Debug "Installing the bin file redirects"
$redirectsPath = Join-Path $chocolateyPath 'redirects'
if (!(Test-Path "$redirectsPath")) {
Write-Warning "$redirectsPath does not exist"
return
}

$exeFiles = Get-ChildItem "$redirectsPath" -include @("*.exe","*.cmd") -recurse
foreach ($exeFile in $exeFiles) {
$exeFilePath = $exeFile.FullName
Expand Down Expand Up @@ -367,6 +400,7 @@ param(
[string]$chocolateyExePath = "$($env:ALLUSERSPROFILE)\chocolatey\bin",
[string]$chocolateyExePathVariable = "%$($chocInstallVariableName)%\bin"
)
Write-Debug "Initialize-ChocolateyPath"
Write-Debug "Initializing Chocolatey Path if required"
$environmentTarget = [System.EnvironmentVariableTarget]::User
if (Test-ProcessAdminRights) {
Expand All @@ -384,7 +418,7 @@ param(
[string]$chocolateyExePath = "$($env:ALLUSERSPROFILE)\chocolatey\bin",
[string]$chocolateyExePathVariable = "%$($chocInstallVariableName)%\bin"
)

Write-Debug "Process-ChocolateyBinFiles"
$processedMarkerFile = Join-Path $chocolateyExePath '_processed.txt'
if (!(test-path $processedMarkerFile)) {
$files = get-childitem $chocolateyExePath -include *.bat -recurse
Expand All @@ -409,6 +443,7 @@ param(
}

function Install-DotNet4IfMissing {
Write-Debug "Install-DotNet4IfMissing"
if ([IntPtr]::Size -eq 8) {$fx="framework64"} else {$fx="framework"}

Write-Debug "Installing .NET Framework 4.0 if it is missing"
Expand Down

0 comments on commit 2d1c0b4

Please sign in to comment.