Fix rubocop warnings
[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 wordpress_plugin "contact-form-7" do
61   site "join.osmfoundation.org"
62 end
63
64 civicrm_version = node[:civicrm][:version]
65 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
66
67 directory "/opt/civicrm-#{civicrm_version}" do
68   owner "wordpress"
69   group "wordpress"
70   mode 0o755
71 end
72
73 remote_file "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do
74   action :create_if_missing
75   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
76   owner "wordpress"
77   group "wordpress"
78   mode 0o644
79   backup false
80 end
81
82 remote_file "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do
83   action :create_if_missing
84   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
85   owner "wordpress"
86   group "wordpress"
87   mode 0o644
88   backup false
89 end
90
91 execute "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do
92   action :nothing
93   command "unzip -qq /var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip"
94   cwd "/opt/civicrm-#{civicrm_version}"
95   user "wordpress"
96   group "wordpress"
97   subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
98 end
99
100 execute "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do
101   action :nothing
102   command "tar -zxf /var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz"
103   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
104   user "wordpress"
105   group "wordpress"
106   subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
107 end
108
109 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
110   action :nothing
111   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
112   user "wordpress"
113   group "wordpress"
114   subscribes :run, "execute[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
115   subscribes :run, "execute[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
116 end
117
118 directory "/srv/join.osmfoundation.org/wp-content/plugins/files" do
119   owner "www-data"
120   group "www-data"
121   mode 0o755
122 end
123
124 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
125
126 directory extensions_directory do
127   owner "wordpress"
128   group "wordpress"
129   mode 0o755
130 end
131
132 node[:civicrm][:extensions].each_value do |details|
133   git "#{extensions_directory}/#{details[:name]}" do
134     action :sync
135     repository details[:repository]
136     revision details[:revision]
137     user "wordpress"
138     group "wordpress"
139   end
140 end
141
142 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
143   line.gsub!(/%%cms%%/, "WordPress")
144   line.gsub!(/%%CMSdbUser%%/, "civicrm")
145   line.gsub!(/%%CMSdbPass%%/, database_password)
146   line.gsub!(/%%CMSdbHost%%/, "localhost")
147   line.gsub!(/%%CMSdbName%%/, "civicrm")
148   line.gsub!(/%%dbUser%%/, "civicrm")
149   line.gsub!(/%%dbPass%%/, database_password)
150   line.gsub!(/%%dbHost%%/, "localhost")
151   line.gsub!(/%%dbName%%/, "civicrm")
152   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
153   line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/plugins/files/civicrm/templates_c/")
154   line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
155   line.gsub!(/%%siteKey%%/, site_key)
156   line.gsub!(%r{// *(.*'ext_repo_url'.*)$}, "\\1")
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