]> git.openstreetmap.org Git - chef.git/blob - cookbooks/civicrm/recipes/default.rb
Manage static content for planet.openstreetmap.org
[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 "drupal"
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 drupal_site "crm.osmfoundation.org" do
38   title "CiviCRM"
39   database_name "civicrm"
40   database_username "civicrm"
41   database_password database_password
42   admin_password admin_password
43 end
44
45 directory "/usr/local/share/civicrm" do
46   owner "root"
47   group "root"
48   mode "0755"
49 end
50
51 civicrm_version = node[:civicrm][:version]
52 civicrm_directory = "/usr/local/share/civicrm/#{civicrm_version}"
53
54 subversion civicrm_directory do
55   action :export
56   repository "http://svn.civicrm.org/civicrm/tags/tarballs/#{node[:civicrm][:version]}"
57   user "root"
58   group "root"
59 end
60
61 link "/usr/share/drupal7/sites/all/modules/civicrm" do
62   to "/usr/local/share/civicrm/#{node[:civicrm][:version]}"
63 end
64
65 directory "/data/crm.osmfoundation.org/civicrm" do
66   owner "www-data"
67   group "www-data"
68   mode "0775"
69 end
70
71 ruby_block "#{civicrm_directory}/civicrm.settings.php" do
72   block do
73     out = File.new("#{civicrm_directory}/civicrm.settings.php", "w")
74
75     File.foreach("#{civicrm_directory}/templates/CRM/common/civicrm.settings.php.tpl") do |line|
76       line.gsub!(/%%cms%%/, "Drupal")
77       line.gsub!(/%%CMSdbUser%%/, "civicrm")
78       line.gsub!(/%%CMSdbPass%%/, database_password)
79       line.gsub!(/%%CMSdbHost%%/, "localhost")
80       line.gsub!(/%%CMSdbName%%/, "civicrm")
81       line.gsub!(/%%dbUser%%/, "civicrm")
82       line.gsub!(/%%dbPass%%/, database_password)
83       line.gsub!(/%%dbHost%%/, "localhost")
84       line.gsub!(/%%dbName%%/, "civicrm")
85       line.gsub!(/%%crmRoot%%/, "/usr/share/drupal7/sites/all/modules/civicrm")
86       line.gsub!(/%%templateCompileDir%%/, "/data/crm.osmfoundation.org/civicrm")
87       line.gsub!(/%%baseURL%%/, "http://crm.osmfoundation.org/")
88       line.gsub!(/%%siteKey%%/, site_key)
89
90       out.print(line)
91     end
92
93     out.close
94   end
95
96   not_if do
97     File.exist?("#{civicrm_directory}/civicrm.settings.php") and
98     File.mtime("#{civicrm_directory}/civicrm.settings.php") >= File.mtime("#{civicrm_directory}/templates/CRM/common/civicrm.settings.php.tpl")
99   end
100 end
101
102 link "/etc/drupal/7/sites/crm.osmfoundation.org/civicrm.settings.php" do
103   to "#{civicrm_directory}/civicrm.settings.php"
104 end
105
106 template "#{civicrm_directory}/settings_location.php" do
107   source "settings_location.php.erb"
108   owner "root"
109   group "root"
110   mode "0644"
111 end
112
113 execute "civicrm-load-acl" do
114   action :nothing
115   command "mysql --user=civicrm --password=#{database_password} civicrm < sql/civicrm_acl.mysql"
116   cwd "/usr/share/drupal7/sites/all/modules/civicrm"
117   user "root"
118   group "root"
119 end
120
121 execute "civicrm-load-data" do
122   action :nothing
123   command "mysql --user=civicrm --password=#{database_password} civicrm < sql/civicrm_data.mysql"
124   cwd "/usr/share/drupal7/sites/all/modules/civicrm"
125   user "root"
126   group "root"
127   notifies :run, resources(:execute => "civicrm-load-acl")
128 end
129
130 execute "civicrm-load" do
131   action :nothing
132   command "mysql --user=civicrm --password=#{database_password} civicrm < sql/civicrm.mysql"
133   cwd "/usr/share/drupal7/sites/all/modules/civicrm"
134   user "root"
135   group "root"
136   notifies :run, resources(:execute => "civicrm-load-data")
137 end
138
139 execute "civicrm-gencode" do
140   command "php GenCode.php"
141   cwd "#{civicrm_directory}/xml"
142   user "root"
143   group "root"
144   creates "#{civicrm_directory}/civicrm-version.php"
145   notifies :run, resources(:execute => "civicrm-load")
146 end
147
148 directory "/data/crm.osmfoundation.org/civicrm/en_US" do
149   owner "www-data"
150   group "www-data"
151   mode "0775"
152 end
153
154 directory "/data/crm.osmfoundation.org/civicrm/en_US/ConfigAndLog" do
155   owner "www-data"
156   group "www-data"
157   mode "0775"
158 end
159
160 template "/etc/cron.daily/osmf-crm-backup" do
161   source "backup.cron.erb"
162   owner "root"
163   group "root"
164   mode 0750
165   variables :passwords => passwords
166 end