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