<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

/**
 * Installs a specific application into the folder in which this file is placed.
 *
*/

// configuration - subversion server
$svnUsername						= '** SVN Username **';
$svnPassword						= '** SVN Password **';
$version							= '** Current version **';

// repository information
$svn								= 'https://svn.msdev.co.uk/';
$repo								= 'blinc';
$branch								= '/release/'.$version.'/src';
$libCode							= 'msLib/trunk/src/assets/lib/';

// the code is going into the folder this file is in
$path								= dirname(__FILE__);

// use a try/catch block to handle any errors
try {
	// array to hold data
	$output							= array();

	// check that we have write access to the folder
	if(!is_writeable($path)) {
		throw new Exception('Unable to write to the document root. Please ensure that the web server (Apache of IIS) has write access to the folder you have placed this install file in.');
	}

	// now check out the code into the folder we're in
	$cmd							= 'svn export "'.$svn.$repo.$branch.'" "'.$path.'"'." --force --username {$svnUsername} --password {$svnPassword} --config-dir /tmp/ --non-interactive --trust-server-cert 2>&1";
	$output[] 						= $cmd;
	exec($cmd, $output, $value);

	// and the library code
	$cmd							= 'svn export "'.$svn.$libCode.'" "'.$path.'/assets/lib/"'." --force --username {$svnUsername} --password {$svnPassword} --config-dir /tmp/ --non-interactive --trust-server-cert 2>&1";
	$output[] 						= $cmd;
	exec($cmd, $output, $value);

	// and a little reminder at the end
	$output[]						= " ************ IMPORTANT *************";
 	$output[]						= "     Remember to delete install.php";

 	// add the output from the svn export
	$html					 	   	= '<h3>Output results</h3><pre>'.print_r($output, true).'</pre>';
} catch (Exception $e) {
    $html							= "<h3>Fatal error</h3><p>The following fatal error occured: {$e->getMessage()}</p>";
}

?>
<html>
	<body>
		<?php echo $html; ?>
	</body>
</html>