[wp-hackers] Multiple WordPress Site Update Script

Brian Layman Brian at TheCodeCave.com
Thu Dec 21 21:47:57 GMT 2006


Some of you might remember the auto-update script that I ran by you all,
about four months ago.  It meant to make updating one or more blogs much
easier, but it had some restrictions.  

Well, it's grown since then.

I suspect many/most of you have MUCH more *nix experience than I have and I
would like your help in ensuring this method isn't gonna crash any typical
*nix based, non-core-code-customized blogs.  I was wondering if some of you
might review this script and tell me of any errors or problems you can
foresee.  I've got it working just fine updating my blogs. But, I'd like
more  of a confidence factor than what I can get just having it work for me
and only me.

How does this look to you? 

BTW, if you don't know how to take this from the email, put it on your
server, set the rights, and run it, you probably should not review it at
this stage.  Soon...


OH! And I just realized I never did add the commands to Wget the Upgrade
page...  I'll have to do that yet... I'll change back to the tmp directory
first I guess hmmm...
_______________________________________________
Brian Layman
www.TheCodeCave.com
 



<----------------%<-----------CUT HERE---------------------->

# *************************************************************************
#  UpdateWP ver 2.0 alpha 1                                    01/Aug/2006
#  Written by Brian Layman
#
#  A unix shell script to update multiple WordPress blogs to the current
#  stable release.
#
#  Usage: (A full instruction set is at http://thecodecave.com/article300)
#    Browse out to www.TheCodeCave.com and get the latest
#    Customize the "Configuration variables" found below
#    Use chmod to grant yourself execute status on the script
#    Run the program 
#
#  You can use this program in several ways.  
#    First, you can use it in the default mode to download the latest
#      update and then install it to several directories.
#    Second, you can use it to automate backing up files and tables when 
#      updating.
#    Third, you can cron it and change the source of the update and use 
#      it to force the start of a known clean system every morning. 
#
# Original Author - Brian Layman
#
# Created       - 01/AUG/2006
# Last Modified - 21/DEC/2006
# Contributors: (Put your name & Initials at the top)
#   Brian Layman - BL - http:#www.TheCodeCave.com
#
#
# History:
#    01/AUG/2006 - BL - Created
#    21/DEC/2006 - BL - Finalized Ver. 2 tweaks
#
# License - If this helps you - Great! Use it, modify it share it.
#
# Indemnity -
#   Use this file at your own risk. I'm not going to deliberately hack
#   your server, but others might. This is a shell script. Very bad 
#   things can happen.  I am relatively new to *nix scripts.  So
#   I'M HAVING others review this script. But NONE of this guarantees
#   things won't go wrong or that this script is unchanged, even if
#   you've gotten it from TheCodeCave.com or another site you trust.
#
#   THIS SCRIPT SHOULD BE USED AT YOUR OWN RISK. It CAN erase hours of 
#   hard work put into your site.  Before using this script it is  
#   required that you review and understand every line and vouch for 
#   its safety.  If you are not comfortable with this, don't run this 
#   script.  I have one host that I can test this on.  Only you can say
#   that this script will not do irreperable harm to your site or your 
#   host if you use it.
#
#   YOU are responsible for YOUR site.  Learn how to protected it and 
#   understand what every line of code does before you call it.  I 
#   am not liable for any damages, lost data, lost time, or iterupted
#   services because you've chosen to run this script on a system
#   for which I cannot vouch.  Use at your own risk.
#
# Donations - If this batch file really helps you out, feel free to
#   make a donation of the cost of a cup of expresso via Paypal to 
#   Brian at TheCodeCave.com.  A morning coffee or cheesy nachos and I 
#   your friend for life.  And/or leave a comment on my site: 
#   http://www.thecodecave.com/did-that-help.
#
# *************************************************************************


# ##################################################################
# Configuration variables
# ##################################################################
# Common root is the part of your path that is shared by all of your
# WP blogs.  It is probably your htdocs directory.  Blank is fine if
# you want to specify the full path in the BlogDirs variable.
# Using ~ will not work.
CommonRootPrefix="/put/your/homepages/path/here/htdocs/"

# List all of your WordPress directories here
BlogDirs[1]='myflowers'
BlogDirs[2]='storesite/news'
BlogDirs[3]='example.com'

# These variable can be used to change where you get the clean copy of
WordPress
# Override this variable if you wish to use this script to restore your
files to
# a known version of WordPress.  As part of a nightly routine, this can keep
all 
# of your sites running un-hacked codes.
SourceURL='http://wordpress.org/'
TarBallName='latest.tar.gz'

# MAKEFILEBACKUPS will back up the FILES from the folders above if it is set
to 1.
# Only use this feature when the WP folders only have WP stuff in them.  
# This will take time and space.  If you have, for example, a downloads
folder under 
# one of the folders listed above, you will make a copy of it.  You may run
out of 
# space and that can crash your site.  That's why this is off by default.
# MAKEFILEBACKUPS=0  # REMOVED FROM THIS VERSION

# MAKESQLBACKUPS enables Database backups to be made of the WP specific
tables
# for each blog.  It reads the database username, password and table prefix
# It is disabled by default for several reasons
# 1. Copies of a DB on a webserver is a security risk
# 2. I suspect it will not work on all systems mysqldump must be present
# 3. Your wp-config file might not allow me to read it
# 4. Your wp-config file might customized in a way I cannot predict
# 5. I'm not done testing it
# MAKESQLBACKUPS=0  # REMOVED FROM THIS VERSION

# ##################################################################
# Constants - Do not change these
# ##################################################################
#Error Codes
E_SUCCESS=0 # No Error Code. It worked.
E_XCD=66 # Can't change directory?
E_XMD=67 # Can't make directory?
TMPPREFIX='TCCWPUPDATE-'

# ##################################################################
# Prepare the stage by getting the files in order.
# ##################################################################

# Make Temporary directory for downloading the WordPress file
tmp=${TMPDIR-/tmp}
tmp=$tmp/$TMPPREFIX$RANDOM$RANDOM$RANDOM.$$
(umask 077 && mkdir $tmp) || {
  echo "Could not create temporary directory! Exiting." 1>&2
  exit $E_XMD
}

# Show this to allow potential manual cleanup...
echo "A temp dir was created at: $tmp"

#Change to the temporary directory
cd $tmp

# Doublecheck if in right directory, before messing with downloading files.
if [ `pwd` != "$tmp" ] 
then
echo "Can't change to new temp dir.  Aborting."
exit $E_XCD
fi 

# Download the tarball into the temp directory, extract it and deleted it.
wget $SourceURL$TarBallName
tar -zxf latest.tar.gz
rm $TarBallName


# ##################################################################
# Perform the full file backup before touching any files.
# ##################################################################

# ##################################################################
#  Perform the full table backups before touching any files.
# ##################################################################

# ##################################################################
#  Iterate all of the directories and overwrite their contents.
# ##################################################################

# Loop through the BlogDirs array
for CurDir in "${BlogDirs[@]}" 
do
  echo "Now Updating: $CurDir"
  # Go to each directory
  cd $CommonRootPrefix$CurDir
  # Doublecheck if in right place, before copying over hundress of files.
  if [ `pwd` != "$CommonRootPrefix$CurDir" ] 
  then
    echo "Aborting. Can't reach one of the blog directories:
$CommonRootPrefix$CurDir"
    rm $tmp -R # Don't leave the temp dir out there if we don't have to
    exit $E_XCD
  fi 
  
  # Copy all of of the files from the temp dir
  cp -R -v --remove-destination $tmp .
  echo "$CurDir Update complete"
done

# ##################################################################
#  Cleanup
# ##################################################################

# Once everything is done, we can remove the temp directory
rm $tmp -R


# ##################################################################
#  Close
# ##################################################################
echo UPDATE COMPLETE 
exit $E_SUCCESS



<----------------%<-----------CUT HERE---------------------->













More information about the wp-hackers mailing list