Drupal Module Update Script

Here is a bash script for updating a Drupal module to a given version and archiving it (in case reversion is needed)

Usage:

  • ./update.sh --help
  • ./update.sh drupal 6.2 #installs drupal 6.2 into the default directory
  • ./update.sh views 6.x-2.x-dev
  • ./update.sh dhtml_menu 6.x-1.04
  • ./update.sh zen 6.x-1.x-dev /var/www/themes #alternative install path specified

Note that if you are checking out a module, rather than Drupal core, the name of the module will be appended to the path where it is to be put. Also note that this script assumes that the Drupal core tree can be deleted, i.e. the sites directory within the tree is not used. I would strongly recommend that the actual website be in a different directory and symlink into the drupal tree, for easy updating. For information on how to do this, look here

drupalpath.sh - Include file for default paths

#Paths to Drupal core files and contrib modules
#Modify the next three lines to suit your configuration
drupaldir=/var/www/drupal
targetdir=/var/www/modules
archivedir=/var/www/archive

update.sh - Check Drupal core/modules out of CVS

#!/bin/bash
desc="Update Drupal module to a given version"
usage="$0 <name_of_module>  <version>  [alternative install path]"
source drupalpath.sh
ftpdir=http://ftp.drupal.org/files/projects/

if [ $# -lt 2 ]; then
  if [ "$1" != "--help" ]; then
    echo "  ** wrong number of arguments supplied **"
  fi
  echo " " $desc
  echo "  Usage:" $usage
  exit
fi
if [ -n "$3" ]; then           # alternative install directory
  if [ "$1" == "drupal" ]; then
    drupaldir=$3
  else
    targetdir=$3
  fi
fi

echo installing $1-$2 into $targetdir
wget -q $ftpdir/$1-$2.tar.gz
return_val=$?
if [ "$return_val" -ne 0 ]; then
  echo "failed to wget $ftpdir/$1-$2.tar.gz"
  exit
fi
rm -fR $targetdir/$1     #delete old version
chdate=`stat -c %y $1-$2.tar.gz | awk '{printf $1 "\n"}'`
tar -zxf $1-$2.tar.gz -C $targetdir
mv $1-$2.tar.gz $archivedir/$1-$2_$chdate.tar.gz
if [ "$1" == "drupal" ]; then
  echo "   Moving new version of drupal from:" $targetdir/$1-$2 to $drupaldir
  rm -fR $drupaldir
  mv $targetdir/$1-$2 $drupaldir
fi
AttachmentSize
update.txt1 KB