+extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
+
+directory extensions_directory do
+ owner "wordpress"
+ group "wordpress"
+ mode "755"
+end
+
+node[:civicrm][:extensions].each_value do |details|
+ git "#{extensions_directory}/#{details[:name]}" do
+ action :sync
+ repository details[:repository]
+ revision details[:revision]
+ user "wordpress"
+ group "wordpress"
+ end
+end
+
+settings = edit_file "#{civicrm_directory}/civicrm/templates/CRM/common/civicrm.settings.php.template" do |line|
+ line.gsub!(/%%cms%%/, "WordPress")
+ line.gsub!(/%%CMSdbUser%%/, "civicrm")
+ line.gsub!(/%%CMSdbPass%%/, database_password)
+ line.gsub!(/%%CMSdbHost%%/, "localhost")
+ line.gsub!(/%%CMSdbName%%/, "civicrm")
+ line.gsub!(/%%dbUser%%/, "civicrm")
+ line.gsub!(/%%dbPass%%/, database_password)
+ line.gsub!(/%%dbHost%%/, "localhost")
+ line.gsub!(/%%dbName%%/, "civicrm")
+ line.gsub!(/%%crmRoot%%/, "#{civicrm_directory}/civicrm/")
+ line.gsub!(/%%templateCompileDir%%/, "/srv/join.osmfoundation.org/wp-content/uploads/civicrm/templates_c/")
+ line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
+ line.gsub!(/%%siteKey%%/, site_key)
+ line.gsub!(/%%credKeys%%/, cred_keys)
+ line.gsub!(/%%signKeys%%/, sign_keys)
+ line.gsub!(%r{// *define\('CIVICRM_CMSDIR', '/path/to/install/root/'\);}, "define('CIVICRM_CMSDIR', '/srv/join.osmfoundation.org');")
+
+ line
+end
+
+file "#{civicrm_directory}/civicrm.settings.php" do
+ owner "wordpress"
+ group "wordpress"
+ mode "644"
+ content settings
+end
+
+systemd_service "osmf-crm-jobs" do
+ description "Run CRM jobs"
+ exec_start "/usr/bin/php #{civicrm_directory}/civicrm/bin/cli.php -s join.osmfoundation.org -u batch -p \"#{passwords['batch']}\" -e Job -a execute"
+ user "www-data"
+ sandbox :enable_network => true
+ memory_deny_write_execute false
+ restrict_address_families "AF_UNIX"
+ read_write_paths "/srv/join.osmfoundation.org/wp-content/uploads/civicrm"
+end
+
+systemd_timer "osmf-crm-jobs" do
+ description "Run CRM jobs"
+ on_boot_sec "15m"
+ on_unit_inactive_sec "15m"
+end
+
+service "osmf-crm-jobs.timer" do
+ action [:enable, :start]