2 # Cookbook Name:: civicrm
 
   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 #     http://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 "drupal"
 
  21 include_recipe "mysql"
 
  23 passwords = data_bag_item("civicrm", "passwords")
 
  25 database_password = passwords["database"]
 
  26 admin_password = passwords["admin"]
 
  27 site_key = passwords["key"]
 
  29 mysql_user "civicrm@localhost" do
 
  30   password database_password
 
  33 mysql_database "civicrm" do
 
  34   permissions "civicrm@localhost" => :all
 
  37 drupal_site "crm.osmfoundation.org" do
 
  39   database_name "civicrm"
 
  40   database_username "civicrm"
 
  41   database_password database_password
 
  42   admin_password admin_password
 
  45 directory "/usr/local/share/civicrm" do
 
  51 civicrm_version = node[:civicrm][:version]
 
  52 civicrm_directory = "/usr/local/share/civicrm/#{civicrm_version}"
 
  54 subversion civicrm_directory do
 
  56   repository "http://svn.civicrm.org/civicrm/tags/tarballs/#{node[:civicrm][:version]}"
 
  61 link "/usr/share/drupal7/sites/all/modules/civicrm" do
 
  62   to "/usr/local/share/civicrm/#{node[:civicrm][:version]}"
 
  65 directory "/data/crm.osmfoundation.org/civicrm" do
 
  71 ruby_block "#{civicrm_directory}/civicrm.settings.php" do
 
  73     out = File.new("#{civicrm_directory}/civicrm.settings.php", "w")
 
  75     File.foreach("#{civicrm_directory}/templates/CRM/common/civicrm.settings.php.tpl") do |line|
 
  76       line.gsub!(/%%cms%%/, "Drupal")
 
  77       line.gsub!(/%%CMSdbUser%%/, "civicrm")
 
  78       line.gsub!(/%%CMSdbPass%%/, database_password)
 
  79       line.gsub!(/%%CMSdbHost%%/, "localhost")
 
  80       line.gsub!(/%%CMSdbName%%/, "civicrm")
 
  81       line.gsub!(/%%dbUser%%/, "civicrm")
 
  82       line.gsub!(/%%dbPass%%/, database_password)
 
  83       line.gsub!(/%%dbHost%%/, "localhost")
 
  84       line.gsub!(/%%dbName%%/, "civicrm")
 
  85       line.gsub!(/%%crmRoot%%/, "/usr/share/drupal7/sites/all/modules/civicrm")
 
  86       line.gsub!(/%%templateCompileDir%%/, "/data/crm.osmfoundation.org/civicrm")
 
  87       line.gsub!(/%%baseURL%%/, "http://crm.osmfoundation.org/")
 
  88       line.gsub!(/%%siteKey%%/, site_key)
 
  97     File.exist?("#{civicrm_directory}/civicrm.settings.php") and
 
  98     File.mtime("#{civicrm_directory}/civicrm.settings.php") >= File.mtime("#{civicrm_directory}/templates/CRM/common/civicrm.settings.php.tpl")
 
 102 link "/etc/drupal/7/sites/crm.osmfoundation.org/civicrm.settings.php" do
 
 103   to "#{civicrm_directory}/civicrm.settings.php"
 
 106 template "#{civicrm_directory}/settings_location.php" do
 
 107   source "settings_location.php.erb"
 
 113 execute "civicrm-load-acl" do
 
 115   command "mysql --user=civicrm --password=#{database_password} civicrm < sql/civicrm_acl.mysql"
 
 116   cwd "/usr/share/drupal7/sites/all/modules/civicrm"
 
 121 execute "civicrm-load-data" do
 
 123   command "mysql --user=civicrm --password=#{database_password} civicrm < sql/civicrm_data.mysql"
 
 124   cwd "/usr/share/drupal7/sites/all/modules/civicrm"
 
 127   notifies :run, "execute[civicrm-load-acl]"
 
 130 execute "civicrm-load" do
 
 132   command "mysql --user=civicrm --password=#{database_password} civicrm < sql/civicrm.mysql"
 
 133   cwd "/usr/share/drupal7/sites/all/modules/civicrm"
 
 136   notifies :run, "execute[civicrm-load-data]"
 
 139 execute "civicrm-gencode" do
 
 140   command "php GenCode.php"
 
 141   cwd "#{civicrm_directory}/xml"
 
 144   creates "#{civicrm_directory}/civicrm-version.php"
 
 145   notifies :run, "execute[civicrm-load]"
 
 148 directory "/data/crm.osmfoundation.org/civicrm/en_US" do
 
 154 directory "/data/crm.osmfoundation.org/civicrm/en_US/ConfigAndLog" do
 
 160 template "/etc/cron.daily/osmf-crm-backup" do
 
 161   source "backup.cron.erb"
 
 165   variables :passwords => passwords