More automation with Drush shebang shell scripting

Last weekend our dev team attended the Pacific Northwest Drupal Summit. We had a blast, we nerded out about Foundation and we learned a lot (especially about SCSS and Compass). We were taking furious notes and we can expect some big changes to come to our Cogito Foundation theme in the coming weeks. 

 

We also did a presentation where we took a website from design to build to theming to launch in front of a live audience in 45 minutes. People said we were crazy (and the jury is still out on that one) but it worked like a charm and the demo gods were with us.

 

 

One of the things we demonstrated was how to use a .make file with 'drush make'. Drush make goes out and pulls in all the modules, themes and features you need to set up a site. Once drush make is finished you have to do a regular site install, enable your themes and plugins etc.

I was watching Colin present this and I thought to myself " This is awesome but there must be a way to automate all the fiddly bits you need to do after your make file runs."

 

So we went to work and came up with the following script, annotated using Gist and Zurb's Chop App for your convenience

 

Commented using Zurb's chop app. http://chopapp.com/#b9ihtok3

 

There's nothing magic or super innovative here. All the pieces have been available to us for quite some time but when we assemble them all together in a script we get a significant time savings on iterative builds of a site.

Ok, so what does this script do:

  1. You fill out your site details, modules, features you want to enable etc. at the top of the file.
  2. It then runs 'drush make' on the make file you specify
  3. Then it does a drupal install with the credentials you specify
  4. Turn on the modules we care about, turn off the modules we don't care about
  5. Create a new cogito subtheme and change its name to match our site.
  6. Enable features and themes (including our new child theme)
  7. run cron
  8. clear the cache

 

A better way

 

As it turns out drush has all kinds of goodness to do things automatically and make our lives better. One of the little known things about it is that you can use it inside a shebang script with PHP. 

 

here are a couple of resources to outline how that works:

 

drush site-install?!? NO WAY!!!!

This is a big discovery for us because when we're iterating through our builds we end up doing a lot of installs every day. Now with one drush command we can enter all our admin user details, our database credentials and perform a standard site install.

 

Take a look at line 51 of the script to see it in action. 

 

Exciting future

 

We just started with these drush shell scripts so if you've been using them for a while and do really neat things we'd love to hear from you.