Skip to content

Commit 366718d

Browse files
committed
FEAT: Ensure it now also can install wp-cli on Windows and that the wp command works to update option blogname on a WordPress installation on Windows.
FEAT: Added new parameters php_executable_path, bin_path, executable_filename to the wp class. These now have default values both for Linux and Windows. BUG: On Windows I set the exec user that is used to run the wp-cli command to undef so prevent this bug from happening https://tickets.puppetlabs.com/browse/ENTERPRISE-13. On Windows you can't run an exec as another user. The wp-cli client doesn't complain about this when I tested to run it as the SYSTEM user in Windows, which is the Puppet default. MISC: Respected tab indenting in cli.pp, command.pp, init.pp, params.pp.
1 parent b5871df commit 366718d

File tree

8 files changed

+55
-43
lines changed

8 files changed

+55
-43
lines changed

files/wp

Lines changed: 0 additions & 3 deletions
This file was deleted.

files/wp.bat

Lines changed: 0 additions & 3 deletions
This file was deleted.

manifests/cli.pp

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

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

1412
if 'installed' == $ensure or 'present' == $ensure {
1513
# Create the install path
1614
file { [ $install_path, "${install_path}/bin" ]:
1715
ensure => directory,
1816
}
1917

20-
archive { 'wp-cli download':
21-
ensure => present,
22-
source => 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar',
23-
path => "${install_path}/bin/wp-cli.phar",
24-
}
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",
22+
}
2523

2624
if $::kernel == 'Linux' {
27-
file { "${install_path}/bin/wp":
28-
ensure => 'present',
29-
source => 'puppet:///modules/wp/wp',
30-
mode => 'a+x',
31-
require => Archive[ 'wp-cli download' ]
32-
}
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+
}
3331

34-
# Symlink it across
35-
file { "${wp::params::bin_path}/wp":
36-
ensure => link,
37-
target => "${install_path}/bin/wp",
38-
require => File[ "${install_path}/bin/wp" ],
39-
}
40-
} else {
41-
42-
file { "${install_path}/bin/wp.bat":
43-
ensure => 'present',
44-
source => 'puppet:///modules/wp/wp.bat',
45-
require => Archive[ 'wp-cli download' ]
46-
}
47-
}
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 {
39+
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+
}
45+
}
4846
}
4947
elsif 'absent' == $ensure {
50-
file { "${wp::params::bin_path}/wp":
48+
file { "${wp::bin_path}/":
5149
ensure => absent,
5250
}
5351
file { '/usr/local/src/wp-cli':

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
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,
58
) inherits wp::params {
69
# ...
710
}

manifests/params.pp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
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',
714
/^windows$/ => 'php',
8-
default => 'php-cli',
15+
default => 'php-cli',
16+
}
17+
$php_executable_path = $::operatingsystem ? {
18+
'windows' => 'C:/tools/php80/php.exe',
19+
default => '/usr/bin/php',
920
}
1021
}

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 $0)/wp-cli.phar" $@
3+

0 commit comments

Comments
 (0)