Make the osmfoundation certificate the default cert on ridley
[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 "crm.osmfoundation.org" do
39   ssl_enabled true
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 "crm.osmfoundation.org"
47   repository "git://github.com/harry-wood/osmblog-wp-theme.git"
48 end
49
50 civicrm_version = node[:civicrm][:version]
51 civicrm_directory = "/srv/crm.osmfoundation.org/wp-content/plugins/civicrm"
52
53 directory "/opt/civicrm-#{civicrm_version}" do
54   owner "wordpress"
55   group "wordpress"
56   mode 0755
57 end
58
59 remote_file "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do
60   action :create_if_missing
61   source "http://downloads.sourceforge.net/project/civicrm/civicrm-stable/#{civicrm_version}/civicrm-#{civicrm_version}-wordpress.zip"
62   owner "wordpress"
63   group "wordpress"
64   mode 0644
65   backup false
66 end
67
68 remote_file "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do
69   action :create_if_missing
70   source "http://downloads.sourceforge.net/project/civicrm/civicrm-stable/#{civicrm_version}/civicrm-#{civicrm_version}-l10n.tar.gz"
71   owner "wordpress"
72   group "wordpress"
73   mode 0644
74   backup false
75 end
76
77 execute "/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip" do
78   action :nothing
79   command "unzip -qq /var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip"
80   cwd "/opt/civicrm-#{civicrm_version}"
81   user "wordpress"
82   group "wordpress"
83   subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
84 end
85
86 execute "/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz" do
87   action :nothing
88   command "tar -zxf /var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz"
89   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
90   user "wordpress"
91   group "wordpress"
92   subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
93 end
94
95 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
96   action :nothing
97   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
98   user "wordpress"
99   group "wordpress"
100   subscribes :run, "execute[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
101   subscribes :run, "execute[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
102 end
103
104 directory "/srv/crm.osmfoundation.org/wp-content/plugins/files" do
105   owner "www-data"
106   group "www-data"
107   mode 0755
108 end
109
110 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
111   line.gsub!(/%%cms%%/, "WordPress")
112   line.gsub!(/%%CMSdbUser%%/, "civicrm")
113   line.gsub!(/%%CMSdbPass%%/, database_password)
114   line.gsub!(/%%CMSdbHost%%/, "localhost")
115   line.gsub!(/%%CMSdbName%%/, "civicrm")
116   line.gsub!(/%%dbUser%%/, "civicrm")
117   line.gsub!(/%%dbPass%%/, database_password)
118   line.gsub!(/%%dbHost%%/, "localhost")
119   line.gsub!(/%%dbName%%/, "civicrm")
120   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
121   line.gsub!(/%%templateCompileDir%%/, "/srv/crm.osmfoundation.org/wp-content/plugins/files/civicrm/templates_c/")
122   line.gsub!(/%%baseURL%%/, "http://crm.osmfoundation.org/")
123   line.gsub!(/%%siteKey%%/, site_key)
124
125   line
126 end
127
128 file "#{civicrm_directory}/civicrm.settings.php" do
129   owner "wordpress"
130   group "wordpress"
131   mode 0644
132   content settings
133 end
134
135 template "/etc/cron.d/osmf-crm" do
136   source "cron.erb"
137   owner "root"
138   group "root"
139   mode 0600
140   variables :directory => civicrm_directory, :passwords => passwords
141 end
142
143 template "/etc/cron.daily/osmf-crm-backup" do
144   source "backup.cron.erb"
145   owner "root"
146   group "root"
147   mode 0750
148   variables :passwords => passwords
149 end