#!/usr/bin/php -q
<?php
require (dirname(__FILE__)."/../../appcore/app.php");
$app = new AppApp( dirname(__FILE__)."/../app.config.php");


if ( $argv[1] != "--commit" ) { 
	print " THIS WILL WIPE-OUT ALL YOUR DATA !!!!!! \n";
	print "use with --commit to confirm\n";
	exit;
}


$dp = $app->attachPath;



$dn =dirname(__FILE__);
$cmd = "cd '$dn' && cat dbschema.sql | mysql -u{$app->dbUser} -p{$app->dbPass} -h{$app->dbHost} {$app->dbName}";
print "$cmd\n";
passthru($cmd);

$cmd = "cd '$dn' && cat dbbasedata.sql | mysql -u{$app->dbUser} -p{$app->dbPass} -h{$app->dbHost} {$app->dbName}";
print "$cmd\n";
passthru($cmd);




`cd '$dn'`;
`mkdir -p '$dp'`;
if ( $dp == "/opt/epgdata" ) { 
$cmd ="tar -zxvf epgdatabasedata.tar.gz -C /";
print "$cmd\n";
passthru("$cmd");
`chown -R www:www '$dp'`;
} else { 
print "WARNING.... this command will extract to /opt/epgdata, 
you need to modify and RUN it to your liking
tar -zxvf epgdatabasedata.tar.gz /
chown -R www:www  '$dp'
";
}

	


?>
