Script to Upgrade WordPress to the latest version fully automatically
UPDATE: Please check out latest version from my git repo: http://git.vpetkov.net/projects – project name: “wordpress”
When you host a WordPress installation for yourself, and there is some sort of an update about every month, it can get annoying doing all the upgrade steps manually (for the people who do not have a CPANEL or FTP account). Now imagine hosting 5-6 WordPress installations. Now imagine 500+. Welcome to my nightmare. Eventually I caved in and wrote this:
# http://codex.wordpress.org/Updating_WordPress#Step_1:_Replace_WordPress_files # This strictly follow the directions mentioned above. # Utilizes: "rm", "cp", "mv", "wget", "unzip" umask 0022 WEBROOT=/var/www/domain CURRENT_BLOG=$WEBROOT/CURRENT_BLOG TEMP_NEW=$WEBROOT/wordpress cd $WEBROOT /bin/rm -Rf latest.zip /usr/bin/wget http://wordpress.org/latest.zip /usr/bin/unzip -q latest.zip # Remove outdated CURRENT_BLOG files per instructions cd $CURRENT_BLOG /bin/rm -Rf wp-includes wp-admin # Copy TEMP_NEW files per instructions cd $TEMP_NEW /bin/cp -Rf wp-includes $CURRENT_BLOG/. /bin/cp -Rf wp-admin $CURRENT_BLOG/. cd wp-content /bin/cp -Rf * $CURRENT_BLOG/wp-content/. cd .. /bin/mv *.php $CURRENT_BLOG/. /bin/mv readme.html $CURRENT_BLOG/. /bin/mv license.txt $CURRENT_BLOG/. # Cleanup TEMP_NEW - remove extraction and download. cd $WEBROOT /bin/rm -Rf wordpress latest.zip # CUSTOM echo "go to: http://YOUR-BLOG-URL/wp-admin/upgrade.php"
So, to summarize, this will download the latest version of wordpress, unzip it, and move the new things accordingly. At the end, it will remind you to upgrade your DB, just in case. I highly suggest backing up your primary blog before you begin this, just because it’s the “safe thing” to do.
Thanks, this is great!
Can you clarify what the $NEW and $OLD variables represent? I think $OLD is the location of your wordpress installation, and $NEW is a temporary folder where the wordpress distribution is unpacked, right? And $HOME is the folder that the wordpress distribution is downloaded to?
Thanks!
Hey, $OLD (poor choice for a variable name) is the “full current blog path”. It builds on $HOME. For example, something like $HOME=/var/www and $OLD would be $HOME/myblog. The $NEW variable is a temporary folder where the new wordpress is unpacked yes. I will fix these with something that makes more sense, and update it in Git and on my blog. Thanks for pointing this out.