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