]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Use chef cache directory instead of creating our own
[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 end
60
61 wordpress_plugin "contact-form-7" do
62   site "join.osmfoundation.org"
63 end
64
65 civicrm_version = node[:civicrm][:version]
66 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
67
68 directory "/opt/civicrm-#{civicrm_version}" do
69   owner "wordpress"
70   group "wordpress"
71   mode 0o755
72 end
73
74 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
75   action :create_if_missing
76   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
77   owner "wordpress"
78   group "wordpress"
79   mode 0o644
80   backup false
81 end
82
83 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
84   action :create_if_missing
85   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
86   owner "wordpress"
87   group "wordpress"
88   mode 0o644
89   backup false
90 end
91
92 execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
93   action :nothing
94   command "unzip -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip"
95   cwd "/opt/civicrm-#{civicrm_version}"
96   user "wordpress"
97   group "wordpress"
98   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
99 end
100
101 execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
102   action :nothing
103   command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz"
104   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
105   user "wordpress"
106   group "wordpress"
107   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
108 end
109
110 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
111   action :nothing
112   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
113   user "wordpress"
114   group "wordpress"
115   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
116   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
117 end
118
119 directory "/srv/join.osmfoundation.org/wp-content/plugins/files" do
120   owner "www-data"
121   group "www-data"
122   mode 0o755
123 end
124
125 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
126
127 directory extensions_directory do
128   owner "wordpress"
129   group "wordpress"
130   mode 0o755
131 end
132
133 node[:civicrm][:extensions].each_value do |details|
134   git "#{extensions_directory}/#{details[:name]}" do
135     action :sync
136     repository details[:repository]
137     revision details[:revision]
138     user "wordpress"
139     group "wordpress"
140   end
141 end
142
143 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
144   line.gsub!(/%%cms%%/, "WordPress")
145   line.gsub!(/%%CMSdbUser%%/, "civicrm")
146   line.gsub!(/%%CMSdbPass%%/, database_password)
147   line.gsub!(/%%CMSdbHost%%/, "localhost")
148   line.gsub!(/%%CMSdbName%%/, "civicrm")
149   line.gsub!(/%%dbUser%%/, "civicrm")
150   line.gsub!(/%%dbPass%%/, database_password)
151   line.gsub!(/%%dbHost%%/, "localhost")
152   line.gsub!(/%%dbName%%/, "civicrm")
153   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
154   line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/plugins/files/civicrm/templates_c/")
155   line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
156   line.gsub!(/%%siteKey%%/, site_key)
157   line.gsub!(%r{// *(.*'ext_repo_url'.*)$}, "\\1")
158   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
159
160   line
161 end
162
163 file "#{civicrm_directory}/civicrm.settings.php" do
164   owner "wordpress"
165   group "wordpress"
166   mode 0o644
167   content settings
168 end
169
170 template "/etc/cron.d/osmf-crm" do
171   source "cron.erb"
172   owner "root"
173   group "root"
174   mode 0o600
175   variables :directory => civicrm_directory, :passwords => passwords
176 end
177
178 template "/etc/cron.daily/osmf-crm-backup" do
179   source "backup.cron.erb"
180   owner "root"
181   group "root"
182   mode 0o750
183   variables :passwords => passwords
184 end