Skip to content

Instantly share code, notes, and snippets.

@wizardishungry
Created December 29, 2008 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizardishungry/41407 to your computer and use it in GitHub Desktop.
Save wizardishungry/41407 to your computer and use it in GitHub Desktop.
GitHub post receive hook example -- secret support off
<?php /*
example post receive hook for github
url: http://example.com/post-receive.php?secret=amazingpasswordgoeshere
setup sudo using visudo -- these are my defaults on openbsd, YMMV
Cmnd_Alias GIT = /usr/local/bin/git
Defaults:www !authenticate
www ALL=(usernamehere) NOPASSWD: GIT
*/
$my_secret='amazingpasswordgoeshere';
$my_path='/var/www/htdocs/example.com/';
$my_user='usernamehere';
$my_git='/usr/local/bin/git';
function hide()
{
header("Status: 404 Not Found");
exit();
}
if(!isset($_POST['payload'])) { hide(); }
//if(@$_GET['secret']!=$my_secret) { hide(); }
//$payload=json_decode($_POST['payload']);
echo shell_exec("cd $my_path && sudo -u $my_user $my_git pull");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment