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