#!/bin/bash # Linux Wordpress Upgrader Script # # Mark Davidson | mark@4each.co.uk | www.pablumfication.co.uk # function wpExtract { echo $(grep -o "define('$1', '\([^']*\)');" $WP/wp-config.php | cut -f 2 -d ' ' | awk '{ print substr($0, 2, length($0) - 4) }') } TEMP=/tmp if [ $# = "1" ]; then WP=$1 # need to either force full path input or create canconical version # Validate that this directory is valid and contains wordpress files BACKUP_DIR=$PWD/backups/wp/$(date +%s) echo "Creating Backup Directory" mkdir -p $BACKUP_DIR echo "Backup Directroy Created " $BACKUP_DIR cd $BACKUP_DIR echo "Backing up wordpress database" result=`mysqldump -u $(wpExtract DB_USER) -p$(wpExtract DB_PASSWORD) --database $(wpExtract DB_NAME) 2>&1 > blog.sql` if [ -n "$result" ]; then echo $result else echo "Taring DB Backup" result=`tar -cf db.tar.gz blog.sql 2>&1` if [ -n "$result" ]; then echo "DB backup could not tared be created exiting" else echo "DB backup tared" rm blog.sql echo "Creating Backup of Wordpress Files" tar -Pzcf blog.tar.gz $WP echo "Checking Backup Integrity" result=`tar -dPf blog.tar.gz $WP` if [ -n "$result" ]; then echo "Integrity check failed" echo $result else echo "Downloading Latest Wordpress" wget -O $TEMP/latest.tar.gz http://wordpress.org/latest.tar.gz tar -zxf $TEMP/latest.tar.gz result=`tar -ztf $TEMP/latest.tar.gz | grep wordpress/index.php | wc -l` # Really basic chek that file is intact proberly a better way to do this if [ "$result" = 1 ]; then echo "File OK" echo "Extracting Wordpress" result=`tar -C $TEMP -xf $TEMP/latest.tar.gz` #TODO: Validate extraction echo $result cd $WP result=`cp -avr $TEMP/wordpress/* .` echo $result rm -rf $TEMP/wordpress $TEMP/latest.tar.gz echo "New files copied vist http://yourdomain.com/wp-admin/upgrade.php to complete the upgrade" else echo "File Corrupt or missing" fi fi fi fi else echo "Incorrect Number of Arguments" fi