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"
31 cache_dir = Chef::Config[:file_cache_path]
33 passwords = data_bag_item("civicrm", "passwords")
35 database_password = passwords["database"]
36 site_key = passwords["key"]
38 mysql_user "civicrm@localhost" do
39 password database_password
42 mysql_database "civicrm" do
43 permissions "civicrm@localhost" => :all
46 wordpress_site "join.osmfoundation.org" do
47 aliases "crm.osmfoundation.org"
48 database_name "civicrm"
49 database_user "civicrm"
50 database_password database_password
51 fpm_prometheus_port 11301
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"
69 wordpress_plugin "contact-form-7" do
70 site "join.osmfoundation.org"
73 wordpress_plugin "civicrm-admin-utilities" do
74 site "join.osmfoundation.org"
77 civicrm_version = node[:civicrm][:version]
78 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
80 directory "/opt/civicrm-#{civicrm_version}" do
86 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
87 action :create_if_missing
88 source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
95 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
96 action :create_if_missing
97 source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
104 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
106 destination "/opt/civicrm-#{civicrm_version}"
110 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
113 archive_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
115 destination "/opt/civicrm-#{civicrm_version}/civicrm"
119 subscribes :extract, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
122 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
124 command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
127 subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
128 subscribes :run, "archive_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
131 directory "/srv/join.osmfoundation.org/wp-content/uploads" do
137 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
139 directory extensions_directory do
145 node[:civicrm][:extensions].each_value do |details|
146 git "#{extensions_directory}/#{details[:name]}" do
148 repository details[:repository]
149 revision details[:revision]
155 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
156 line.gsub!(/%%cms%%/, "WordPress")
157 line.gsub!(/%%CMSdbUser%%/, "civicrm")
158 line.gsub!(/%%CMSdbPass%%/, database_password)
159 line.gsub!(/%%CMSdbHost%%/, "localhost")
160 line.gsub!(/%%CMSdbName%%/, "civicrm")
161 line.gsub!(/%%dbUser%%/, "civicrm")
162 line.gsub!(/%%dbPass%%/, database_password)
163 line.gsub!(/%%dbHost%%/, "localhost")
164 line.gsub!(/%%dbName%%/, "civicrm")
165 line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
166 line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
167 line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
168 line.gsub!(/%%siteKey%%/, site_key)
169 line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
174 file "#{civicrm_directory}/civicrm.settings.php" do
184 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):'"
185 mailto "admins@openstreetmap.org"
188 template "/etc/cron.daily/osmf-crm-backup" do
189 source "backup.cron.erb"
193 variables :passwords => passwords