public
Last active

Automated WordPress upgrades using SVN tags

  • Download Gist
wp-tag-svn-up.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/bin/bash
TAGSURL='http://core.svn.wordpress.org/tags/'
STABLETAG=`curl -s $TAGSURL | awk -F '">' '{print $2}' | awk -F"/<" '{print $1}' | egrep "^[0-9].[0-9]" | sort -n | tail -n 1`
if [ $STABLETAG == '' ]
then
echo "Stable tag not found, exiting..."
exit 1
fi
for ADDON in `ls -1d /home/user/sites/*/`
do
if [ -e $ADDON/wp-load.php ] && [ "`svn info $ADDON | grep tags`" ]
then
echo "Upgrading $ADDON to $STABLETAG..."
cd $ADDON
svn sw $TAGSURL$STABLETAG
svn up
 
WPCONFIG='wp-config.php'
 
DB_HOST=`sed -n "s/.*\(['\"]\)DB_HOST\1[ \t]*,[ \t]*\(['\"]\)\(.*\)\2[ \t]*);.*/\3/p" $WPCONFIG`
DB_NAME=`sed -n "s/.*\(['\"]\)DB_NAME\1[ \t]*,[ \t]*\(['\"]\)\(.*\)\2[ \t]*);.*/\3/p" $WPCONFIG`
DB_USER=`sed -n "s/.*\(['\"]\)DB_USER\1[ \t]*,[ \t]*\(['\"]\)\(.*\)\2[ \t]*);.*/\3/p" $WPCONFIG`
DB_PASSWORD=`sed -n "s/.*\(['\"]\)DB_PASSWORD\1[ \t]*,[ \t]*\(['\"]\)\(.*\)\2[ \t]*);.*/\3/p" $WPCONFIG`
TABLE_PREFIX=`sed -n "s/.table_prefix[ \t]*=[ \t]*\(['\"]\)\(.*\)\1[ \t]*;.*/\2/p" $WPCONFIG`
SITEURL=`mysql -h "$DBHOST" -u "$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" --batch -sre "SELECT option_value FROM ${TABLE_PREFIX}options WHERE option_name='siteurl'"`
RESPONSE=`curl -siL "$SITEURL/wp-admin/upgrade.php?step=upgrade_db"`
 
CODE=`echo "$RESPONSE" | head -1 | awk '{print $2}'`
 
if [ "$CODE" != "200" ]
then
echo "Failed to update $SITEURL: $CODE"
exit 1
fi
fi
done
exit 0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.