User login

Upgrade between Drupal versions using a diff shell script

[This should be on its way to being obsoleted by drush, but i'm using it for Drupal 7 alpha so thought i'd finally make sure it was shared.]

Download this and other useful scripts from their public repository on gitorious.

(Please use the code from the repository, the below may be out of date.)

If you put the agaric-scripts repository in ~/scripts and the site you are updating is in ~/code/example/web,
usage of the script would look like:

~/scripts/version-upgrade-diff.sh 7.0 7.1 ~/code/example/web

#!/bin/sh -e

if [ $# -lt 2 ]; then
    echo "Usage: $0 oldversion newversion (optional) directory (e.g. 5.5 5.6 dir)"
    exit 1
fi

# If you change TMP, you will have to change the -p3 option in the patch command!
TMP=/tmp
# Change the version below to what you have
VER_OLD=$1
VER_NEW=$2

if [ $# -gt 2 ]; then
  DRUPAL_DIR=/var/www/$3
else
  DRUPAL_DIR=`pwd`
fi

# Change that to the directory where Drupal is installed
PATCH_FILE=$TMP/drupal-$VER_OLD-to-$VER_NEW.patch
cd $TMP

# Download your current version
wget http://ftp.drupal.org/files/projects/drupal-$VER_OLD.tar.gz

# Extract it
tar -xzf drupal-$VER_OLD.tar.gz

# Now, download the new version
wget http://ftp.drupal.org/files/projects/drupal-$VER_NEW.tar.gz
# And extract that too
tar -xzf drupal-$VER_NEW.tar.gz

# Now create the diff file
# echo "This command, or the next one, breaks the script so you'll just have to do the rest yourself."
echo `diff -Naur $TMP/drupal-$VER_OLD $TMP/drupal-$VER_NEW > $PATCH_FILE`

# Now change to the directory where your Drupal installation is
cd $DRUPAL_DIR

# we'll want to see the output for this
set -vx

# Check that the patch would apply without errors
patch -p3 --dry-run < $PATCH_FILE

# turn off verbose output
set +vx
# turning it back off (naturally, on is a minus sign and off is a plus sign)

echo "If the above dry run patch applied without errors, you can press Y to apply the patch for real."
echo "If there are errors, or you just aren't ready to apply the patch, press N to abort."
read YN
if ( test -z "$YN" )
then
  echo -e "Please enter either "Y" or "N" " ;
  eval "$0" "$@" ;
  exit ;
fi
# at this point 'YN' contains Y, y, N, or n
if ( test "$YN" = "N" -o "$YN" = "n" )
then
  exit ;
fi

set -vx
# Assuming there are no error from the previous step, you can
# now apply the patch for real
patch -p3 < $PATCH_FILE

Searched words: 
diff version upgrading bash shell script version-upgrade-diff.sh update Drupal

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • 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> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.