wordpress upgrade script
If there’s one thing that gets old really fast, it’s upgrading Wordpress everytime a new release comes out. Finally fed up enough to look for a solution, I found this script that promised to automate the job. Unfortunately, it has a number of flaws including not copying the “uploads” directory and being overly complicated.
Next, I found this script. Not only is it simpler, but it also downloads the source for you. Perfect! It seems to work–below is my modified version, however, that is a little less “finicky” about where it is run from, and properly cleans up after itself. Of course, you need to change the second and third lines of the script to suit your needs.
I hope this saves somebody some aggravation…
#!/bin/bash
BLOGDIR=”/home/jmaki/webopticon.com”
SITEURL=”http://www.webopticon.com”echo Updating Wordpress in $BLOGDIR
cd $BLOGDIR
cd ..echo 1. downloading latest build
wget -q http://wordpress.org/latest.tar.gzecho 2. unpacking latest build
tar zxf latest.tar.gz
cd wordpress/echo 3. replacing old files with fresh ones
tar cf - . | (cd $BLOGDIR; tar xf -)echo 4. updating your blog
wget -q -O - ${SITEURL}/wp-admin/upgrade.php?step=1 > /dev/nullecho 5. removing unneeded files and directories
cd ..
rm -f latest.tar.gz
rm -rf wordpressecho 6. all done !
Hi! I’m the author of the script you mentioned that has a “number of flaws”. I was hoping that you might be able to report these flaws - there’s a bug reporting link on the page you linked to. I hate flaws in the code I write, even when it is handling unusual circumstances.
It took me a minute to figure out just how it was not handling the upload directory. It was handling all custom directories and files just perfectly. Then I found what you meant, and you’re absolutely right. Wordpress allows you to specify which directory to use as uploads. By default, if you don’t explicitly specify one, it tries to write to a directory called “uploads” underneath their system wp-content directory that comes with the source. I’m assuming this is what you meant by it not bringing over your uploads - please correct me if I’m wrong!
The script currently will not (by design) bring over any unknown files or directories that are inside supposedly “pure” Wordpress code directories (except for themes and plugins). This is to help protect from hacked Wordpress installations when you upgrade. But it is possible people will create their own valid, custom content within the pristine Wordpress source, such as having that upload directory underneath wp-content. I need to address this, and thank you very much for pointing it out.
The Wordpress installations I manage do not allow the web server to write to any directories that could contain Wordpress source files. Having a setup that allows the web server to write to your source code is not the best idea. But it seems that many people do this. I don’t know about your installation in particular (I hope you don’t have everything open for writing by the web server!) but I do need to account for directories and files that might have been created within Wordpress source subdirectories.
If there are any other flaws that you noticed, if you could report them, or just list them here, I’d be very appreciative.
As for it being overly-complicated, it’s designed to handle sensibly more than just one person’s blog, and it also backs up all your site and data, too, unlike the other script you listed. Although it can be run in nearly all situations by just specifying the name of the directory that contains your Wordpress site, it allows many aspects of the upgrade process to be controlled via command line options if administrators choose to do so, for special situations.
I had thought about just downloading new source code and just dumping it on top of everything you currently have, but there are many potential problems associated with doing that. Just one is, files that are no longer used in Wordpress (and may be a security issue) will forever remain accessible in sites updated with this other script you mentioned (it doesn’t clean out old ones).
Personally, I think the best approach is starting out each upgrade with pristine Wordpress source, then bringing in your customizations. I’m not a fan of just globbing stuff on top of something already there.
The auto-downloading of the source code is a good idea! I think I’ll do that, too. But in the interest of making things complicated (or allowing choice) I’ll also make it so that people can specify the Wordpress source tree that they might have already downloaded instead of forcing them to use the latest.tar.gz file from the Wordpress website. That way, people who modify the Wordpress source for their users will still have a script they can use. The trick is deciding on the best defaults to keep things simple. But even then, you need to document what you can control, which can make things appear complicated.
I think that the script you mentioned is probably the better choice for most single-site users (except for the simple overwriting of trees issue). I thinking adding a backup of your current source tree, and your data before running the upgrade is a good idea, too, though.