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
 
  53 wordpress_theme "osmblog-wp-theme" do
 
  54   site "join.osmfoundation.org"
 
  55   repository "https://github.com/harry-wood/osmblog-wp-theme.git"
 
  58 wordpress_plugin "registration-honeypot" do
 
  59   site "join.osmfoundation.org"
 
  62 wordpress_plugin "sitepress-multilingual-cms" do
 
  63   site "join.osmfoundation.org"
 
  64   repository "https://git.openstreetmap.org/private/sitepress-multilingual-cms.git"
 
  65   not_if { ENV["TEST_KITCHEN"] }
 
  68 wordpress_plugin "contact-form-7" do
 
  69   site "join.osmfoundation.org"
 
  72 civicrm_version = node[:civicrm][:version]
 
  73 civicrm_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm"
 
  75 directory "/opt/civicrm-#{civicrm_version}" do
 
  81 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
 
  82   action :create_if_missing
 
  83   source "https://download.civicrm.org/civicrm-#{civicrm_version}-wordpress.zip"
 
  90 remote_file "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
 
  91   action :create_if_missing
 
  92   source "https://download.civicrm.org/civicrm-#{civicrm_version}-l10n.tar.gz"
 
  99 execute "#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip" do
 
 101   command "unzip -o -qq #{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip"
 
 102   cwd "/opt/civicrm-#{civicrm_version}"
 
 105   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
 
 108 execute "#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz" do
 
 110   command "tar -zxf #{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz"
 
 111   cwd "/opt/civicrm-#{civicrm_version}/civicrm"
 
 114   subscribes :run, "remote_file[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
 
 117 execute "/opt/civicrm-#{civicrm_version}/civicrm" do
 
 119   command "rsync --archive --delete /opt/civicrm-#{civicrm_version}/civicrm/ #{civicrm_directory}"
 
 122   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-wordpress.zip]", :immediately
 
 123   subscribes :run, "execute[#{cache_dir}/civicrm-#{civicrm_version}-l10n.tar.gz]", :immediately
 
 126 directory "/srv/join.osmfoundation.org/wp-content/uploads" do
 
 132 extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
 
 134 directory extensions_directory do
 
 140 node[:civicrm][:extensions].each_value do |details|
 
 141   git "#{extensions_directory}/#{details[:name]}" do
 
 143     repository details[:repository]
 
 144     revision details[:revision]
 
 150 settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
 
 151   line.gsub!(/%%cms%%/, "WordPress")
 
 152   line.gsub!(/%%CMSdbUser%%/, "civicrm")
 
 153   line.gsub!(/%%CMSdbPass%%/, database_password)
 
 154   line.gsub!(/%%CMSdbHost%%/, "localhost")
 
 155   line.gsub!(/%%CMSdbName%%/, "civicrm")
 
 156   line.gsub!(/%%dbUser%%/, "civicrm")
 
 157   line.gsub!(/%%dbPass%%/, database_password)
 
 158   line.gsub!(/%%dbHost%%/, "localhost")
 
 159   line.gsub!(/%%dbName%%/, "civicrm")
 
 160   line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
 
 161   line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
 
 162   line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
 
 163   line.gsub!(/%%siteKey%%/, site_key)
 
 164   line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
 
 169 file "#{civicrm_directory}/civicrm.settings.php" do
 
 179   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):'"
 
 180   mailto "admins@openstreetmap.org"
 
 183 template "/etc/cron.daily/osmf-crm-backup" do
 
 184   source "backup.cron.erb"
 
 188   variables :passwords => passwords