Install Drupal and contributed modules and themes via cvs

The quickest and most efficient way to maintain a Drupal installation is in my opinion to install and update it via cvs. It looks complicated to start with but my experience is that when you get used to it you don’t want to do it any other way.

I will assume you already have cvs installed or otherwise know how to do it on your server. You also need to have shell access and be familiar with the command line. If this is not true you better stop reading :-).

Original article 2006-10-31, new revision 2007-11-16.

Update 2009-06-25: If this stuff interest you I warmly recommend Drush, a command line shell and Unix scripting interface for Drupal.

I will describe how a cvs install is done manually. Later I will show a couple of shell script to automate the procedure.

There are two Drupal modules that you should install first.

CVS deploy - Get the right version information for modules installed via cvs. The version information is used by the update status module and on the modules page at admin/build/modules. When you install modules via cvs the info files has no version info (they should’t have any at least).

Update status - Checks with drupal.org to see if there are new officially released versions of Drupal and any modules that you are running. Is part of core in Drupal 6.

With these two modules you will have all the module name and version information you need on one page, Available updates at admin/logs/updates. You load the “Available updates” page, put a Terminal window next to it and then get to work updating your Drupal installation.

For cvs I recommend you start by setting some good default options in the file ~/.cvsrc. See man cvs for more information about the option. This is what I use:

cvs -z3
update -dP
checkout -P
diff -up
log -N

Now we are ready to start installing. Assume we want to install Drupal on a shared host in a directory named “web”. First go to the parent directory of “web” and then use the following command to install Drupal 5.3 in the “web” directory.

cvs -d :pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout -d web -r DRUPAL-5-3 drupal

You will now have the Drupal 5.3 code installed on your server.

Next up is to install some contributed modules and themes. There are a couple of different places you may choose to install these.

  • The main modules and theme directories together with the core files.
  • A sub directory, e.g. named “contrib” in the above directories.
  • Create your own modules and theme directories in sites/default or sites/example.com.

I favor the last option. This will keep core and contributed code separate and it will also keep all site specific code together. Many times I also put the files directory in the same place.

Change to the directory where you want to install the contributed modules. The following command will install version 5.x-1.1 of the Thickbox module in in a directory named “thickbox”.

cvs -d :pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d thickbox -r DRUPAL-5--1-1 contributions/modules/thickbox

Change to the directory where you want to install the contributed themes. The following command will install version 5.x of the Slash theme in a directory named “slash”.

cvs -d :pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d slash -r DRUPAL-5 contributions/themes/slash

Now it’s time keep all the code updated. You will need to do it once for the core Drupal install and once for each and every contributed module and them you have installed. The updates is done by going to the directory of the Drupal/module/theme install, e.g. web/thickbox/slash in the examples above, and give the following command. Replace “5—x-x” with the version you want.

cvs update -dP -r DRUPAL-5--x-x

It’s a good habit to make a dry run first by adding the option “-n”. This will not change any file, only report what would have happend.

cvs -n update -dP -r DRUPAL-5--x-x

If you followed my advice to set up a .cvsrc file with the default I suggested you can just do a cvs update -r DRUPAL-5--x-x instead.

If you have many contributed modules and themes it will be a small hassel to go through all the directories and issue the cvs update command. Compared to the alternatives it’s still a very quick and painless process.

To make it even better we can make some shell script to run the commands for us. Below you find one script to checkout (install) and one to update Drupal core, modules and themes via cvs. You can name them anything you like, I use “cvsdr” and “cvsup”. Short names, less typing.

cvsdr

#!/bin/sh
# $Id: cvsdr,v 1.1 2006/10/31 18:52:37 frjo Exp $
#
# Script to checkout Drupal core, modules and themes via cvs.

if [ "$1" = "" ]; then
  echo "Usage: name tag c|m|t (core/modules/themes) defaults to HEAD/module";
  exit 1;
fi

cmd="/usr/bin/cvs -d :pserver:anonymous:anonymous@cvs.drupal.org";

name=$1;
tag=`echo $2 | sed 's/DRUPAL-//'`;
type=$3;

if [ "${tag}" = "" ]; then
  tag="HEAD";
else
  tag=DRUPAL-${tag};
fi

if [ "${type}" = "t" ]; then
  type="themes";
elif [ "${type}" = "c" ]; then
  type="core";
else
  type="modules";
fi

if [ "${type}" = "core" ]; then
  echo "Doing this: /cvs/drupal checkout -d ${name} -r ${tag} drupal";
  ${cmd}:/cvs/drupal checkout -d ${name} -r ${tag} drupal;
else
  echo "Doing this: /cvs/drupal-contrib checkout -d ${name} -r ${tag} contributions/${type}/${name}";
  ${cmd}:/cvs/drupal-contrib checkout -d ${name} -r ${tag} contributions/${type}/${name};
fi

# end

cvsup

#!/bin/sh
# $Id: cvsup,v 1.1 2006/10/31 18:52:37 frjo Exp $
#
# Script to update Drupal core, modules and themes via cvs.

if [ "$1" = "" ]; then
  echo "Usage: tag : defaults to HEAD";
  exit 1;
fi

if [ "$2" != "" ]; then
  dry=" -n"
fi

cmd="/usr/bin/cvs${dry} update -dP";


tag=`echo $1 | sed 's/DRUPAL-//'`;

if [ "${tag}" = "" ]; then
  tag="HEAD";
else
  tag=DRUPAL-${tag};
fi

echo "Doing this: cvs${dry} update -dP -r ${tag}";
${cmd} -r ${tag};

# end

More reading:

Comments

Shell Access

And what it you don't have shell access?

If you have no shell access

If you have no shell access you can't use cvs in this way. You are stuck with manual uploads via FTP or something. My suggestion is to find a new web host that offer shell access.

Very handy little scripts

Jättebra små script, dom tackar man för! Grattis till en bra ranking hos Google, jag kom hit direkt genom att söka på "drupal install cvs". Hoppas resan är/blir trevlig, vi hörs senare!

Shared hosting allows this?

I have a shared hosting account. Will they allow CVS?

Some do, some don't. I make

Some do, some don't. I make sure all my customers have accounts on the ones that have cvs.

Thank you for this howto and

Thank you for this howto and the scripts, frjo!

I have some questions about the usage of the scripts:

1. Is cvsdr capable of creating a brand new install of Drupal on a new system?

2. Is the argument "name" soley the directory where drupal will sit?

3. How would I assemble an apropiate tag for let's say version 6.10?

Can you pleas give some examples on how to operate those shell scripts of yours? Especially cvsdr puzzles me a bit.

These script are for

These script are for developers who now cvs but want to type less. I strongly recommend that you take the time to learn the cvs command and then the script will make sense to you.

1 and 2 If you are unsure of the script you should use the full cvs commands instead.

3 On the release notes you can see the cvs tag, it the first line that says "Official release from CVS tag: DRUPAL-6-n".

Finding .cvsrc

Hello Frjo,

I'm a relative newbie of using the command line and linux, I am running Darwin on mac osx 10.3.9

Whilst I have managed to install CVS and install from drupal.org, I hcan not seem to find the .cvsrc file. Please could you tell me where (or how) I can find it?

If I do:
% vim ~/cvsrc a new file is opened, rather than opening the config file. So it does not seem to be in my how directory.

If I do:
% find / -name "*.cvsrc", no results are returned.

Thank-you in advance,
Michelle

RE: Finding .cvsrc

Not to worry, I simply created it.

Thanks
Michelle

Post new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.
Syndicate content