Easily Update Owncloud with PHP Scripting

update your owncloud installation with only one command

Owncloud#

You like owncloud ? But updating realy sucks..there ist no automatic update function and typing 10 lines into your shell takes to much time. So here is the simple. 1 command solution!

Usage#

Just execute the following command via ssh (you get the packeage url directly from owncloud.com):

Syntax: owncloud_update.php <package_url.tar.bz2>
Example:php owncloud_update.php http://download.owncloud.org/releases/owncloud-4.0.4.tar.bz2

Required Directory Structure#

You need the following directory structure:
*owncloud_update.php
*owncloud
*owncloud/config
*ownclouddata (the data folder, name may be variant)

Warning#

If you have the default structure (which is strongly not recommended) the script will erase all your data!
Default Structure is like:
owncloud
*owncloud/config
*owncloud/data (your data dir which is directly web-accessables -> security risk)

The Script#

Functionality#

The Steps of the script explained:

  1. Move the config dir ./owncloud/config outside of the owncloud system dir ./owncloud
  2. Deletes the old owncloud system dir ./owncloud
  3. Download the given new package by url
  4. Extract (Un-Tar/Bz2) the new Package
  5. Remove the tar.bz2 package file
  6. Remove the new config dir into ./owncloud/config
  7. Restore the old config dir to ./owncloud/config

Well that’s it – and quite faster/easier as typing each command by hand. And it will save your time ;)

Scriptfile#

owncloud_update.php#

<?php
if ($argc==2 && strlen(trim($argv[1]))>0){
	// get pathes
	$url = trim($argv[1]);
	$archive = basename($url);
	
	// save config dir
	shell_exec('mv ./owncloud/config ./config');
	
	// remove old installation
	shell_exec('rm -rf ./owncloud');
	
	// download new version
	file_put_contents($archive, file_get_contents($url));
	
	// unzip
	shell_exec('tar xfj '.$archive);
	
	// remove installation archive
	unlink($archive);
	
	// delete new ocnfig dir
	shell_exec('rm -rf ./owncloud/config');
	
	// move config dir back
	shell_exec('mv ./config ./owncloud/config');
}else{
	echo 'Usage: ocupdate.php <achiveurl.tar.bz2>'."\r\n";	
}

?>