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