]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Rework civicrm using wordpress instead of drupal
[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 true
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 "root"
49   group "root"
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 "root"
57   group "root"
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 "root"
66   group "root"
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 "root"
76   group "root"
77   subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-wordpress.zip]"
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 "root"
85   group "root"
86   subscribes :run, "remote_file[/var/cache/chef/civicrm-#{civicrm_version}-l10n.tar.gz]"
87 end
88
89 link civicrm_directory do
90   to "/opt/civicrm-#{civicrm_version}/civicrm"
91 end
92
93 directory "/srv/crm.osmfoundation.org/wp-content/plugins/files" do
94   owner "www-data"
95   group "www-data"
96   mode 0755
97 end
98
99 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
100   line.gsub!(/%%cms%%/, "WordPress")
101   line.gsub!(/%%CMSdbUser%%/, "civicrm")
102   line.gsub!(/%%CMSdbPass%%/, database_password)
103   line.gsub!(/%%CMSdbHost%%/, "localhost")
104   line.gsub!(/%%CMSdbName%%/, "civicrm")
105   line.gsub!(/%%dbUser%%/, "civicrm")
106   line.gsub!(/%%dbPass%%/, database_password)
107   line.gsub!(/%%dbHost%%/, "localhost")
108   line.gsub!(/%%dbName%%/, "civicrm")
109   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm")
110   line.gsub!(/%%templateCompileDir%%/, "/srv/crm.osmfoundation.org/wp-content/plugins/files/civicrm/templates_c")
111   line.gsub!(/%%baseURL%%/, "http://crm.osmfoundation.org/")
112   line.gsub!(/%%siteKey%%/, site_key)
113
114   line
115 end
116
117 file "#{civicrm_directory}/civicrm/civicrm.settings.php" do
118   owner "root"
119   group "root"
120   mode 0644
121   content settings
122 end
123
124 template "/etc/cron.daily/osmf-crm-backup" do
125   source "backup.cron.erb"
126   owner "root"
127   group "root"
128   mode 0750
129   variables :passwords => passwords
130 end