Update your Wordpress installation via Ant

After toying a little with Ant I came up with this task

  1. <project name="update_wordpress" basedir="../" default="all">
  2.    
  3.    
  4.     <target name="init">
  5.         <property name="ftp_user" value="john_doe" />
  6.         <property name="ftp_pass" value="secret" />
  7.         <property name="ftp_server" value="www.foo.com" />
  8.         <property name="ftp_path" value="ftp/path/to/your/blog" />
  9.     </target>   
  10.    
  11.    
  12.     <target name="download_latest">
  13.         <mkdir dir="tmp" />
  14.         <get src="http://counter.wordpress-deutschland.org/dlcount.php?id=static&amp;url=/de-edition/latest.zip" dest="tmp/latest.zip" />
  15.         <unzip src="tmp/latest.zip" dest="tmp" />
  16.         <delete file="tmp/latest.zip" />
  17.         <fail message="there's something wrong with the wordpress archive">
  18.            <condition>
  19.                 <not>
  20.                     <available file="tmp/wordpress" property="wordpressinstall.exists" />
  21.                 </not>
  22.             </condition>       
  23.         </fail>
  24.     </target>
  25.    
  26.    
  27.     <target name="backup" depends="init">
  28.       <mkdir dir="backup" />
  29.       <ftp action="recv"
  30.            server="${ftp_server}"
  31.            userid="${ftp_user}"
  32.            password="${ftp_pass}"      
  33.            remotedir="${ftp_path}"
  34.            passive="yes"          
  35.            verbose="yes">
  36.         <fileset dir="backup">
  37.             <include name="**" />
  38.         </fileset>
  39.       </ftp>       
  40.     </target>   
  41.    
  42.    
  43.     <target name="update" depends="init,download_latest">
  44.         <ftp action="del"
  45.              server="${ftp_server}"
  46.              userid="${ftp_user}"
  47.              remotedir="${ftp_path}"
  48.              passive="yes"
  49.              verbose="yes"
  50.              password="${ftp_pass}">
  51.             <fileset>
  52.                 <include name="**" />
  53.                 <exclude name=".htaccess" />
  54.                 <exclude name="wp-content" />
  55.                 <exclude name="wp-content/**" />
  56.                 <exclude name="wp-config.php" />
  57.             </fileset>
  58.         </ftp>
  59.    
  60.         <ftp server="${ftp_server}"
  61.              remotedir="${ftp_path}"
  62.              userid="${ftp_user}"
  63.              password="${ftp_pass}"
  64.              passive="yes"
  65.              verbose="yes"
  66.              binary="yes">
  67.             <fileset dir="tmp/wordpress">
  68.                 <include name="**" />
  69.                 <exclude name="wp-content" />
  70.                 <exclude name="wp-content/**" />
  71.                 <exclude name="*.html" />
  72.                 <exclude name="*.txt" />
  73.                 <exclude name="wp-config-sample.php" />
  74.             </fileset>
  75.         </ftp>   
  76.     </target>
  77.    
  78.    
  79.     <target name="all" depends="init,download_latest,backup,update">
  80.         <deltree dir="tmp" />
  81.         <echo message="Update finished." />
  82.     </target>
  83.    
  84. </project>

Be careful, this Ant file downloads the german version of Wordpress. You also need to have commons-net and jakarta-oro in your %ANT_HOME%/lib installed in order to have this work. See here. Additional I won't be responsible if you screw up your blog or other relevant data. Be sure to make an manual backup first.


About this entry