Wordpress upgrade script
Tuesday, July 29th, 2008I’ve just upgraded to Wordpress 2.6, and it struck me that it’d be handy to have a script to do this automatically. I’m sure others have their own versions of this, but here’s mine:
#!/bin/bash
DATESTAMP=`date "+%Y%m%d%H%M%S"`
# All these should be absolute paths so that symlinks work properly
NEWCODE=$(pwd)/blog/wordpress-$DATESTAMP
CURRENT=$(pwd)/blog/current
SHARED=$(pwd)/blog/shared
wget -O blog/latest.tar.gz http://www.wordpress.org/latest.tar.gz
# Extract it and change the directory name
tar -zxf blog/latest.tar.gz -C ./blog
mv blog/wordpress $NEWCODE
# Copy the new content code into the shared directory
cp -a $NEWCODE/wp-content $SHARED/wp-content
# Remove it and then link it back in. This preserves installed themes
rm -rf $NEWCODE/wp-content
ln -s $SHARED/wp-content $NEWCODE/wp-content
# Link the config in
ln -s $SHARED/wp-config.php $NEWCODE/wp-config.php
# Clobber the old link
rm -f $CURRENT
# Make a new one
ln -s $NEWCODE $CURRENT
There are a couple of rough edges (like not moving $CURRENT sideways before deleting it so that requests that come in mid-process aren’t broken), but it works for me. It assumes that you’ve got the directory ~/blog/shared, containing wp-config.php and your wp-content directory, and the new version of Wordpress will be installed at ~/blog/current (symlinked to a datestamped folder), so that’s where Apache should be pointed.