+extensions_directory = "/srv/join.osmfoundation.org/wp-content/plugins/civicrm-extensions"
+
+directory extensions_directory do
+ owner "wordpress"
+ group "wordpress"
+ mode 0o755
+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/plugins/files/civicrm/templates_c/")
+ line.gsub!(/%%baseURL%%/, "http://join.osmfoundation.org/")
+ line.gsub!(/%%siteKey%%/, site_key)
+ line.gsub!(%r{// *(.*'ext_repo_url'.*)$}, "\\1")
+ 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 0o644
+ content settings
+end
+
+template "/etc/cron.d/osmf-crm" do
+ source "cron.erb"
+ owner "root"
+ group "root"
+ mode 0o600
+ variables :directory => civicrm_directory, :passwords => passwords