Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (doc) update CHANGELOG/nuspec
  (GH-412) Add licensing to new Posh files
  (GH-412) Install Chocolatey Profile
  (GH-412) Tab Completion Flow / Filtering / Perf
  (GH-663) Search Order By Popularity
  (GH-663) Search by Id Starts With
  (GH-666) Setup messages as Output with color
  • Loading branch information
ferventcoder committed Mar 23, 2016
2 parents c497b4f + 652a747 commit 02c4232
Show file tree
Hide file tree
Showing 8 changed files with 286 additions and 76 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ What will be highlighted:
* Introduce managing package templates, reintroduce extensions.
* Talk about using original download file name
* Talk about the improvements in search information
* Talk about tab completion and refreshenv!
* Talk a little about what's coming with pro

### BREAKING CHANGES
Expand All @@ -33,6 +34,8 @@ For 590 - if you set a custom cache directory for downloads, it will no longer u
* [Security] Show moderation-related information in search results - see [#493](https://github.com/chocolatey/choco/issues/493)
* New Helper - Get-ToolsLocation helper (replacement for Get-BinRoot) - see [#631](https://github.com/chocolatey/choco/issues/631)
* Choco list/search should have exact filter search - see [#453](https://github.com/chocolatey/choco/issues/453)
* RefreshEnv (Refresh Environment Variables) Should also work in PowerShell - see [#664](https://github.com/chocolatey/choco/issues/664)
* Provide PowerShell tab completion for Chocolatey - see [#412](https://github.com/chocolatey/choco/issues/412)

### BUG FIXES

Expand Down Expand Up @@ -61,6 +64,8 @@ For 590 - if you set a custom cache directory for downloads, it will no longer u
* Fix: Get-ChocolateyUnzip captures files that don't belong to the package - see [#616](https://github.com/chocolatey/choco/issues/616)
* Fix: Package succeeds but software install silently fails when Install-ChocolateyInstallPackage has the wrong arguments - see [#629](https://github.com/chocolatey/choco/issues/629)
* Fix - ShimGen handling of spaces and arguments that have shimgen in them - see [#647](https://github.com/chocolatey/choco/issues/647)
* Fix - PowerShell v2 - Choco installer messages can't actually be warnings (causes FileStream errors) - see [#666](https://github.com/chocolatey/choco/issues/666)
* Fix - Installing chocolatey removes $env:PSModulePath changes for current PowerShell session - see [#295](https://github.com/chocolatey/choco/issues/295)

### IMPROVEMENTS

Expand All @@ -78,6 +83,8 @@ For 590 - if you set a custom cache directory for downloads, it will no longer u
* File description of ShimGen shims should match original as closely as possible - see [#374](https://github.com/chocolatey/choco/issues/374)
* Shim Generation should automatically detect GUI - see [#634](https://github.com/chocolatey/choco/issues/634)
* Don't show 32 bit wording unless there is explicitly both versions available - see [#642](https://github.com/chocolatey/choco/issues/642)
* Allow passing arbitrary key/value arguments to new command when generating packages from templates - see [#658](https://github.com/chocolatey/choco/issues/658)
* Choco search/list should be able to search just by Id - see [#663](https://github.com/chocolatey/choco/issues/663)
* Pro - Also check for license in User Profile location - see [#606](https://github.com/chocolatey/choco/issues/606)
* Pro - Set download cache information if available - see [#562](https://github.com/chocolatey/choco/issues/562)
* Pro - Allow commands to be added - see [#583](https://github.com/chocolatey/choco/issues/583)
Expand Down
7 changes: 7 additions & 0 deletions nuget/chocolatey/chocolatey.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ What will be highlighted:
* Introduce managing package templates, reintroduce extensions.
* Talk about using original download file name
* Talk about the improvements in search information
* Talk about tab completion and refreshenv!
* Talk a little about what's coming with pro

### BREAKING CHANGES
Expand All @@ -90,6 +91,8 @@ For 590 - if you set a custom cache directory for downloads, it will no longer u
* [Security] Show moderation-related information in search results - see [#493](https://github.com/chocolatey/choco/issues/493)
* New Helper - Get-ToolsLocation helper (replacement for Get-BinRoot) - see [#631](https://github.com/chocolatey/choco/issues/631)
* Choco list/search should have exact filter search - see [#453](https://github.com/chocolatey/choco/issues/453)
* RefreshEnv (Refresh Environment Variables) Should also work in PowerShell - see [#664](https://github.com/chocolatey/choco/issues/664)
* Provide PowerShell tab completion for Chocolatey - see [#412](https://github.com/chocolatey/choco/issues/412)

### BUG FIXES

Expand Down Expand Up @@ -118,6 +121,8 @@ For 590 - if you set a custom cache directory for downloads, it will no longer u
* Fix: Get-ChocolateyUnzip captures files that don't belong to the package - see [#616](https://github.com/chocolatey/choco/issues/616)
* Fix: Package succeeds but software install silently fails when Install-ChocolateyInstallPackage has the wrong arguments - see [#629](https://github.com/chocolatey/choco/issues/629)
* Fix - ShimGen handling of spaces and arguments that have shimgen in them - see [#647](https://github.com/chocolatey/choco/issues/647)
* Fix - PowerShell v2 - Choco installer messages can't actually be warnings (causes FileStream errors) - see [#666](https://github.com/chocolatey/choco/issues/666)
* Fix - Installing chocolatey removes $env:PSModulePath changes for current PowerShell session - see [#295](https://github.com/chocolatey/choco/issues/295)

### IMPROVEMENTS

Expand All @@ -135,6 +140,8 @@ For 590 - if you set a custom cache directory for downloads, it will no longer u
* File description of ShimGen shims should match original as closely as possible - see [#374](https://github.com/chocolatey/choco/issues/374)
* Shim Generation should automatically detect GUI - see [#634](https://github.com/chocolatey/choco/issues/634)
* Don't show 32 bit wording unless there is explicitly both versions available - see [#642](https://github.com/chocolatey/choco/issues/642)
* Allow passing arbitrary key/value arguments to new command when generating packages from templates - see [#658](https://github.com/chocolatey/choco/issues/658)
* Choco search/list should be able to search just by Id - see [#663](https://github.com/chocolatey/choco/issues/663)
* Pro - Also check for license in User Profile location - see [#606](https://github.com/chocolatey/choco/issues/606)
* Pro - Set download cache information if available - see [#562](https://github.com/chocolatey/choco/issues/562)
* Pro - Allow commands to be added - see [#583](https://github.com/chocolatey/choco/issues/583)
Expand Down
124 changes: 105 additions & 19 deletions nuget/chocolatey/tools/chocolateysetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ $sysDrive = $env:SystemDrive
$tempDir = $env:TEMP
$defaultChocolateyPathOld = "$sysDrive\Chocolatey"

$originalForegroundColor = $host.ui.RawUI.ForegroundColor

function Write-ChocolateyWarning {
param (
[string]$message = ''
)

try {
$host.ui.RawUI.ForegroundColor = "Yellow"
Write-Output "WARNING: $message"
$host.ui.RawUI.ForegroundColor = $originalForegroundColor
} catch {
Write-Output "WARNING: $message"
}
}

function Write-ChocolateyError {
try {
$host.ui.RawUI.ForegroundColor = "Red"
Write-Output "ERROR: $message"
$host.ui.RawUI.ForegroundColor = $originalForegroundColor
} catch {
Write-Output "ERROR: $message"
}
}

function Initialize-Chocolatey {
<#
.DESCRIPTION
Expand Down Expand Up @@ -76,7 +102,7 @@ Creating Chocolatey folders if they do not already exist.
"@ | Write-Output

Write-Warning "You can safely ignore errors related to missing log files when `n upgrading from a version of Chocolatey less than 0.9.9. `n 'Batch file could not be found' is also safe to ignore. `n 'The system cannot find the file specified' - also safe."
Write-ChocolateyWarning "You can safely ignore errors related to missing log files when `n upgrading from a version of Chocolatey less than 0.9.9. `n 'Batch file could not be found' is also safe to ignore. `n 'The system cannot find the file specified' - also safe."

#create the base structure if it doesn't exist
Create-DirectoryIfNotExists $chocolateyExePath
Expand All @@ -99,6 +125,7 @@ Creating Chocolatey folders if they do not already exist.
Install-ChocolateyBinFiles $chocolateyPath $chocolateyExePath
}

Add-ChocolateyProfile
Install-DotNet4IfMissing

@"
Expand Down Expand Up @@ -129,11 +156,11 @@ param(
# removing old variable
Install-ChocolateyEnvironmentVariable -variableName "$chocInstallVariableName" -variableValue $null -variableType $environmentTarget
} else {
Write-Warning "Setting ChocolateyInstall Environment Variable on USER and not SYSTEM variables.`n This is due to either non-administrator install OR the process you are running is not being run as an Administrator."
Write-ChocolateyWarning "Setting ChocolateyInstall Environment Variable on USER and not SYSTEM variables.`n This is due to either non-administrator install OR the process you are running is not being run as an Administrator."
}

Write-Output "Creating $chocInstallVariableName as an environment variable (targeting `'$environmentTarget`') `n Setting $chocInstallVariableName to `'$folder`'"
Write-Warning "It's very likely you will need to close and reopen your shell `n before you can use choco."
Write-ChocolateyWarning "It's very likely you will need to close and reopen your shell `n before you can use choco."
Install-ChocolateyEnvironmentVariable -variableName "$chocInstallVariableName" -variableValue "$folder" -variableType $environmentTarget
}

Expand All @@ -154,7 +181,7 @@ param(
Write-Debug "Ensure-UserPermissions"

if (!(Test-ProcessAdminRights)) {
Write-Warning "User is not running elevated, cannot set user permissions."
Write-ChocolateyWarning "User is not running elevated, cannot set user permissions."
return
}

Expand All @@ -176,7 +203,7 @@ param(
$acl.SetAccessRule($userAccessRule)
Set-Acl $folder $acl
} catch {
Write-Warning "Not able to set permissions for user."
Write-ChocolateyWarning "Not able to set permissions for user."
}
$ErrorActionPreference = $currentEA
}
Expand All @@ -191,9 +218,9 @@ param(

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-ChocolateyWarning "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-ChocolateyWarning "!!!! ATTN: YOU WILL NEED TO CLOSE AND REOPEN YOUR SHELL !!!!"
#-ForegroundColor Magenta -BackgroundColor Black

$chocolateyExePathOld = Join-Path $chocolateyPathOld 'bin'
Expand All @@ -206,7 +233,7 @@ param(
try {
Set-EnvironmentVariable -Name 'Path' -Value $updatedPath -Scope $_ -ErrorAction Stop
} catch {
Write-Warning "Was not able to remove the old environment variable from PATH. You will need to do this manually"
Write-ChocolateyWarning "Was not able to remove the old environment variable from PATH. You will need to do this manually"
}

}
Expand All @@ -228,7 +255,7 @@ param(
Copy-Item $_ -Destination $fileToMove -Exclude $exclude -Force -ErrorAction Stop
}
catch {
Write-Warning "Was not able to move `'$fileToMove`'. You may need to reinstall the shim"
Write-ChocolateyWarning "Was not able to move `'$fileToMove`'. You may need to reinstall the shim"
}
}
}
Expand All @@ -242,7 +269,7 @@ param(
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."
Write-ChocolateyWarning "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) {
Expand All @@ -255,7 +282,7 @@ param(
Remove-Item "$($chocolateyPathOld)" -force -recurse -ErrorAction Stop
}
catch {
Write-Warning "Was not able to remove `'$chocolateyPathOld`'. You will need to manually remove it."
Write-ChocolateyWarning "Was not able to remove `'$chocolateyPathOld`'. You will need to manually remove it."
}
}
}
Expand Down Expand Up @@ -291,7 +318,7 @@ param(
Move-Item $chocoExe "$chocoExe.old" -force -ErrorAction SilentlyContinue
}
catch {
Write-Warning "Was not able to rename `'$chocoExe`' to `'$chocoExe.old`'."
Write-ChocolateyWarning "Was not able to rename `'$chocoExe`' to `'$chocoExe.old`'."
}
}

Expand Down Expand Up @@ -350,7 +377,7 @@ param(
Write-Debug "Installing the bin file redirects"
$redirectsPath = Join-Path $chocolateyPath 'redirects'
if (!(Test-Path "$redirectsPath")) {
Write-Warning "$redirectsPath does not exist"
Write-ChocolateyWarning "$redirectsPath does not exist"
return
}

Expand All @@ -370,7 +397,7 @@ param(
Remove-Item $binFilePathRename -force -ErrorAction Stop
}
catch {
Write-Warning "Was not able to remove `'$binFilePathRename`'. This may cause errors."
Write-ChocolateyWarning "Was not able to remove `'$binFilePathRename`'. This may cause errors."
}
}
if (Test-Path ($binFilePath)) {
Expand All @@ -379,7 +406,7 @@ param(
Move-Item -path $binFilePath -destination $binFilePathRename -force -ErrorAction Stop
}
catch {
Write-Warning "Was not able to rename `'$binFilePath`' to `'$binFilePathRename`'."
Write-ChocolateyWarning "Was not able to rename `'$binFilePath`' to `'$binFilePathRename`'."
}
}

Expand All @@ -388,7 +415,7 @@ param(
Copy-Item -path $exeFilePath -destination $binFilePath -force -ErrorAction Stop
}
catch {
Write-Warning "Was not able to replace `'$binFilePath`' with `'$exeFilePath`'. You may need to do this manually."
Write-ChocolateyWarning "Was not able to replace `'$binFilePath`' with `'$exeFilePath`'. You may need to do this manually."
}

$commandShortcut = [System.IO.Path]::GetFileNameWithoutExtension("$exeFilePath")
Expand All @@ -408,7 +435,7 @@ param(
Write-Debug "Administrator installing so using Machine environment variable target instead of User."
$environmentTarget = [System.EnvironmentVariableTarget]::Machine
} else {
Write-Warning "Setting ChocolateyInstall Path on USER PATH and not SYSTEM Path.`n This is due to either non-administrator install OR the process you are running is not being run as an Administrator."
Write-ChocolateyWarning "Setting ChocolateyInstall Path on USER PATH and not SYSTEM Path.`n This is due to either non-administrator install OR the process you are running is not being run as an Administrator."
}

Install-ChocolateyPath -pathToInstall "$chocolateyExePath" -pathType $environmentTarget
Expand Down Expand Up @@ -443,6 +470,65 @@ param(
}
}

# Adapted from http://www.west-wind.com/Weblog/posts/197245.aspx
function Get-FileEncoding($Path) {
$bytes = [byte[]](Get-Content $Path -Encoding byte -ReadCount 4 -TotalCount 4)

if(!$bytes) { return 'utf8' }

switch -regex ('{0:x2}{1:x2}{2:x2}{3:x2}' -f $bytes[0],$bytes[1],$bytes[2],$bytes[3]) {
'^efbbbf' { return 'utf8' }
'^2b2f76' { return 'utf7' }
'^fffe' { return 'unicode' }
'^feff' { return 'bigendianunicode' }
'^0000feff' { return 'utf32' }
default { return 'ascii' }
}
}

function Add-ChocolateyProfile {
try {
$profileFile = "$profile"
$profileDirectory = (Split-Path -Parent $profileFile)

if (!(Test-Path($profileDirectory))) {
New-Item "$profileDirectory" -Type Directory -Force -ErrorAction SilentlyContinue | Out-Null
}

if (!(Test-Path($profileFile))) {
"" | Out-File $profileFile -Encoding UTF8

}

$profileInstall = @'
# Chocolatey profile
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
'@

$chocoProfileSearch = '$ChocolateyProfile'
if(Select-String -Path $profileFile -Pattern $chocoProfileSearch -Quiet -SimpleMatch) {
Write-Debug "Chocolatey profile is already installed."
return
}

Write-Output 'Adding Chocolatey to the profile. This will provide tab completion, refreshenv, etc.'
$profileInstall | Out-File $profileFile -Append -Encoding (Get-FileEncoding $profileFile)
Write-ChocolateyWarning 'Chocolatey profile installed. Reload your profile - type . $profile'

if ($PSVersionTable.PSVersion.Major -lt 3) {
Write-ChocolateyWarning "Tab completion does not currently work in PowerShell v2. `n Please upgrade to a more recent version of PowerShell to take advantage of tab completion."
#Write-ChocolateyWarning "To load tab expansion, you need to install PowerTab. `n See https://powertab.codeplex.com/ for details."
}

} catch {
Write-ChocolateyWarning "Unable to add Chocolatey to the profile. You will need to do it manually. Error was '$_'"
}
}

$netFx4InstallTries = 0

function Install-DotNet4IfMissing {
Expand Down Expand Up @@ -488,10 +574,10 @@ param(
$s.WaitForExit();
if ($s.ExitCode -ne 0 -and $s.ExitCode -ne 3010) {
if ($netFx4InstallTries -eq 2) {
Write-Error ".NET Framework install failed with exit code `'$($s.ExitCode)`'. `n This will cause the rest of the install to fail."
Write-ChocolateyError ".NET Framework install failed with exit code `'$($s.ExitCode)`'. `n This will cause the rest of the install to fail."
throw "Error installing .NET Framework 4.0 (exit code $($s.ExitCode)). `n Please install the .NET Framework 4.0 manually and then try to install Chocolatey again. `n Download at `'$NetFx4Url`'"
} else {
Write-Warning "First try of .NET framework install failed with exit code `'$($s.ExitCode)`'. Trying again."
Write-ChocolateyWarning "First try of .NET framework install failed with exit code `'$($s.ExitCode)`'. Trying again."
Install-DotNet4IfMissing $true
}
}
Expand Down
Loading

0 comments on commit 02c4232

Please sign in to comment.