cvsdrupal - checkout and maintain a local CVS repository

Last modified: February 18, 2009 - 12:25

This sophisticated script will check out Drupal and any number of contrib modules into a multisite (optionally) directory tree.

It does check out the most recent files for tag selected in $REL, so if you do not want this, you'll have to cvs up to the tag you want.

The file is attached for download - just change it from a .txt to a .sh file.

#!/bin/sh
#
# cvsdrupal v0.0.3 20071101 cody@ray.name
#
# Multisite CVS Drupal Manager
#
# Initializes and maintains a multisite Drupal installation
# from the CVS codebase. Additionally, this script manages
# global and per-site modules and themes in the same manner.
#
# Run this daily or weekly with cron to keep your checkouts
# up to date with all bug fixes and security patches
# applied to your release in CVS.
#
# You define your site configurations in newline-delineated
# string arrays. There are three classes of such configuration
# arrays used in this script: SITES, _MODULES, _THEMES.
#
# For instance, you want to host two websites with shared
# modules, example.net and www.example.com:
#
   SITES="
#     all
#     example.net
#     www.example.com
#
   "
#
# The pseudo-site 'all' creates an 'all' subdirectory of 'sites'
# in your Drupal installation. This is the parent of all shared
# modules, themes, profiles, etc.
#
# Thus, you can create shared resources
#   all_MODULES="
#     subversion
#     svn
#   "
#   all_THEMES="
#     meta
#   "
#
# Each website you define (in SITES) is allowed its own modules
# and themes independent of the other sites in your installation,
# or it may use shared resources, or both. The decision is left
# to you.
#
# Or, to continue our example, you can create per-site resources
#   example_net_MODULES="
#     image
#     img_assist
#   "
#   example_net_THEMES="
#     dichotomy
#   "
#   www_example_com_MODULES="
#     diff
#     pathauto
#   "
#   www_example_com_THEMES="
#     combustion
#   "
#
# Be sure to replace the dots with underscores in the names of the
# per-site configurations. Also, note that any or all of these
# configurations can be blank or left out altogether.
#
# The configuration above has been included as a skeleton for your
# own website(s). See these included examples for further usage
# details in context of the code.
#
# License: http://www.gnu.org/licenses/gpl.txt
#
Change these settings to suit your environment:
#
#   REL   the CVS codebase version you want to checkout,
#         leave as is for a stable release or change to
#         HEAD for the very latest developments
#
#   BASE  root path in which the "drupal" folder resides
#
#   UGID  the local user:group file permissions,
#         set empty to ignore
#
# CHANGELOG:
#   2007-11-01 Cody Ray <cody@ray.name>
#       * adapted for multisite usage
#       * with more sensible defaults
#
#   2006-06-28 Mark Constable <markc@renta.net>
#       * initial implementation
#

REL=DRUPAL-5
BASE=/var/www
UGID=www-data:www-data

# Add your sites

SITES="
    all
    example.net
    www.example.com
"
#
Add shared modules

all_MODULES="
    subversion
    svn
"
# Add site-specific modules

example_net_MODULES="
    image
    img_assist
"
www_example_com_MODULES="
    diff
    pathauto
"
# Add shared themes

all_THEMES="
    meta
"
# Add site-specific themes

example_net_THEMES="
    dichotomy
"
www_example_com_THEMES="
    combustion
"
# Below here should remain untouched

SRC=:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal
export CVSROOT=$SRC

[ -d $BASE/drupal/sites/all/modules ]            || mkdir -p $BASE/drupal/sites/all/modules
[ -d $BASE/drupal/sites/all/themes/engines ]     || mkdir -p $BASE/drupal/sites/all/themes/engines
[ -d $BASE/drupal/sites/all/themes/custom ]      || mkdir -p $BASE/drupal/sites/all/themes/custom
[ -d $BASE/drupal/sites/all/themes/contrib ]     || mkdir -p $BASE/drupal/sites/all/themes/contrib
[ -d $BASE/drupal/sites/default/modules ]        || mkdir -p $BASE/drupal/sites/default/modules
[ -d $BASE/drupal/sites/default/themes/custom ]  || mkdir -p $BASE/drupal/sites/default/themes/custom
[ -d $BASE/drupal/sites/default/themes/contrib ] || mkdir -p $BASE/drupal/sites/default/themes/contrib

if [ -d $BASE/drupal/CVS ]; then
    cd $BASE/drupal
    cvs -z6 up . -PAd -r $REL
else
    cd $BASE
    cvs -z6 co -r $REL drupal
fi

for S in $SITES; do
    [ -d $BASE/drupal/sites/$S ] || cp -a $BASE/drupal/sites/default $BASE/drupal/sites/$S
done

export CVSROOT=${SRC}-contrib

for S in $SITES; do
    N=`echo $S|sed -e 's/\./_/g'`
    for M in $(eval echo \$${N}_MODULES); do
        if [ -d $BASE/drupal/sites/$S/modules/$M/CVS ]; then
            cd $BASE/drupal/sites/$S/modules/$M
            cvs -z6 up . -PAd
        else
            cd $BASE/drupal/sites/$S/modules
            cvs -z6 co -d $M contributions/modules/$M
        fi
    done
done

for S in $SITES; do
    N=`echo $S|sed -e 's/\./_/g'`
    for T in $(eval echo \$${N}_THEMES); do
        if [ -d $BASE/drupal/sites/$S/themes/$T/CVS ]; then
            cd $BASE/drupal/sites/$S/themes/$T
            cvs -z6 up . -PAd
        else
            cd $BASE/drupal/sites/$S/themes
            cvs -z6 co -d $T contributions/themes/$T
        fi
    done
done

[ ! -z $UGID ] && chown $UGID -R $BASE/drupal

# vim: ts=4 sw=4 noet sts=4

AttachmentSize
cvsdrupal.sh_.txt4.9 KB
 
 

Drupal is a registered trademark of Dries Buytaert.