Skip to content

Commit 4c12aef

Browse files
authored
Merge pull request #141 from JohnEricson/master
2 parents 337a1c6 + 937519a commit 4c12aef

File tree

10 files changed

+70
-33
lines changed

10 files changed

+70
-33
lines changed

.fixtures.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fixtures:
2+
repositories:
3+
archive: "git://github.com/voxpupuli/puppet-archive"

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ gem 'puppet-lint'
1111
gem 'rspec-puppet'
1212
gem 'syck'
1313
gem 'puppet', puppetversion
14+
gem "puppetlabs_spec_helper", "2.10.0"
15+

Rakefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
require "rake"
2-
require "rspec/core/rake_task"
1+
require 'puppetlabs_spec_helper/rake_tasks'
32

4-
RSpec::Core::RakeTask.new(:spec) do |t|
5-
t.pattern = Dir.glob("spec/**/*_spec.rb")
6-
end
7-
8-
task default: :spec

manifests/cli.pp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,58 +4,68 @@
44
$install_path = '/usr/local/src/wp-cli',
55
$version = 'dev-master',
66

7-
) {
8-
include wp
7+
) inherits wp {
8+
if $::osfamily == 'Windows' {
9+
Package { provider => 'chocolatey' }
10+
}
911

1012
if 'installed' == $ensure or 'present' == $ensure {
1113
# Create the install path
1214
file { [ $install_path, "${install_path}/bin" ]:
1315
ensure => directory,
1416
}
1517

16-
# Clone the Git repo
17-
exec { 'wp-cli download':
18-
command => "/usr/bin/curl -o ${install_path}/bin/wp -L https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar",
19-
require => [ Package[ 'curl' ], File[ $install_path ] ],
20-
creates => "${install_path}/bin/wp"
18+
archive { 'wp-cli download':
19+
ensure => present,
20+
source => 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar',
21+
path => "${install_path}/bin/wp-cli.phar",
2122
}
2223

23-
# Ensure we can run wp-cli
24-
file { "${install_path}/bin/wp":
25-
ensure => 'present',
26-
mode => 'a+x',
27-
require => Exec[ 'wp-cli download' ]
28-
}
24+
if $::kernel == 'Linux' {
25+
file { "${install_path}/bin/${wp::executable_filename}":
26+
ensure => 'present',
27+
content => template('wp/wp.sh.erb'),
28+
mode => 'a+x',
29+
require => Archive[ 'wp-cli download' ]
30+
}
31+
32+
# Symlink it across
33+
file { "${wp::bin_path}/${wp::executable_filename}":
34+
ensure => link,
35+
target => "${install_path}/bin/${wp::executable_filename}",
36+
require => File[ "${install_path}/bin/wp" ],
37+
}
38+
} else {
2939

30-
# Symlink it across
31-
file { "${wp::params::bin_path}/wp":
32-
ensure => link,
33-
target => "${install_path}/bin/wp",
34-
require => File[ "${install_path}/bin/wp" ],
40+
file { "${install_path}/bin/${wp::executable_filename}":
41+
ensure => 'present',
42+
content => template('wp/wp.bat.erb'),
43+
require => Archive[ 'wp-cli download' ]
44+
}
3545
}
3646
}
3747
elsif 'absent' == $ensure {
38-
file { "${wp::params::bin_path}/wp":
48+
file { "${wp::bin_path}/${wp::executable_filename}":
3949
ensure => absent,
4050
}
4151
file { '/usr/local/src/wp-cli':
4252
ensure => absent,
4353
}
4454
}
4555

46-
if ! defined( Package[ $::wp::php_package ] ) {
56+
if $::wp::manage_php_package and ! defined( Package[ $::wp::php_package ] ) {
4757
package { $::wp::php_package:
4858
ensure => installed,
4959
}
5060
}
5161

52-
if ! defined(Package['curl']) {
62+
if $::wp::manage_curl_package and ! defined(Package['curl']) {
5363
package { 'curl':
5464
ensure => installed,
5565
}
5666
}
5767

58-
if ! defined(Package['git']) {
68+
if $::wp::manage_git_package and ! defined(Package['git']) {
5969
package { 'git':
6070
ensure => installed,
6171
}

manifests/command.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
$command,
55
$user = $::wp::user,
66
$unless = undef,
7-
$onlyif = "${wp::params::bin_path}/wp is-installed",
7+
$onlyif = "${wp::bin_path}/${wp::executable_filename} core is-installed",
88
) {
99
include wp::cli
1010

1111
exec {"${location} wp ${command}":
12-
command => "${wp::params::bin_path}/wp ${command}",
12+
command => "${wp::bin_path}/${wp::executable_filename} ${command}",
1313
cwd => $location,
1414
user => $user,
1515
require => [ Class['wp::cli'] ],

manifests/init.pp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
class wp (
33
$user = $::wp::params::user,
44
$php_package = $::wp::params::php_package,
5+
$php_executable_path = $::wp::params::php_executable_path,
6+
$bin_path = $::wp::params::bin_path,
7+
$executable_filename = $::wp::params::executable_filename,
8+
$manage_php_package = $::wp::params::manage_php_package,
9+
$manage_curl_package = $::wp::params::manage_curl_package,
10+
$manage_git_package = $::wp::params::manage_git_package,
511
) inherits wp::params {
612
# ...
713
}

manifests/params.pp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
# A class for parameters we might need to use.
22
class wp::params {
3-
$user = 'www-data'
4-
$bin_path = '/usr/local/bin'
3+
$user = $::operatingsystem ? {
4+
'windows' => undef,
5+
default => 'www-data',
6+
}
7+
$bin_path = '/usr/local/bin'
8+
$executable_filename = $::operatingsystem ? {
9+
'windows' => 'wp.bat',
10+
default => 'wp',
11+
}
512
$php_package = $::operatingsystem ? {
613
/^(Debian|Ubuntu)$/ => 'php5-cli',
14+
'windows' => 'php',
715
default => 'php-cli',
816
}
17+
$php_executable_path = $::operatingsystem ? {
18+
'windows' => 'C:/tools/php80/php.exe',
19+
default => '/usr/bin/php',
20+
}
21+
$manage_php_package = true
22+
$manage_curl_package = true
23+
$manage_git_package = true
924
}

spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'puppetlabs_spec_helper/module_spec_helper'
12
require 'rspec-puppet'
23

34
fixture_path = File.join(File.dirname(File.expand_path(__FILE__)), 'fixtures')

templates/wp.bat.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@ECHO OFF
2+
<%= @php_executable_path %> "%~dp0/wp-cli.phar" %*
3+

templates/wp.sh.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
<%= @php_executable_path %> "$(dirname "$(readlink -f "$0")")/wp-cli.phar" "$@"
3+

0 commit comments

Comments
 (0)