Technosailor

  • Home
  • Blog
  • Venture Files
  • Espanol
  • Technosailor Staff
Feb
08
2007

My Script for Auto WordPress Upgrade

Posted by: Aaron Brazell

I like posting scripts. I am proud of most of them. I mentioned before that I run WordPress trunk and that every day, the auto upgrade script runs, upgrades this blog and sends me a detailed email regarding the upgrade. Not only does this help me keep track of changes from revision to revision without having to go browsing the repository, it gives me a handy reference in case I have to roll back.

Here is the script I run. It is a PHP command line script (I do most of my CLI scripting in PHP as I’m fluent in it).

#!/usr/bin/php
< ?php
/* Get info from the WordPress repository regarding trunk. We will use this to parse out the latest revision number */
$svninfo = shell_exec('svn info /root/working_copies/wptrunk/trunk/');
$lines = explode("n", $svninfo);
$bits = explode(' ', $lines[7]);
$oldrev = $bits[3];

/* I use shell_exec() because the output of the CLI commands will be returned. I'll be able to add this to the email */
$log = "PROCESS LOGn---------------nn";
$log .= shell_exec('svn up /root/working_copies/wptrunk/trunk/');
$log .= shell_exec('svn export --force /root/working_copies/wptrunk/trunk /home/techno/public_html/');

/* Get the revision number of the working copy. This is the new revision number */
$svninfo = shell_exec('svn info /root/working_copies/wptrunk/trunk/');
$lines = explode("n", $svninfo);
$bits = explode(' ', $lines[7]);
$newrev = $bits[3];

/* Pass the revision info along to be included in the email */
$details = "nnOld Revision: $oldrevnNew Revision: $newrevnnn";

/* Use the revision numbers to determine the log of changes between them. Add for email.  */
$history = "SVN LOGn---------------nn";
$history .= shell_exec("svn log -r $oldrev:$newrev /root/working_copies/wptrunk/trunk/");
$history .= "nn";

/* Grab detailed changes (diff) between revisions. Add to email. */
$history .= "SVN DIFFn---------------nn";
$history .= shell_exec("svn diff -r $oldrev:$newrev http://svn.automattic.com/wordpress/trunk/");
$history .= "nn";

/* Put the pieces together for the email, then send */
$message = $details . $history . $log;
mail('aaron@technosailor.com','WordPress SVN Update', $message, 'From: aaron@technosailor.com');
?>

This sends me an email like the one I got the other night:

 

Old Revision: 4863
New Revision: 4871

SVN LOG
---------------

------------------------------------------------------------------------
r4863 | ryan | 2007-02-02 11:38:26 -0500 (Fri, 02 Feb 2007) | 1 line

Check page ID only if is_page.  fixes #3049
------------------------------------------------------------------------
r4865 | ryan | 2007-02-02 19:56:23 -0500 (Fri, 02 Feb 2007) | 1 line

Typo fix from charleshooper.  fixes #3743
------------------------------------------------------------------------
r4866 | ryan | 2007-02-05 16:29:39 -0500 (Mon, 05 Feb 2007) | 1 line

Disambiguate queries.  Props mhyk25.  fixes #3747
------------------------------------------------------------------------
r4867 | ryan | 2007-02-05 16:37:47 -0500 (Mon, 05 Feb 2007) | 1 line

Make DB_COLLATE blank by default so that MySQL will choose the default collation for the charset. #3517
------------------------------------------------------------------------
r4870 | ryan | 2007-02-05 20:44:23 -0500 (Mon, 05 Feb 2007) | 1 line

XMLRPC changes from Joseph.
------------------------------------------------------------------------
r4871 | ryan | 2007-02-06 15:12:53 -0500 (Tue, 06 Feb 2007) | 1 line

Send content type header. Props nbachiyski.  fixes #3754
------------------------------------------------------------------------

SVN DIFF
---------------

Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 4863)
+++ wp-incmVFW2VW'&Wf6CsФsBbsBbТF6G27V'7G"F6G2"ТFWE6G27V'7G"FWE6G2"Тb7G&VF6G2fwCТАF6G2"B6FVv'BF6G2#ТF6G2"BGwF"fwC7C&6B6FVv'BF6G2#Тb7G&VFWE6G2fwCТАFG2GwF"fwCvWE6‚%4TT5B7EBe$GwF"fwC7C&6BtU$R6FVv'BFWE6G2"ТFG2GwF"fwCvWE6‚%4TT5B7EBe$GwF"fwC7C&6BtU$RGwF"fwC7C&6B6FVv'BFWE6G2"Тb5'&FG2ff6VBFG2fwCТf&V6FG22FBТFWE7G2"FB#ТFWE7G27V'7G"FWE7G2"ТТb7G&VFWE7G2fwCТАFWE6G2"BBBFWE7G2#ТFWE6G2"BGwF"fwC7G2BBFWE7G2#ТV6PТFWE6G2rsТФFWw֖6VFW2gV7F2УТw֖6VFW2gV7F2&Wf6Cc2Тw֖6VFW2gV7F2&Wf6CsФ3#r3#rРТFF2wEF2Тb76WBFF5FFUҒТАFF5FF5UFWwfVSТFF5FFUFWwfVSТw66U6WBvF2rFF2vF2rТV6RТw66U6WBFFRFWwfVRvF2rФFW'2УТ'2&Wf6Cc2Т'2&Wf6CsФ##r##rТ'wvU&VEFFR fwCG&VEFFRТ'wvU&FW" fwCGvRfwCVU&FW"Т'wWF%B fwCFWF"fwCBТА'wWF%F7W6W&R fwCFWF"fwCF7PТ'wWF%F7R fwCFWF"fwCF7PТРТ&WGW&GvU7G'V7BФFWw6fr6RУТw6fr6R&Wf6Cc2Тw6fr6R&Wf6CsФRrRrТFVfRtD%55t$Brw77v&BrB77v&@ТFVfRtD%5Brv6Ɔ7BrR66RRvwBVVBF6vRF2fVPТFVfRtD%4%4UBrwWFcrТFVfRtD%4DRrwWFcvVW&6rТFVfRtD%4DRrrrРТR6fRVFR7FF2RFF&6RbRvfRV6VVR&VfТGF&U&VfwwsǒV&W'2WGFW'2BVFW'66&W2V6RФFWwF֖FWWG&УТwF֖FWWG&&Wf6Cc2ТwF֖FWWG&&Wf6CsФ"b"ÂТ&WV&U6RvF֖rТ&WV&U6R%5Du2r'72rРТVFW"t6FVBGSrvWEFvFGRrs6'6WCrvWEFv&u6'6WBrТТ7vF6EtUEvuРТ66Rv6֖vƖ2rРХ$4U52pТРХR&Bv&u6W2wG'VG'Vw֖6VFW2VW'ХR&Bv&u6W2wG'VG'Vw֖6VFW2gV7F2ХR&Bv&u6W2wG'VG'V'2ХR&Bv&u6W2wG'VG'Vw6fr6RХR&Bv&u6W2wG'VG'VwF֖FWWG&РФfWF6rWFW&FVFr&Bv&u6W2wG'VG'Vw6FVBVv26WBpХWFFVBWFW&F&Wf6sbРХWFFVBF&Wf6CsФW'B6WFR6FS

Nice huh?

Update: Use this script at your own risk. The WordPress trunk is not supported by WordPress. If you use this script without understanding how to roll back, it’s all on you. If you break your blog, no one is going to help you!

Commenter Rick explains the systems requirements:

  • Shell access; the command “php wordpress-update-cli.php” would otherwise be unable to run.
  • Crontab; if you wanted to automate the running of the script on a regular basis.
  • php 4.0.1+ or 5+; shell_exec() would otherwise be unavailable. The other prominent function call, explode(), is available from 4+. Safe mode must be set to Off to use shell_exec().
  • SVN installed on the server in order to use svn command from the shell.

About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He is the Director of Technology at b5media and is available for consulting.
Tagged: at 2:45 pm -

24 Responses to “My Script for Auto WordPress Upgrade”

  1. 1
    Markus Says:

    looks realy great. One day I will try to do it in a similar way.

    February 8th, 2007 at 3:14 pm
  2. 2
    Aaron Brazell Says:

    Thanks, Markus. Would love to see what you comew up with when you do. :)

    February 8th, 2007 at 3:27 pm
  3. 3
    Ajay Says:

    Hi,

    What are the server requirements for using this script?

    February 10th, 2007 at 5:34 am
  4. 4
    Anshul Says:

    As asked before what are the requirements and also what if the hosting provider upgrades wordpress automatically. Wont it interfere with this script then.

    February 10th, 2007 at 6:13 am
  5. 5
    BloggingPro China » Script for Auto WordPress Upgrade Says:

    [...]   My Script for Auto WordPress Upgrade,作者提供了一个php脚本范例,用于每天自动从WordPress SVN上获得最新版本,同时发送一封E-mail到自己的邮箱,内容详述更新内容和细节。推荐有一定脚本基础的用户参考使用。 [...]

    February 10th, 2007 at 6:43 am
  6. 6
    Gene Steinberg Says:

    This may be a silly question, but wouldn’t it be a neat idea to build this into some sort of upgrade application that one could use without having to be on the bleeding edge? The problem with WordPress is that the installation process is from the 1980’s. If your script will work, it’s a great starting point.

    Peace,
    Gene

    February 10th, 2007 at 9:42 am
  7. 7
    Rick Beckman Says:

    I’m not sure what the exact server requirements would be, but I can take a guess:

    1) Shell access; the command “php wordpress-update-cli.php” would otherwise be unable to run.

    2) Crontab; if you wanted to automate the running of the script on a regular basis.

    3) php 4.0.1+ or 5+; shell_exec() would otherwise be unavailable. The other prominent function call, explode(), is available from 4+. Safe mode must be set to Off to use shell_exec().

    4) SVN installed on the server in order to use svn command from the shell. (Not too sure about this one, though it seems reasonable. I’m not sure how native the svn command, whether it needs extra software or not, etc.)

    February 10th, 2007 at 9:54 am
  8. 8
    Aaron Brazell Says:

    Ajay: Rick nailed them.

    Anshuk: If your host auto upgrades anything of yours, it’s time to find a new host.

    BloggingPro China: Uh…. ;)

    Gene: Sure, it’s called http://FTP. :)

    February 10th, 2007 at 11:08 am
  9. 9
    Jonathan Says:

    Is there a way to point the script to the stable release Subversion repository? If so, I’m ’bout it ’bout it! ;o)

    February 10th, 2007 at 11:31 am
  10. 10
    Aaron Brazell Says:

    Why would you do that, Jonathon? If you want stable just go and download the thing from wordpress.org. Stable is only released ever so often, not something you’d want to put on cron and upgrade every night.

    February 10th, 2007 at 11:34 am
  11. 11
    Jonathan Says:

    Laziness, I suppose! :o) How “stable” is the nightly? I mean, you’re running it, so it must be somewhat okay.

    February 10th, 2007 at 11:44 am
  12. 12
    Aaron Brazell Says:

    It’s stable today! Can’t guarantee tomorrow! :) It’s definitely not supported! It’s definitely for advanced users who understand the ins and outs of WordPress and SVN.

    February 10th, 2007 at 11:50 am
  13. 13
    Ajay Says:

    Thanks Aaron and Rick.

    BTW, I listed the post on WLTC.

    February 10th, 2007 at 12:13 pm
  14. 14
    Aaron Brazell Says:

    Thanks, Ajay. Updated the post to make sure people aren’t using this flippantly and hoping for support. ;)

    February 10th, 2007 at 12:35 pm
  15. 15
    Actualiza automáticamente Wordpress 2.1 | aNieto2K Says:

    [...] Fantástico script que te tendrá actualizado automáticamente a la nueva versión de Wordpress 2.1. [...]

    February 10th, 2007 at 5:24 pm
  16. 16
    Atualizao automtica do WP :: bernabauer.com - Noticias de Tecnologia todos os dias. Says:

    [...] como o One Click Install da Dreamhost so sua melhor opo? Ento esta na hora de voc conhecer um script que automatiza o processo de upgrade. Para ser um blogueiro preguioso, mas atualizado, requer [...]

    February 12th, 2007 at 2:52 pm
  17. 17
    Akkam’s Razor Says:

    [...] My Script for Auto WordPress Upgrade » Technology, Blogging and New Media “[This] auto upgrade script runs, upgrades this blog and sends me a detailed email regarding the upgrade.” (tags: WordPress script Plugin backup upgrade) [...]

    February 13th, 2007 at 9:50 pm
  18. 18
    Ajay Says:

    You’re welcome :)

    February 15th, 2007 at 5:17 am
  19. 19
    Autoupgrade for WordPress SVN | bastelblog Says:

    [...] script that I can find out there and recently I stumbled upon a post by Aaron Brazell about an Automated WordPress Upgrade Script he [...]

    February 15th, 2007 at 11:27 am
  20. 20
    The WordPress Podcast » Episode 23: WordPress 2.2 delayed, GSoC workers, Aaron Brazell Says:

    [...] have Subversion installed and you’re running WordPress on a *nix server, both Red Monk and Aaron Brazell have bash files to help you automatically update all of your WordPress [...]

    April 24th, 2007 at 10:53 am
  21. 21
    Top methods for keeping your Wordpress installation and Wordpress plugins up-to-date | fiLi’s tech Says:

    [...] Aaron Brazell of Technosailor wrote a PHP script that will take care of the upgrade for you. Use this with extreme care. You can either execute as any other PHP file, running PHP from your shell or using a PHP-shell, executed as a cron job etc. [...]

    May 21st, 2007 at 8:43 am
  22. 22
    Guide to Disaster: How The Tech Team Handled WordPress Security Flaw Says:

    [...] May 22 - 4:30PM EDT Upgrade script and subversion repositories prepped for switch to WordPress 2.2. We chose revision 5505 as most of [...]

    May 23rd, 2007 at 3:10 am
  23. 23
    futtta Says:

    i wrote a wp upgrade script in bash (so it’s a shell script, really). it makes a backup of the wp-db and -fs, turns of plugins and syncs with the latest tagged version using “svn sw”.

    you can fetch a tar.gz-version of it on http://futtta.be/download/WPuppy.tar.gz.

    more info (in dutch, but there’s an auto translate link in the upper right corner) on: http://blog.futtta.be/2007/09/26/wordpress-automagisch-upgraden-nu-ook-met-hondje/

    September 28th, 2007 at 4:16 pm
  24. 24
    The Best of 2007 Says:

    [...] My Script for Auto WordPress Upgrades [...]

    December 24th, 2007 at 2:19 pm

  • Recent Posts

    • 5 Cambios que Todo Ejecutivo de Medios Debe Hacer
    • Rules for Entrepreneurs: 5 Ways to Avoid Founderitis
    • Early Adopters Are Useless
    • Rules for Entrepreneurs: Pay yourself first
    • New Series: Writing a Marketing Plan
  • Reader Contribution

    • Martin Cleaver on Brightkite: Blazing New Paths in Microcontent
    • Steve Lynch on Early Adopters Are Useless
    • Lisa Hyatt on Early Adopters Are Useless
    • Jeff Brewster on Early Adopters Are Useless
    • Vinnie on Early Adopters Are Useless
  • RSS Venture Files

    • Rules for Entrepreneurs: Pay yourself first
    • New Series: Writing a Marketing Plan
    • New Series Introduction: Rules for Entrepreneurs
    • Do you really want to work in Venture Capital?
    • Business Card FAIL
  • RSS Technosailor en Español

    • 5 Cambios que Todo Ejecutivo de Medios Debe Hacer
    • Cómo Sacarle Provecho a Twitter
    • 7 Herramientas para estar Informado
    • Siguiendo la F1 (y otras noticias) con Twitter
    • Ubica a tus Amigos con Livecontacts
  • Technosailor TV

    View Technosailor TV

  • License Creative Commons Attribution-Noncommercial-Share Alike 3.0 | Copyright © 2004 - 2008 - Aaron Brazell | Lisa helped out | Privacy Policy