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