]> git.openstreetmap.org Git - chef.git/blob - cookbooks/wordpress/resources/theme.rb
nominatim: install secondary importance file
[chef.git] / cookbooks / wordpress / resources / theme.rb
1 #
2 # Cookbook:: wordpress
3 # Resource:: wordpress_theme
4 #
5 # Copyright:: 2015, 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 # https://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 unified_mode true
21
22 default_action :create
23
24 property :theme, :kind_of => String, :name_property => true
25 property :site, :kind_of => String, :required => true
26 property :source, :kind_of => String
27 property :version, :kind_of => String
28 property :repository, :kind_of => String
29 property :revision, :kind_of => String
30 property :reload_apache, :kind_of => [TrueClass, FalseClass], :default => true
31
32 action :create do
33   if new_resource.source
34     remote_directory theme_directory do
35       cookbook "wordpress"
36       source new_resource.source
37       owner node[:wordpress][:user]
38       group node[:wordpress][:group]
39       mode "755"
40       files_owner node[:wordpress][:user]
41       files_group node[:wordpress][:group]
42       files_mode "644"
43     end
44   else
45     theme_repository = new_resource.repository || default_repository
46
47     if theme_repository.end_with?(".git")
48       git theme_directory do
49         action :sync
50         repository theme_repository
51         revision new_resource.revision
52         user node[:wordpress][:user]
53         group node[:wordpress][:group]
54       end
55     elsif theme_repository.end_with?(".zip")
56       zip_path = "#{Chef::Config[:file_cache_path]}/#{new_resource.theme}.zip"
57
58       remote_file zip_path do
59         source theme_repository
60         action :create
61       end
62
63       archive_file zip_path do
64         destination theme_directory
65         action :nothing
66         overwrite true
67         group node[:wordpress][:group]
68         owner node[:wordpress][:user]
69         subscribes :extract, "remote_file[#{zip_path}]", :immediately
70       end
71     else
72       subversion theme_directory do
73         action :sync
74         repository theme_repository
75         user node[:wordpress][:user]
76         group node[:wordpress][:group]
77         ignore_failure theme_repository.start_with?("https://themes.svn.wordpress.org/")
78       end
79     end
80   end
81 end
82
83 action :delete do
84   directory theme_directory do
85     action :delete
86     recursive true
87   end
88 end
89
90 action_class do
91   def site_directory
92     node[:wordpress][:sites][new_resource.site][:directory]
93   end
94
95   def theme_directory
96     "#{site_directory}/wp-content/themes/#{new_resource.theme}"
97   end
98
99   def default_repository
100     "https://themes.svn.wordpress.org/#{new_resource.theme}/#{new_resource.version}"
101   end
102 end
103
104 def after_created
105   notifies :reload, "service[apache2]" if reload_apache
106 end