From fcea25bf27c9a270f01f9bec83a23616af3a1232 Mon Sep 17 00:00:00 2001
From: Eric DenBraber <ericrdb@gmail.com>
Date: Thu, 30 Jan 2014 22:24:52 -0700
Subject: [PATCH] By ericrdb: Install Drupal for listed sites during provision.

---
 README.txt                              |  3 +++
 config.json                             | 10 ++++++----
 cookbooks/core/vdd/recipes/vdd_sites.rb | 25 ++++++++++++++++---------
 roles/vdd.json                          |  4 ++--
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/README.txt b/README.txt
index f67daf6..5f14e29 100644
--- a/README.txt
+++ b/README.txt
@@ -220,6 +220,9 @@ valid. http://jsonlint.com/ can help to check it.
           * site_mail (string, required)
             Drupal site email.
 
+          * drupal_version (string, required)
+            Drupal major or point release version. For example: "7" or "7.26"
+
   * xdebug (object of strings, optional)
     Xdebug configuration.
 
diff --git a/config.json b/config.json
index 45304bc..0622452 100644
--- a/config.json
+++ b/config.json
@@ -18,14 +18,16 @@
       "account_pass": "root",
       "account_mail": "box@example.com",
       "site_name": "Drupal 7",
-      "site_mail": "box@example.com"
+      "site_mail": "box@example.com",
+      "drupal_version": "7"
     },
-    "drupal8": {
+    "drupal7.24": {
       "account_name": "root",
       "account_pass": "root",
       "account_mail": "box@example.com",
-      "site_name": "Drupal 8",
-      "site_mail": "box@example.com"
+      "site_name": "Drupal 7.24",
+      "site_mail": "box@example.com",
+      "drupal_version": "7.24"
     }
   },
   "git": {
diff --git a/cookbooks/core/vdd/recipes/vdd_sites.rb b/cookbooks/core/vdd/recipes/vdd_sites.rb
index 1f0aef1..07386aa 100644
--- a/cookbooks/core/vdd/recipes/vdd_sites.rb
+++ b/cookbooks/core/vdd/recipes/vdd_sites.rb
@@ -3,14 +3,6 @@ if node["sites"]
   node["sites"].each do |index, site|
     include_recipe "database::mysql"
 
-    htdocs = "/var/www/#{index}"
-    directory htdocs do
-      owner "vagrant"
-      group "vagrant"
-      mode "0755"
-      action :create
-    end
-
     mysql_connection_info = {
       :host => "localhost",
       :username => "root",
@@ -21,5 +13,20 @@ if node["sites"]
       action :create
     end
 
+    # Install Drupal if it doesn't exist.
+    bash "create_drupal_site_#{index}" do
+      user "vagrant"
+      group "vagrant"
+      code <<-EOH
+        cd /var/www && rm -rf #{index}
+        drush dl drupal-#{site["drupal_version"]} --drupal-project-rename=#{index}
+        drush @#{index} si standard install_configure_form.update_status_module='array(FALSE,FALSE)' --yes
+        EOH
+      not_if do
+        puts "checking if #{index} already exists"
+        ::File.exists?("/var/www/#{index}/sites/default/settings.php")
+      end  
+    end
+  
   end
-end
+end
\ No newline at end of file
diff --git a/roles/vdd.json b/roles/vdd.json
index 44f67ad..ae1a2e8 100644
--- a/roles/vdd.json
+++ b/roles/vdd.json
@@ -16,9 +16,7 @@
     "recipe[mysql::server]",
     "recipe[vdd::bash]",
     "recipe[vdd::apache]",
-    "recipe[vdd::vdd_sites]",
     "recipe[vdd::php]",
-    "recipe[vdd::drush]",
     "recipe[vdd::phpmyadmin]",
     "recipe[vdd::mysql]",
     "recipe[vdd::xdebug]",
@@ -26,6 +24,8 @@
     "recipe[vdd::mc]",
     "recipe[vdd::rsync]",
     "recipe[vdd::curl]",
+    "recipe[vdd::drush]",
+    "recipe[vdd::vdd_sites]",    
     "recipe[vdd::vdd_help]"
   ],
   "description": "VDD Apache, PHP, MySQL plus other tools configuration.",
-- 
1.8.4.2

