Unverified Commit 550df235 authored by Tim Smith's avatar Tim Smith Committed by GitHub
Browse files

Merge pull request #133 from tas50/master

Require Chef 12.7 and remove the legacy chocolatey resource
parents 566b66d2 e72f33c4
......@@ -9,7 +9,7 @@ spec/reports
test/tmp
test/version_tmp
tmp
_Store
*_Store
*~
*#
.#*
......@@ -42,8 +42,6 @@ vendor/
.coverage/
.zero-knife.rb
Policyfile.lock.json
Cheffile.lock
.librarian/
# vagrant stuff
.vagrant/
......
......@@ -19,7 +19,6 @@ suites:
require_chef_omnibus: 12.19.36
run_list:
- recipe[chocolatey::default]
- recipe[chocolatey_test::default]
attributes:
chocolatey:
install_vars:
......
......@@ -19,7 +19,6 @@ suites:
require_chef_omnibus: 12.19.36
run_list:
- recipe[chocolatey::default]
- recipe[chocolatey_test::default]
attributes:
chocolatey:
install_vars:
......
......@@ -22,5 +22,4 @@ script:
- /opt/chefdk/embedded/bin/chef --version
- /opt/chefdk/embedded/bin/cookstyle --version
- /opt/chefdk/embedded/bin/foodcritic --version
- /opt/chefdk/bin/chef exec rake
- /opt/chefdk/bin/chef exec delivery local all
source 'https://supermarket.chef.io'
metadata
group :integration do
cookbook 'chocolatey_specs', path: './spec/cookbooks/chocolatey_specs'
cookbook 'chocolatey_test', path: './test/cookbooks/chocolatey_test'
end
# This gemfile provides additional gems for testing and releasing this cookbook
# It is meant to be installed on top of ChefDK which provides the majority
# of the necessary gems for testing this cookbook
#
# Run 'chef exec bundle install' to install these dependencies
source 'https://rubygems.org'
gem 'cookstyle'
gem 'foodcritic'
gem 'rake'
gem 'stove'
[![Cookbook Version](https://img.shields.io/cookbook/v/chocolatey.svg)](https://supermarket.getchef.com/cookbooks/chocolatey) [![Build Status](http://img.shields.io/travis/chocolatey/chocolatey-cookbook/master.svg)](https://travis-ci.org/chocolatey/chocolatey-cookbook)
# chocolatey Cookbook
# Description
[![Cookbook Version](https://img.shields.io/cookbook/v/chocolatey.svg)](https://supermarket.getchef.com/cookbooks/chocolatey) [![Build Status](http://img.shields.io/travis/chocolatey/chocolatey-cookbook/master.svg)](https://travis-ci.org/chocolatey/chocolatey-cookbook)
Install Chocolatey with the default recipe and manage packages with a handy resource/provider.
# Requirements
## Requirements
## Platform:
### Platform
- Windows
- Chef 11.6 or greater
## Cookbooks:
### Chef
- windows (~> 1.38)
- 12.7 or greater
# Notes
## Notes
As of Chocolatey version [0.9.8.24](https://github.com/chocolatey/chocolatey/blob/master/CHANGELOG.md#09824-july-3-2014) the install directory for Chocolatey has changed from `C:\Chocolatey` to `C:\ProgramData\Chocolatey`.
More information can be gotten from the [Chocolateywiki](https://github.com/chocolatey/chocolatey/wiki/DefaultChocolateyInstallReasoning).
# Attributes
## Attributes
All attributes below are pre-pended with `node['chocolatey']`
......@@ -34,67 +33,11 @@ Attribute | Description
`['install_vars']['chocolateyVersion']` | Version of Chocolatey to install, e.g. '0.9.9.11' | String | nil (download latest version)
`['install_vars']['chocolateyDownloadUrl']` | Chocolatey .nupkg file URL. Use this if you host an internal copy of the chocolatey.nupkg | String | <https://chocolatey.org/api/v2/package/chocolatey> (download from chocolatey.org)
# Recipes
- chocolatey::default
# Resources
- [chocolatey](#chocolatey)
## chocolatey
**Note:** On chef client versions 12.7.0 and greater, Use the `chocolatey_package` resource instead.
### Actions
- install: Install a chocolatey package (default)
- remove: Uninstall a chocolatey package
- upgrade: Update a chocolatey package
### Resource Properties
- package: package to manage (default name)
- source: The source to find the package(s) to install
- version: The version of the package to use.
- args: arguments to the installation.
- options: Hash of additional options to be sent to `choco.exe`
# Examples
```ruby
include_recipe 'chocolatey'
%w{sysinternals 7zip notepadplusplus GoogleChrome Console2}.each do |pack|
chocolatey pack
end
%w{bash openssh grep}.each do |pack|
chocolatey pack do
source 'cygwin'
end
end
chocolatey 'git.install' do
options ({ 'params' => "'/GitOnlyOnPath'" })
end
chocolatey 'wireshark' do
version '1.12.6'
action :install
end
chocolatey "some_private_secure_package" do
source "https://some.proget/feed"
options ({'u' => 'username', 'p' => 'password'})
end
chocolatey 'DotNet4.5'
## Recipes
chocolatey 'PowerShell'
```
- chocolatey::default - installs Chocolatey
# License and Maintainer
## License and Maintainer
Maintainer:: Guilhem Lettron ([guilhem@lettron.fr](mailto:guilhem@lettron.fr))
......
#!/usr/bin/env rake
# Style tests. cookstyle (rubocop) and Foodcritic
namespace :style do
begin
require 'cookstyle'
require 'rubocop/rake_task'
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
begin
require 'foodcritic'
desc 'Run Chef style checks'
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any'],
}
end
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end
desc 'Run all style checks'
task style: ['style:chef', 'style:ruby']
# ChefSpec
begin
require 'rspec/core/rake_task'
desc 'Run ChefSpec examples'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
# Integration tests. Kitchen.ci
namespace :integration do
begin
require 'kitchen/rake_tasks'
desc 'Run kitchen integration tests'
Kitchen::RakeTasks.new
rescue LoadError, StandardError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end
namespace :maintain do
begin
require 'stove/rake_task'
Stove::RakeTask.new
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV['CI']
end
end
# default
task default: %w(style spec)
......@@ -32,7 +32,7 @@ build_script:
test_script:
- c:\opscode\chefdk\bin\cookstyle --version
- c:\opscode\chefdk\bin\chef.bat exec foodcritic --version
- c:\opscode\chefdk\bin\chef.bat exec rake
- c:\opscode\chefdk\bin\chef.bat exec delivery local all
- c:\opscode\chefdk\bin\chef.bat exec kitchen verify
deploy: off
......@@ -82,17 +82,11 @@ Berksfile.lock
cookbooks/*
tmp
# Policyfile #
##############
Policyfile.rb
Policyfile.lock.json
# Cookbooks #
#############
CONTRIBUTING*
CHANGELOG*
TESTING*
MAINTAINERS.toml
# Strainer #
############
......
# =====================================================================
# Copyright 2011 - Present RealDimensions Software, LLC, and the
# Copyright 2017 Chocolatey Software, Inc, and the
# original authors/contributors from ChocolateyGallery
# Copyright 2011 - 2017 RealDimensions Software, LLC, and the
# original authors/contributors from ChocolateyGallery
# at https://github.com/chocolatey/chocolatey.org
#
......@@ -44,10 +46,14 @@ if ($env:TEMP -eq $null) {
}
$chocTempDir = Join-Path $env:TEMP "chocolatey"
$tempDir = Join-Path $chocTempDir "chocInstall"
if (![System.IO.Directory]::Exists($tempDir)) {[System.IO.Directory]::CreateDirectory($tempDir)}
if (![System.IO.Directory]::Exists($tempDir)) {[void][System.IO.Directory]::CreateDirectory($tempDir)}
$file = Join-Path $tempDir "chocolatey.zip"
# PowerShell v2/3 caches the output stream. Then it throws errors due # to the FileStream not being what is expected. Fixes "The OS handle's # position is not what FileStream expected. Do not use a handle # simultaneously in one FileStream and in Win32 code or another # FileStream."
# PowerShell v2/3 caches the output stream. Then it throws errors due
# to the FileStream not being what is expected. Fixes "The OS handle's
# position is not what FileStream expected. Do not use a handle
# simultaneously in one FileStream and in Win32 code or another
# FileStream."
function Fix-PowerShellOutputRedirectionBug {
$poshMajorVerion = $PSVersionTable.PSVersion.Major
......@@ -179,8 +185,8 @@ $useWindowsCompression = $env:chocolateyUseWindowsCompression
if ($useWindowsCompression -ne $null -and $useWindowsCompression -eq 'true') {
Write-Output 'Using built-in compression to unzip'
$unzipMethod = 'builtin'
} else {
Write-Output "Downloading 7-Zip commandline tool prior to extraction."
} elseif (-Not (Test-Path ($7zaExe))) {
Write-Output "Downloading 7-Zip commandline tool prior to extraction."
# download 7zip
Download-File 'https://chocolatey.org/7za.exe' "$7zaExe"
}
......@@ -244,7 +250,11 @@ Write-Output 'Ensuring chocolatey commands are on the path'
$chocInstallVariableName = "ChocolateyInstall"
$chocoPath = [Environment]::GetEnvironmentVariable($chocInstallVariableName)
if ($chocoPath -eq $null -or $chocoPath -eq '') {
$chocoPath = 'C:\ProgramData\Chocolatey'
$chocoPath = "$env:ALLUSERSPROFILE\Chocolatey"
}
if (!(Test-Path ($chocoPath))) {
$chocoPath = "$env:SYSTEMDRIVE\ProgramData\Chocolatey"
}
$chocoExePath = Join-Path $chocoPath 'bin'
......@@ -260,10 +270,10 @@ if (![System.IO.Directory]::Exists($chocoPkgDir)) { [System.IO.Directory]::Creat
Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue
# SIG # Begin signature block
# MIINWwYJKoZIhvcNAQcCoIINTDCCDUgCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# MIINVQYJKoZIhvcNAQcCoIINRjCCDUICAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBlBAdKza9HJh5y
# SStdXAQqtPBJqqekYVu4kBAl52mATaCCCngwggUwMIIEGKADAgECAhAECRgbX9W7
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBtI1XhNa+BTJDA
# Udd7cvDCY121zDB7LmEXLgQMpQmPnqCCCnIwggUwMIIEGKADAgECAhAECRgbX9W7
# ZnVTQ7VvlVAIMA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNVBAYTAlVTMRUwEwYDVQQK
# EwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5jb20xJDAiBgNV
# BAMTG0RpZ2lDZXJ0IEFzc3VyZWQgSUQgUm9vdCBDQTAeFw0xMzEwMjIxMjAwMDBa
......@@ -291,45 +301,45 @@ Copy-Item "$file" "$nupkg" -Force -ErrorAction SilentlyContinue
# r7VRwo0kriTGxycqoSkoGjpxKAI8LpGjwCUR4pwUR6F6aGivm6dcIFzZcbEMj7uo
# +MUSaJ/PQMtARKU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fLetknY2Z5r+b1+eu
# camDGbsbstoG
# SIG # End signature block
#
# Cookbook Name:: chocolatey
# Library:: matchers
#
# These can be used when testing for chefspec.
# Example:
# Recipe:
# chocolatey 'cool_package'
# ChefSpec:
# expect(chef_run).to install_chocolatey('cool_package')
#
if defined?(ChefSpec)
ChefSpec.define_matcher(:chocolatey)
def install_chocolatey(name)
ChefSpec::Matchers::ResourceMatcher.new(:chocolatey, :install, name)
end
def upgrade_chocolatey(name)
ChefSpec::Matchers::ResourceMatcher.new(:chocolatey, :upgrade, name)
end
def remove_chocolatey(name)
ChefSpec::Matchers::ResourceMatcher.new(:chocolatey, :remove, name)
end
end
......@@ -6,11 +6,9 @@ description 'Install chocolatey and packages on Windows'
long_description 'Installs the Chocolatey package manager for Windows and provides a Chef resource for installing nuget packages from https://chocolatey.org/'
version '1.2.1'
source_url 'https://github.com/chocolatey/chocolatey-cookbook' if defined?(:source_url)
issues_url 'https://github.com/chocolatey/chocolatey-cookbook/issues' if defined?(:issues_url)
source_url 'https://github.com/chocolatey/chocolatey-cookbook'
issues_url 'https://github.com/chocolatey/chocolatey-cookbook/issues'
supports 'windows'
depends 'windows', '>= 1.38'
chef_version '>= 11.6.0' if respond_to?(:chef_version)
chef_version '>= 12.7' if respond_to?(:chef_version)
#
# Provider:: chocolatey
# Author:: Guilhem Lettron <guilhem.lettron@youscribe.com>
#
# Copyright 20012, Societe Publica.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Prepending with '::' to prevent breaks in older versions of chef
include ::Chocolatey::Helpers
use_inline_resources
# Support whyrun
def whyrun_supported?
true
end
def load_current_resource
@current_resource = Chef::Resource::Chocolatey.new(@new_resource.name)
@current_resource.name(@new_resource.name)
@current_resource.version(@new_resource.version)
@current_resource.source(@new_resource.source) unless @new_resource.source.nil?
@current_resource.args(@new_resource.args) unless @new_resource.args.nil?
@current_resource.options(@new_resource.options)
@current_resource.package(@new_resource.package)
@current_resource.exists = package_exists?(@current_resource.package, @current_resource.version)
# @current_resource.installed = true if package_installed?(@current_resource.package)
end
action :install do
if @current_resource.exists
Chef::Log.info "#{@current_resource.package} already installed - nothing to do."
else
if @current_resource.version
install_version(@current_resource.package, @current_resource.version)
else
install(@current_resource.package)
end
adjust_path(@current_resource.package)
end
end
def adjust_path(name)
ruby_block "track-path-#{name}" do
block { ENV['PATH'] = environment_path(ENV['PATH']) }
end
end
action :upgrade do
package_name = @current_resource.package
if upgradeable?(package_name)
upgrade(package_name)
else
Chef::Log.info("Package #{@current_resource} already to latest version")
end
end
action :remove do
if @current_resource.exists
package_name = @current_resource.package
converge_by("uninstall package #{package_name}") do
execute "uninstall package #{package_name}" do
command "#{chocolatey_executable} uninstall -y #{package_name}"
end
end
else
Chef::Log.info "#{@current_resource} not installed - nothing to do."
end
end
def cmd_args
output = ''
output += " --source #{@current_resource.source}" if @current_resource.source
output += " --installargs '#{@current_resource.args}'" unless @current_resource.args.to_s.empty?
@current_resource.options.each do |k, v|
output += " -#{k}"
output += " #{v}" if v
end
output
end
def package_installed?(name)
package_exists?(name, nil)
end
def package_exists?(name, version)
cmd = Mixlib::ShellOut.new("#{chocolatey_executable} list -l -r #{name}")
cmd.run_command
software = cmd.stdout.split("\r\n").each_with_object({}) do |s, h|
v, k = s.split('|')
h[String(v).strip.downcase] = String(k).strip.downcase
h
end
if version
installed = software[name.downcase]
installed && installed.downcase.casecmp(version.downcase) == 0
else
!software[name.downcase].nil?
end
end
def upgradeable?(name)
return false unless @current_resource.exists
unless package_installed?(name)
Chef::Log.debug("Package isn't installed... we can upgrade it!")
return true
end
Chef::Log.debug("Checking to see if this chocolatey package is installed/upgradable: '#{name}'")
cmd = Mixlib::ShellOut.new("#{chocolatey_executable} upgrade -r --noop #{cmd_args} #{name}")
cmd.run_command
result = cmd.stdout.chomp
package_name, current_version, updated_version, is_pinned = result.downcase.split('|')
raise "Wrong package name #{name} != #{package_name}" if package_name != name
current_version != updated_version && is_pinned != 'true'
end
def install(name)
execute "install package #{name}" do
command "#{chocolatey_executable} install -y #{cmd_args} #{name}"
end
end
def upgrade(name)
execute "updating #{name} to latest" do
command "#{chocolatey_executable} upgrade -y #{cmd_args} #{name}"
end
end
def install_version(name, version)
execute "install package #{name} version #{version}" do
command "#{chocolatey_executable} install -y -version #{version} #{cmd_args} #{name}"
end
end
......@@ -18,7 +18,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
unless node['platform_family'] == 'windows'
unless platform_family?('windows')
return "Chocolatey install not supported on #{node['platform_family']}"
end
......
actions :install, :remove, :upgrade
default_action :install
attribute :package, kind_of: String, name_attribute: true
attribute :source, kind_of: [String, nil], default: nil
attribute :version, kind_of: [String]
attribute :args, kind_of: [String, nil], default: nil
attribute :options, kind_of: Hash, default: {}