#!/bin/bash # # # Licensed under GPLv2 # # Version 0.2 - Ivo Teel # http://www.labcoding.com # # # This script updates your WordPress blog. # a) from 2.3.1 to 2.3.2 # b) from 2.3.2 to 2.3.3 # # TODO # Expand this script to support many different WP versions and diff's. # WP_SUP=("2.3.1" "2.3.2") while getopts d:s: name do case $name in d) WP_DST="$OPTARG";; s) WP_SRC="$OPTARG";; ?) printf "Usage: wp-upgrade -d destination [ -s source ]" exit 2;; esac done if [ ! ${WP_DST} ]; then echo "Usage: wp-upgrade -d destination [ -s source ]" exit 2 fi if [ ! ${WP_SRC} ]; then WP_SRC="$HOME/wordpress" fi # Grab the latest version and unpack echo "" echo "Grabbing the latest version from WordPress.org" echo "" cd ~ rm -f ~/latest.tar.gz wget http://wordpress.org/latest.tar.gz rm -Rf ~/wordpress tar -zxf latest.tar.gz # Check the version of the source wp_version=`grep '\$wp_version' ${WP_SRC}/wp-includes/version.php | cut -b 16-20` echo "The downloaded version is ${wp_version}." # Check destination version wp_dversion=`grep '\$wp_version' ${WP_DST}/wp-includes/version.php | cut -b 16-20` vernum=${#WP_SUP} sup=0 # Check if we support this version for ((i=0;i<$vernum;i++)); do if [ "${WP_SUP[${i}]}" == "${wp_dversion}" ]; then sup=1 fi done if [ ${sup} -eq 0 ]; then echo "" echo "The version we have to upgrade at ${WP_DST} is not a supported version, it's ${wp_dversion}." echo "" echo "We support:" for ((i=0;i<$vernum;i++)); do echo "${WP_SUP[${i}]}" done echo "This script cannot continue." exit 2 fi # Backup current site, just in case... echo "" echo "Creating backup of current WordPress files, just in case..." echo "" tar -zcf $HOME/wp-${wp_dversion}.tar.gz ${WP_DST}/ # Copy all files echo "Copying changed files into ${WP_DST}" echo "" if [ "${wp_version}" == "2.3.2" ]; then cp ${WP_SRC}/wp-app.php ${WP_SRC}/wp-mail.php ${WP_SRC}/wp-settings.php ${WP_SRC}/xmlrpc.php ${WP_DST} cp ${WP_SRC}/wp-admin/admin.php ${WP_SRC}/wp-admin/install.php ${WP_SRC}/wp-admin/setup-config.php ${WP_DST}/wp-admin cp ${WP_SRC}/wp-includes/formatting.php ${WP_SRC}/wp-includes/functions.php ${WP_SRC}/wp-includes/pluggable.php ${WP_SRC}/wp-includes/post.php ${WP_SRC}/wp-includes/query.php ${WP_SRC}/wp-includes/taxonomy.php ${WP_SRC}/wp-includes/wp-db.php ${WP_SRC}/wp-includes/version.php ${WP_DST}/wp-includes fi if [ "${wp_version}" == "2.3.3" ]; then cp ${WP_SRC}/xmlrpc.php ${WP_DST} cp ${WP_SRC}/wp-admin/install-helper.php ${WP_DST}/wp-admin cp ${WP_SRC}/wp-includes/pluggable.php ${WP_SRC}/wp-includes/version.php ${WP_DST}/wp-includes/ fi # Complete! echo "Your blog has been updated from ${wp_dversion} to ${wp_version}! No running of update.php is needed for this release."