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