Using drush with the Drupal Script Library

UPDATE: See comments below for update to this post.

This is a discussion on how to integrate drush into a Drupal environment set up with my Drupal Scripts Library.

While I do think the administration services offered by my Drupal Scripts Library are generally better than those offered by drush for administering collections of Drupal websites; I acknowledge that drush has its usefulness.  Drush has a flexible plug-in architecture and there are lots of extensions contributed by the Drupal community.  Also, drush is written in PHP which allows it to leverage functionality from within the Drupal installation itself.  In said environment, there is no need to use drush to install and update code; but there is other functionality that can be leveraged.


Installing drush is fairly straight-forward.  It is packaged as a Drupal module and available in Drupal's contrib CVS space.  The easiest way to download it is to use the script: -versiontag HEAD install module drush <site name>

where <site name> is any site in your install group.  The CVS HEAD branch is used as that's the most up-to-date version of drush.  You're free to use another tag if you want although you have to specify something -- drush doesn't follow the standard naming convention for contrib themes/modules as it's not really either of those...

After the install, you can move the just-loaded code..

mv "` sitedir "<site name>"`/modules/contrib/drush" ${HOME}

(Moves the 'drush' directory to your home directory -- you can move it where to ever you choose.)


Now that drush is installed, we need a way of calling drush with the required parameters so that drush can operate correctly.  Drush, by default, assumes an installations "site dir" (directory with the active 'settings.php' file) is the 'default' directory where the Drupal Script Library uses the convention that the site dir is .../sites/<site name>.  Using the drush's '-l' parameter will get around this ('-l' supports multisite installations).  Also, we must tell drush the directory in which the site is installed.

Here's a script that will make the correct call:


# Runs drush
# Usage: $0 <site name> drush commands

PHP="<path to PHP executable>/php"

if [[ -n "${site}" && -n "` listsites | grep ${site}`" ]]; then
	siteroot="` siteroot "${site}"`"
	"${PHP}" "${DRUSH_ROOT}/drush.php" -r "${siteroot}" -l "http://${site}/" $*
	"${PHP}" "${DRUSH_ROOT}/drush.php" $*

The script generates the required values for the '-r' and '-l' parameters and then calls the drush script with any extra parameters.

Hope this helps.

Free Tag:


Be sure to see the post Using drush with the Drupal Script Library, revisited -- it is now much easier to integrate the two systems. 

The sample script supplied is now available as a bash procedure call set up in the script as 'ddrush'.

Note, the script mentioned in this post has been renamed to  Read more in my post on converting the Drupal Script Library to use Git.

Note that the '' script mentioned in the previous comment has been renamed to '' which uses Drush to do the download/install operations.