Shell script to simplify Drupal CVS module checkouts

I am finally fed up enough with the multi-step process for checking out a Drupal contrib module that I created a simple shell script to do the dirty work for me. This script is named cvs_checkout_module.sh (imaginative, huh?). In hopes that this might be of interest/use to others... here it is.

#!/bin/bash
#####################################################################
# This script checks out a contrib module.
# It sets up the environment first, and then does a CVS login and 
# a CVS checkout.
#####################################################################
 
if [[ $# == 0 ]]; then
  echo "Usage: $0 module_name [branch_or_tag]"
  echo " "
  echo "  module_name: "
  echo "    Module name must be the name of the module  in Drupal's CVS repo."
  echo "  branch_or_tag: "
  echo "    If no branch/tag is specified, HEAD will be used."
  echo " "
  echo "Example: "
  echo "  $0 cacheexclude DRUPAL-6--2"
  echo " "
  exit 1;
fi
 
# This directory will be created, and then used to house the 
# new code.
dest="./$1/$2"
 
mkdir -p $dest
cd $dest
 
export CVSROOT=:pserver:$DRUPAL_USERNAME@cvs.drupal.org:/cvs/drupal-contrib
cvs login
 
TAG='HEAD';
if [[ $# > 1 ]]; then
  TAG=$2;
fi
 
echo "Checking out $1 with revision $TAG"
cvs -z6 checkout -r $TAG -d $1 contributions/modules/$1

(The code above is public domain. Use it however.)

Make sure to set $DRUPAL_USERNAME to your username.

Running this script is as easy as this:

$ ./cvs_checkout_module.sh cacheexclude DRUPAL-6--2

This will check out the DRUPAL-6--2 branch of the cacheexclude module.

How the code works

The code above does the following:

  • It creates a new directory of the form ./MODULE_NAME/TAG. For example, ./cacheexclude/DRUPAL-6--2. This allows you to conveniently keep multiple versions of a module in the same place.
  • It logs into the Drupal CVS server. Again, make sure that $DRUPAL_USERNAME is set.
  • It checks out the new module into the appropriate directory.

When this is done, you should have a directory layout looking like this:

./cacheexclude/
  DRUPAL-6--2/
    cacheexclude/
      cacheexclude.module
      cacheexclude.info
      # etc.

Checking out multiple branches of the same project
Need to grab another branch? You can run the same command again, passing a different branch:

$ ./cvs_checkout_module.sh cacheexclude DRUPAL-5--2

That will give you a directory layout that looks like this:

./cacheexclude/
  DRUPAL-6--2/
    cacheexclude/
      cacheexclude.module
      cacheexclude.info
      # etc.
  DRUPAL-5--2/
    cacheexclude/
      cacheexclude.module
      cacheexclude.info
      # etc.

From inside of each of branch directories, you can use CVS as usual.

Anonymous users...

Want to check out as an anonymous user? I think you should be able to simply set $DRUPAL_USERNAME to anonymous. In the shell, that's

export DRUPAL_USERNAME='anonymous'
./cvs_checkout_module.sh cacheexclude DRUPAL-6--2

This is an incredible module,

This is an incredible module, thank you for sharing it!

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.
  • Images can be added to this post.

More information about formatting options