fix autoupdate setup

This commit is contained in:
Alex Grintsvayg 2016-03-10 21:49:04 -05:00
parent c03dd921e2
commit 9f8dc71c37
4 changed files with 24 additions and 12 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.sass-cache
/data/config.php
/data/writeable/*
/web/css/*
/log
/web/zohoverify

View file

@ -10,20 +10,18 @@ class OpsActions extends Actions
public static function executePostCommit()
{
$payload = json_decode($_REQUEST['payload'], true);
$rawPost = file_get_contents('php://input');
$secret = Config::get('github_key');
if ($payload['ref'] === 'refs/heads/master')
{
Actions::returnErrorIf(!isset($_SERVER['HTTP_X_HUB_SIGNATURE']), "HTTP header 'X-Hub-Signature' is missing.");
list($algo, $hash) = explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE'], 2) + array('', '');
Actions::returnErrorIf(!in_array($algo, hash_algos(), TRUE), 'Invalid hash algorithm "' . $algo . '"');
$rawPost = file_get_contents('php://input');
$secret = Config::get('github_key');
Actions::returnErrorIf($hash !== hash_hmac($algo, $rawPost, $secret), 'Hash does not match. "' . $secret . '"' . ' algo: ' . $algo . '$');
if ($payload['ref'] === 'refs/heads/master')
{
$ret = shell_exec('sudo -u lbry ' . ROOT_DIR . '/update.php 2>&1');
echo "Successful post commit (aka the script executed, so maybe it is successful):\n";
echo $ret;
file_put_contents(ROOT_DIR . '/data/writeable/NEEDS_UPDATE', '');
}
return [null, []];

0
data/writeable/.gitkeep Normal file
View file

View file

@ -3,6 +3,19 @@
include __DIR__.'/bootstrap.php';
$options = getopt('f');
$force = isset($options['f']); // update even if no NEEDS_UPDATE file exists
$needsUpdateFile = ROOT_DIR . '/data/writeable/NEEDS_UPDATE';
if (!$force && !file_exists($needsUpdateFile))
{
echo "No update necessary\n";
return;
}
unlink($needsUpdateFile);
chdir(ROOT_DIR);
Shell::exec('git fetch && git reset --hard origin/master');