Skip to content

Commit

Permalink
Added script to auto-pull when github receives a push
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jul 23, 2021
1 parent 3365a12 commit 5b67108
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions gitpull.php
@@ -0,0 +1,29 @@
<?php

// Receive webhook requests from github to allow quick publish and test

// Set GITWEBHOOKSECRET in the Apache config files with SetEnv

$headers = apache_request_headers();
if( !isset($headers['X-Hub-Signature-256']) )
{
if( isset($_REQUEST['log']) )
die(file_get_contents('../gitpull.log'));
else
die('Unauthorized');
}

$rawReq = file_get_contents('php://input');

$sig_check = 'sha256=' . hash_hmac('sha256', $rawReq, getenv('GITWEBHOOKSECRET'));

if (!hash_equals($sig_check, $headers['X-Hub-Signature-256']))
{
die("Access denied, request logged");
}

// This is an authenticated notification from github that we need to pull.

shell_exec('date >> ../gitpull.log 2>&1');
shell_exec('git pull >> ../gitpull.log 2>&1');

0 comments on commit 5b67108

Please sign in to comment.