image/svg+xml Openclipart 2007-11-20T10:29:44 Some shapes from photos. http://openclipart.org/detail/8766/tree-silhouettes-by-chrisdesign-8766 Chrisdesign clip art clipart image media nature png public domain shape silhouette svg tree

zzolo

Drush, a King Among Men

16 Mar 2009

Drush is wonderful. I discovered it about six to nine months ago and can’t even fathom the amount of time it has saved me. Thank you, Drush, more specifically the wonderful developers on the project.

Drush Basics

If you are not in the know, and it’s okay if you are not, Drush is a command line application for Drupal. Drush by itself is more of a framework, and becomes much more powerful and useful in conjunction with Drush Extras. Once you have set things up, you can do something like:

drush pm install cck views imagecache

This would install (cvs checkout to sites/all/modules) the CCK, Views, and ImageCache modules. You would still have to go to the web administration to enable the modules. But, how easy is that! I am starting to put put together Drush install profiles, instead of using Drupal’s install profiles. (I understand that these are two very different utilities) For instance, I have put together this single command that will checkout all the latest versions of my usual modules for site:

drush -l http://example.org pm install admin_menu advanced_help better_formats calendar cck date devel favicon filefield globalredirect gmap google_analytics imageapi imagecache imagecache_actions imagefield jquery_update lightbox2 link location logintoboggan markdown mollom pathauto token views seo_checklist context spaces cvs_deploy coder nodequeue wysiwyg webform xmlsitemap emfield jq jquery_media content_profile twitter flickr job_queue

And then, I can review and update them all via the following command.

drush -l http://example.org pm update

You still have to visit update.php and, with any contributed module, make sure it doesn’t break your site.

Recent Drush Presentation

At DrupalCon DC just a couple weeks back, Moshe Weitzman and Owen Barton did the presentation: Drush, Command Line Drupal Productivity. Watch the video

Simple Script to Help Setup Drush

Since the only slight problem with Drush is setting up, which has gotten much easier in the the new 2.x branch, I have created a simple shell script to help automate it. I am not that experienced with shell scripting, but this works in my environment and is a good place to start otherwise.

#BEGIN drush-install.sh

#!/bin/sh

###############################


# General variables

DRUSHPATH='/home/alanpalazzolo/.drush';
DRUSHDOWNLOAD='http://ftp.drupal.org/files/projects/drush-6.x-2.x-dev.tar.gz';
DRUSHEXTRASDOWNLOAD='http://ftp.drupal.org/files/projects/drush_extras-6.x-2.0-alpha1.tar.gz';
ALIASFILE='/home/alanpalazzolo/.bash_profile';
DRUSHALIAS='drush';

# Check directory

if \[ -d $DRUSHPATH \]; then
  echo "Drush directory exists.";
else
  echo "Creating drush directory.";
  mkdir $DRUSHPATH;
fi

# Go to drush dir

echo "Going to drush directory.";
cd $DRUSHPATH;

# Get drush

echo "Download and untar drush.";
wget $DRUSHDOWNLOAD;
tar -zxvf drush-*;

# Get drush_extras

echo "Download and untar drush_extras.";
wget $DRUSHEXTRASDOWNLOAD;
tar -zxvf drush_extras-*;

# Make a handy alias

echo "Make alias in: $ALIASFILE";
echo "# Drush alias auto added" >> $ALIASFILE;
echo "alias $DRUSHALIAS='php $DRUSHPATH/drush/drush.php'" >> $ALIASFILE;
echo "You may have to restart your shell session for the alias to take effect.";