]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Add more depth limits to git checkouts
[chef.git] / cookbooks / civicrm / recipes / default.rb
1 #
2 # Cookbook:: civicrm
3 # Recipe:: default
4 #
5 # Copyright:: 2011, 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 include_recipe "wordpress"
21 include_recipe "mysql"
22
23 package %w[
24   rsync
25   unzip
26   wkhtmltopdf
27 ]
28
29 cache_dir = Chef::Config[:file_cache_path]
30
31 passwords = data_bag_item("civicrm", "passwords")
32
33 database_password = passwords["database"]
34 site_key = passwords["key"]
35
36 mysql_user "civicrm@localhost" do
37   password database_password
38 end
39
40 mysql_database "civicrm" do
41   permissions "civicrm@localhost" => :all
42 end
43
44 wordpress_site "join.osmfoundation.org" do
45   aliases "crm.osmfoundation.org"
46   database_name "civicrm"
47   database_user "civicrm"
48   database_password database_password
49 end
50
51 wordpress_theme "osmblog-wp-theme" do
52   site "join.osmfoundation.org"
53   repository "https://github.com/harry-wood/osmblog-wp-theme.git"
54 end
55
56 wordpress_plugin "registration-honeypot" do
57   site "join.osmfoundation.org"
58 end
59
60 wordpress_plugin "sitepress-multilingual-cms" do
61   site "join.osmfoundation.org"
62   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
63   not_if { ENV["TEST_KITCHEN"] }
64 end
65
66 wordpress_plugin "contact-form-7" do
67   site "join.osmfoundation.org"
68 end
69
70 civicrm_version = node[:civicrm][:version]
71 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
72
73 directory "/opt/civicrm-#{civicrm_version}" do
74   owner "wordpress"
75   group "wordpress"
76   mode 0o755
77 end
78
79 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
80   action :create_if_missing
81   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
82   owner "wordpress"
83   group "wordpress"
84   mode 0o644
85   backup false
86 end
87
88 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
89   action :create_if_missing
90   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
91   owner "wordpress"
92   group "wordpress"
93   mode 0o644
94   backup false
95 end
96
97 execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
98   action :nothing
99   command "unzip -o -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip"
100   cwd "/opt/civicrm-#{civicrm_version}"
101   user "wordpress"
102   group "wordpress"
103   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
104 end
105
106 execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
107   action :nothing
108   command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz"
109   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
110   user "wordpress"
111   group "wordpress"
112   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
113 end
114
115 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
116   action :nothing
117   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
118   user "wordpress"
119   group "wordpress"
120   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
121   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
122 end
123
124 directory "/srv/join.osmfoundation.org/wp-content/plugins/files" do
125   owner "www-data"
126   group "www-data"
127   mode 0o755
128 end
129
130 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
131
132 directory extensions_directory do
133   owner "wordpress"
134   group "wordpress"
135   mode 0o755
136 end
137
138 node[:civicrm][:extensions].each_value do |details|
139   git "#{extensions_directory}/#{details[:name]}" do
140     action :sync
141     repository details[:repository]
142     revision details[:revision]
143     depth 1
144     user "wordpress"
145     group "wordpress"
146   end
147 end
148
149 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
150   line.gsub!(/%%cms%%/, "WordPress")
151   line.gsub!(/%%CMSdbUser%%/, "civicrm")
152   line.gsub!(/%%CMSdbPass%%/, database_password)
153   line.gsub!(/%%CMSdbHost%%/, "localhost")
154   line.gsub!(/%%CMSdbName%%/, "civicrm")
155   line.gsub!(/%%dbUser%%/, "civicrm")
156   line.gsub!(/%%dbPass%%/, database_password)
157   line.gsub!(/%%dbHost%%/, "localhost")
158   line.gsub!(/%%dbName%%/, "civicrm")
159   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
160   line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/plugins/files/civicrm/templates_c/")
161   line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
162   line.gsub!(/%%siteKey%%/, site_key)
163   line.gsub!(%r{// *(.*'ext_repo_url'.*)$}, "\\1")
164   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
165
166   line
167 end
168
169 file "#{civicrm_directory}/civicrm.settings.php" do
170   owner "wordpress"
171   group "wordpress"
172   mode 0o644
173   content settings
174 end
175
176 template "/etc/cron.d/osmf-crm" do
177   source "cron.erb"
178   owner "root"
179   group "root"
180   mode 0o600
181   variables :directory => civicrm_directory, :passwords => passwords
182 end
183
184 template "/etc/cron.daily/osmf-crm-backup" do
185   source "backup.cron.erb"
186   owner "root"
187   group "root"
188   mode 0o750
189   variables :passwords => passwords
190 end