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