Skip to content

Commit

Permalink
Implement new chocolatey install script. Update Documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettrowell committed Oct 18, 2024
1 parent 0b98689 commit cd657ec
Show file tree
Hide file tree
Showing 6 changed files with 668 additions and 201 deletions.
47 changes: 41 additions & 6 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ The following parameters are available in the `chocolatey` class:
* [`log_output`](#-chocolatey--log_output)
* [`chocolatey_version`](#-chocolatey--chocolatey_version)
* [`install_proxy`](#-chocolatey--install_proxy)
* [`install_ignore_proxy`](#-chocolatey--install_ignore_proxy)
* [`install_proxy_user`](#-chocolatey--install_proxy_user)
* [`install_proxy_password`](#-chocolatey--install_proxy_password)
* [`install_tempdir`](#-chocolatey--install_tempdir)

##### <a name="-chocolatey--choco_install_location"></a>`choco_install_location`

Expand Down Expand Up @@ -127,11 +131,9 @@ Default value: `false`
Data type: `String[1]`

Specifies the source file for 7za.exe.
Supports all sources supported by Puppet's file resource. You should use
a 32bit binary for compatibility.
Defaults to 'https://chocolatey.org/7za.exe'.
Defaults to 'https://community.chocolatey.org/7za.exe'.

Default value: `'https://chocolatey.org/7za.exe'`
Default value: `'https://community.chocolatey.org/7za.exe'`

##### <a name="-chocolatey--choco_install_timeout_seconds"></a>`choco_install_timeout_seconds`

Expand All @@ -150,9 +152,9 @@ Data type: `Stdlib::Filesource`
A url that will return
`chocolatey.nupkg`. This must be a url, but not necessarily an OData feed.
Any old url location will work. Defaults to
`'https://chocolatey.org/api/v2/package/chocolatey/'`.
`'https://community.chocolatey.org/api/v2/package/chocolatey/'`.

Default value: `'https://chocolatey.org/api/v2/package/chocolatey/'`
Default value: `'https://community.chocolatey.org/api/v2/package/chocolatey/'`

##### <a name="-chocolatey--enable_autouninstaller"></a>`enable_autouninstaller`

Expand Down Expand Up @@ -194,6 +196,39 @@ Proxy server to use to use for installation of chocolatey itself or

Default value: `undef`

##### <a name="-chocolatey--install_ignore_proxy"></a>`install_ignore_proxy`

Data type: `Optional[Boolean]`

If set to 'true' the installation script will ignore
the configured 'install_proxy'

Default value: `undef`

##### <a name="-chocolatey--install_proxy_user"></a>`install_proxy_user`

Data type: `Optional[String[1]]`

The username to use when using a proxy that requires authentication.

Default value: `undef`

##### <a name="-chocolatey--install_proxy_password"></a>`install_proxy_password`

Data type: `Optional[Sensitive]`

The password to use when using a proxy that requires authentication.

Default value: `undef`

##### <a name="-chocolatey--install_tempdir"></a>`install_tempdir`

Data type: `Optional[Stdlib::Windowspath]`

The temporary directory Chocolatey extracts to when installing.

Default value: `undef`

## Resource types

### <a name="chocolateyconfig"></a>`chocolateyconfig`
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/chocolatey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def self.listcmd
args << '-lo'
args << '-r' if compiled_choco?

["\"command(:chocolatey)\"", *args]
["\"#{command(:chocolatey)}\"", *args]
end

def self.instances
Expand Down
38 changes: 25 additions & 13 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
# Defaults to `false`.
#
# @param [String] seven_zip_download_url Specifies the source file for 7za.exe.
# Supports all sources supported by Puppet's file resource. You should use
# a 32bit binary for compatibility.
# Defaults to 'https://chocolatey.org/7za.exe'.
# Defaults to 'https://community.chocolatey.org/7za.exe'.
#
# @param [Integer] choco_install_timeout_seconds How long in seconds should
# be allowed for the install of Chocolatey (including .NET Framework 4 if
Expand All @@ -56,7 +54,7 @@
# @param [String] chocolatey_download_url A url that will return
# `chocolatey.nupkg`. This must be a url, but not necessarily an OData feed.
# Any old url location will work. Defaults to
# `'https://chocolatey.org/api/v2/package/chocolatey/'`.
# `'https://community.chocolatey.org/api/v2/package/chocolatey/'`.
#
# @param [Boolean] enable_autouninstaller [Deprecated] - Should auto
# uninstaller be turned on? Auto uninstaller is what allows Chocolatey to
Expand All @@ -73,16 +71,30 @@
#
# @param install_proxy Proxy server to use to use for installation of chocolatey itself or
# `undef` to not use a proxy
#
# @param [Boolean] install_ignore_proxy If set to 'true' the installation script will ignore
# the configured 'install_proxy'
#
# @param install_proxy_user The username to use when using a proxy that requires authentication.
#
# @param install_proxy_password The password to use when using a proxy that requires authentication.
#
# @param install_tempdir The temporary directory Chocolatey extracts to when installing.
#
class chocolatey (
Stdlib::Windowspath $choco_install_location = $facts['choco_install_path'],
Boolean $use_7zip = false,
String[1] $seven_zip_download_url = 'https://chocolatey.org/7za.exe',
Integer $choco_install_timeout_seconds = 1500,
Stdlib::Filesource $chocolatey_download_url = 'https://chocolatey.org/api/v2/package/chocolatey/',
Boolean $enable_autouninstaller = true,
Boolean $log_output = false,
String[1] $chocolatey_version = $facts['chocolateyversion'],
Optional[String[1]] $install_proxy = undef,
Stdlib::Windowspath $choco_install_location = $facts['choco_install_path'],
Boolean $use_7zip = false,
String[1] $seven_zip_download_url = 'https://community.chocolatey.org/7za.exe',
Integer $choco_install_timeout_seconds = 1500,
Stdlib::Filesource $chocolatey_download_url = 'https://community.chocolatey.org/api/v2/package/chocolatey/',
Boolean $enable_autouninstaller = true,
Boolean $log_output = false,
String[1] $chocolatey_version = $facts['chocolateyversion'],
Optional[String[1]] $install_proxy = undef,
Optional[Boolean] $install_ignore_proxy = undef,
Optional[String[1]] $install_proxy_user = undef,
Optional[Sensitive] $install_proxy_password = undef,
Optional[Stdlib::Windowspath] $install_tempdir = undef,
) {
class { 'chocolatey::install': }
-> class { 'chocolatey::config': }
Expand Down
56 changes: 28 additions & 28 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
class chocolatey::install {
assert_private()

$install_proxy = $chocolatey::install_proxy
$_install_proxy = $install_proxy ? {
undef => '$false',
default => "'${install_proxy}'",
}
$_download_url = $chocolatey::chocolatey_download_url
$seven_zip_download_url = $chocolatey::seven_zip_download_url
$seven_zip_exe = "${facts['choco_temp_dir']}\\7za.exe"
$_download_url = $chocolatey::chocolatey_download_url

# lint:ignore:only_variable_string
if "${_download_url}" =~ /^http(s)?:\/\/.*api\/v2\/package.*\/$/ and "${chocolatey::chocolatey_version}" =~ /\d+\./ {
Expand All @@ -22,40 +15,47 @@
}
# lint:endignore

if $chocolatey::use_7zip {
$unzip_type = '7zip'
file { $seven_zip_exe:
ensure => file,
source => $seven_zip_download_url,
replace => false,
mode => '0755',
before => Exec['install_chocolatey_official'],
}
} else {
$unzip_type = 'windows'
}

registry_value { 'ChocolateyInstall environment value':
ensure => present,
path => 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\ChocolateyInstall',
type => 'string',
data => $chocolatey::choco_install_location,
}

# New install script exclusively uses environment variables in powershell.
# Filter out undef values and build an array of ['key=value'] to be passed in to the execs environment attribute.
# The 'chocolateyVersion' can also be passed to the install script. Instead only pass an explicit 'chocolateyDownloadUrl' that we
# already build correctly if $chocolatey::chocolatey_version is set. This allows for a custom $chocolatey:chocolatey_download_url
# to be used with no modification to the script. If the version is unset, the default behavior remains the same which is to attempt
# to install the latest available version.
$install_parameters = {
'download_url' => $download_url,
'unzip_type' => $unzip_type,
'_install_proxy' => $_install_proxy,
'seven_zip_exe' => $seven_zip_exe,
}
'ChocolateyInstall' => $chocolatey::choco_install_location,
'chocolateyDownloadUrl' => $download_url,
'chocolateyProxyLocation' => $chocolatey::install_proxy,
'chocolateyProxyUser' => $chocolatey::install_proxy_user,
'chocolateyProxyPassword' => $chocolatey::install_proxy_password.unwrap,
'chocolateyIgnoreProxy' => $chocolatey::install_ignore_proxy,
# install script defaults to using 7zip, this module defaults to using windows compression.
# this is ignored by install script if $PSVersionTable.PSVersion >= 5
'chocolateyUseWindowsCompression' => $chocolatey::use_7zip ? {
true => false,
false => true,
},
'TEMP' => $chocolatey::install_tempdir,
}.filter |$k, $v| { $v != undef }.map |$k, $v| { join([$k, $v], '=') }

# install.ps1 obtained from: https://community.chocolatey.org/install.ps1
# Lightly modified to allow a custom $seven_zip_download_url. This has the benefit of using the same proxy
# if configured to use a proxy. For this module this is also a change in behavior as previously this was managed
# as a separate File resource.
# Since it was modified the [SIG] block was also removed
exec { 'install_chocolatey_official':
command => epp('chocolatey/InstallChocolatey.ps1.epp', $install_parameters),
command => epp('chocolatey/install.ps1.epp'),
creates => "${chocolatey::choco_install_location}\\bin\\choco.exe",
provider => powershell,
timeout => $chocolatey::choco_install_timeout_seconds,
logoutput => $chocolatey::log_output,
environment => ["ChocolateyInstall=${chocolatey::choco_install_location}"],
environment => $install_parameters,
require => Registry_value['ChocolateyInstall environment value'],
}
}
153 changes: 0 additions & 153 deletions templates/InstallChocolatey.ps1.epp

This file was deleted.

Loading

0 comments on commit cd657ec

Please sign in to comment.