#!/bin/sh # Drupal Update Script # Written by: Benjamin Shell # Created: September 5, 2008 # Updated: March 18, 2009 # License: GNU GPL # # This script can be used to update the files affected by Drupal maintenance releases. # When Drupal is checked out with CVS this script isn't necessary, but this method # of updating works great when subversion is used for a site. # # INSTRUCTIONS: # 1) Put this file somewhere within your PATH, or create an alias to it. # 2) Navigate to the Drupal root of the site you want to update (where index.php lives). # 3) Call this script. # # IMPORTANT NOTE: # This only works for Drupal versions 4.7 and greater. Anything older will be updated to # Drupal 4.7 which will break lots of things. # constants: DRUPALSRC="/Users/ben/localhost/src" # print the current path of the Drupal site to update CWD=`pwd` # verify that the current working directory contains Drupal (check for the index.php file) if [ ! -f $CWD/index.php ] then echo "ERROR: The current directory doesn't contain a Drupal site!" exit 0 fi echo "Drupal site to update: $CWD" # Find old Drupal version by searching the CHANGELOG file OLDREV=`awk -F"," '/Drupal [0-9.]/ { print $1; exit }' CHANGELOG.txt` # The $OLDREV variable should be in the form Drupal 5.15 but needs to be converted to # the syntax used by CVS (DRUPAL-5-15) OLDREV=`echo $OLDREV | tr '[:lower:]' '[:upper:]'` OLDREV=`echo $OLDREV | tr '[:blank:]' '-'` OLDREV=`echo $OLDREV | tr '.' '-'` echo "This site is currently running $OLDREV." # Get major version of current Drupal installation MAJORVER=`echo $OLDREV | awk -F"-" '{ print $2; exit }'` # Find newest available Drupal version cd /tmp cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal rlog drupal/index.php > index.php.log PATTERN="DRUPAL-$MAJORVER-[0-9-]+" NEWREV=`awk -F":" -v pat="$PATTERN" '$0 ~ pat { print $1; exit }' index.php.log` NEWREV=`echo $NEWREV | tr -d '[:space:]'` echo "The latest Drupal release is $NEWREV." # Is this site already running the latest Drupal release? if [ $OLDREV = $NEWREV ] then echo "You are already running the latest release of Drupal $MAJORVER!" exit 0 fi # Prompt for confirmation before running the update echo "Do you want to update this Drupal installation now? [y/n]" read ANSWER if [ "$ANSWER" != "y" ] then exit 0 fi # Checkout a fresh copy of the new Drupal versions in order to compare the differences echo "Getting a temporary fresh copy of Drupal" cd /tmp rm -rf drupal-newrev cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal co -d drupal-newrev -r $NEWREV drupal # Create a patch of the differences between new and old versions of Drupal cd drupal-newrev cvs diff -upN -r $OLDREV > $CWD/diff.patch cd .. rm -rf drupal-newrev # Apply the patch cd $CWD patch -p0 < diff.patch # Remove the patch rm diff.patch