5 # Copyright:: 2011, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "wordpress"
21 include_recipe "mysql"
32 cache_dir = Chef::Config[:file_cache_path]
34 passwords = data_bag_item("civicrm", "passwords")
36 database_password = passwords["database"]
37 site_key = passwords["key"]
39 mysql_user "civicrm@localhost" do
40 password database_password
43 mysql_database "civicrm" do
44 permissions "civicrm@localhost" => :all
47 wordpress_site "join.osmfoundation.org" do
48 aliases "crm.osmfoundation.org"
49 database_name "civicrm"
50 database_user "civicrm"
51 database_password database_password
54 wordpress_theme "osmblog-wp-theme" do
55 site "join.osmfoundation.org"
56 repository "https://github.com/harry-wood/osmblog-wp-theme.git"
59 wordpress_plugin "registration-honeypot" do
60 site "join.osmfoundation.org"
63 wordpress_plugin "sitepress-multilingual-cms" do
64 site "join.osmfoundation.org"
65 repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
66 not_if { ENV["TEST_KITCHEN"] }
69 wordpress_plugin "contact-form-7" do
70 site "join.osmfoundation.org"
73 civicrm_version = node[:civicrm][:version]
74 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
76 directory "/opt/civicrm-#{civicrm_version}" do
82 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
83 action :create_if_missing
84 source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
91 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
92 action :create_if_missing
93 source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
100 execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
102 command "unzip -o -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip"
103 cwd "/opt/civicrm-#{civicrm_version}"
106 subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
109 execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
111 command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz"
112 cwd "/opt/civicrm-#{civicrm_version}/civicrm"
115 subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
118 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
120 command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
123 subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
124 subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
127 directory "/srv/join.osmfoundation.org/wp-content/uploads" do
133 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
135 directory extensions_directory do
141 node[:civicrm][:extensions].each_value do |details|
142 git "#{extensions_directory}/#{details[:name]}" do
144 repository details[:repository]
145 revision details[:revision]
151 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
152 line.gsub!(/%%cms%%/, "WordPress")
153 line.gsub!(/%%CMSdbUser%%/, "civicrm")
154 line.gsub!(/%%CMSdbPass%%/, database_password)
155 line.gsub!(/%%CMSdbHost%%/, "localhost")
156 line.gsub!(/%%CMSdbName%%/, "civicrm")
157 line.gsub!(/%%dbUser%%/, "civicrm")
158 line.gsub!(/%%dbPass%%/, database_password)
159 line.gsub!(/%%dbHost%%/, "localhost")
160 line.gsub!(/%%dbName%%/, "civicrm")
161 line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
162 line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
163 line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
164 line.gsub!(/%%siteKey%%/, site_key)
165 line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
170 file "#{civicrm_directory}/civicrm.settings.php" do
180 command "php #{civicrm_directory}/civicrm/bin/cli.php -s join.osmfoundation.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute 2>&1 | egrep -v '^PHP (Deprecated|Warning):'"
181 mailto "admins@openstreetmap.org"
184 template "/etc/cron.daily/osmf-crm-backup" do
185 source "backup.cron.erb"
189 variables :passwords => passwords