]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/definitions/wordpress_plugin.rb
abc20c3887024e2b0862af1684f0a74b87151901
[chef.git] / cookbooks / wordpress / definitions / wordpress_plugin.rb
1 #
2 # Cookbook Name:: wordpress
3 # Definition:: wordpress_plugin
4 #
5 # Copyright 2013, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 define :wordpress_plugin, :action => [ :enable ] do
21   name = params[:name]
22   site = params[:site]
23   site_directory = node[:wordpress][:sites][site][:directory]
24   plugin_directory = "#{site_directory}/wp-content/plugins/#{name}"
25   source = params[:source]
26
27   if source
28     remote_directory plugin_directory do
29       cookbook "wordpress"
30       source source
31       owner node[:wordpress][:user]
32       group node[:wordpress][:group]
33       mode 0755
34       files_owner node[:wordpress][:user]
35       files_group node[:wordpress][:group]
36       files_mode 0755
37     end
38   else
39     unless repository = params[:repository]
40       version = params[:version] || Chef::Wordpress.current_plugin_version(name)
41
42       if version =~ /trunk/
43         repository = "http://plugins.svn.wordpress.org/#{name}/trunk"
44       else
45         repository = "http://plugins.svn.wordpress.org/#{name}/tags/#{version}"
46       end
47     end
48
49     if repository =~ /\.git$/
50       git plugin_directory do
51         action :sync
52         repository repository
53         revision params[:revision]
54         user node[:wordpress][:user]
55         group node[:wordpress][:group]
56         notifies :reload, "service[apache2]"
57       end
58     else
59       subversion plugin_directory do
60         action :sync
61         repository repository
62         user node[:wordpress][:user]
63         group node[:wordpress][:group]
64         ignore_failure repository.start_with?("http://plugins.svn.wordpress.org/")
65         notifies :reload, "service[apache2]"
66       end
67     end
68   end
69 end