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