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